数云accessToken获取以及缓存
parent
4f35e32c3f
commit
5fb2b3a3eb
@ -0,0 +1,73 @@
|
||||
package com.flossom.miniProgram.utils.shuyun;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.flossom.common.core.constant.CacheConstants;
|
||||
import com.flossom.common.core.utils.StringUtils;
|
||||
import com.flossom.common.redis.service.RedisService;
|
||||
import com.flossom.miniProgram.utils.HttpClientUtils;
|
||||
import com.shuyun.open.sdk.bean.HttpMethod;
|
||||
import com.shuyun.open.sdk.core.GateWayClient;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 数云工具类
|
||||
*/
|
||||
@Component
|
||||
public class ShuYunApiUtils {
|
||||
|
||||
protected final static Logger logger = LoggerFactory.getLogger(ShuYunApiUtils.class);
|
||||
|
||||
private static ShuYunConfig shuYunConfig;
|
||||
|
||||
private static RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
public void setShuYunConfig(ShuYunConfig shuYunConfig) {
|
||||
ShuYunApiUtils.shuYunConfig = shuYunConfig;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setRedisService(RedisService redisService) {
|
||||
ShuYunApiUtils.redisService = redisService;
|
||||
}
|
||||
|
||||
public static void refreshAccessToken() throws Exception {
|
||||
String url = "https://open-client.shuyun.com/client/callback/token/" + shuYunConfig.getAppid() + "/v2";
|
||||
logger.info(url);
|
||||
logger.info(HttpClientUtils.get(url));
|
||||
}
|
||||
|
||||
|
||||
public static String getAccessToken(String appid, String secret) throws Exception {
|
||||
String accessToken = redisService.getCacheObject(CacheConstants.SHUYUN_ACCESS_TOKEN_CACHE);
|
||||
if (StringUtils.isBlank(accessToken)) {
|
||||
Map<String, String> params = new LinkedHashMap<>();
|
||||
params.put("platCode", "OFFLINE"); // 暂时固定
|
||||
params.put("shopId", "9005"); // 暂时固定
|
||||
params.put("id", "001");
|
||||
params.put("mobile", "13500000001");
|
||||
|
||||
String requestBody = new ObjectMapper().writeValueAsString(params);
|
||||
String result = GateWayClient.askGateWay(HttpMethod.POST,
|
||||
shuYunConfig.getUrl(),
|
||||
null,
|
||||
requestBody,
|
||||
shuYunConfig.getAppid(),
|
||||
shuYunConfig.getSecurity(),
|
||||
null,
|
||||
"shuyun.loyalty.member.register");
|
||||
|
||||
|
||||
}
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
package com.flossom.miniProgram.utils.shuyun;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 数云接口配置
|
||||
*
|
||||
* @author flossom
|
||||
*/
|
||||
@Configuration
|
||||
@RefreshScope
|
||||
@ConfigurationProperties(prefix = "shuyun")
|
||||
public class ShuYunConfig {
|
||||
|
||||
/**
|
||||
* 接口地址
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 数云 appid
|
||||
*/
|
||||
private String appid;
|
||||
|
||||
/**
|
||||
* 数云 security
|
||||
*/
|
||||
private String security;
|
||||
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getAppid() {
|
||||
return appid;
|
||||
}
|
||||
|
||||
public void setAppid(String appid) {
|
||||
this.appid = appid;
|
||||
}
|
||||
|
||||
public String getSecurity() {
|
||||
return security;
|
||||
}
|
||||
|
||||
public void setSecurity(String security) {
|
||||
this.security = security;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
http-pool.connect-timeout=60000
|
||||
http-pool.connection-request-timeout=60000
|
||||
http-pool.socket-timeout=60000
|
||||
Loading…
Reference in New Issue