艾金辉
2023-07-22 64c7668818aa8272c0aae206a3c0f7007ca38e5d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.ruoyi.rongcloud.service;
 
import com.dtflys.forest.callback.AddressSource;
import com.dtflys.forest.http.ForestAddress;
import com.dtflys.forest.http.ForestRequest;
import com.ruoyi.common.core.redis.RedisCache;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.net.MalformedURLException;
import java.net.URL;
 
/**
 * @Description:
 * @ClassName: MyAddressSource
 * @Author: 刘苏义
 * @Date: 2023年07月17日13:40:46
 * @Version: 1.0
 **/
@Component
public class MyAddressSource implements AddressSource {
 
    @Resource
    RedisCache redisCache;
 
    @Override
    public ForestAddress getAddress(ForestRequest forestRequest) {
 
        String apiUrl = redisCache.getCacheObject("sys_config:rongyun");
        URL url = null;
        try {
            url = new URL(apiUrl);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        String host = url.getHost();
        int port = url.getPort();
        return new ForestAddress(host,port);
    }
}