token优化和修复
This commit is contained in:
parent
c5d09ad3c1
commit
911f82d634
@ -0,0 +1,53 @@
|
|||||||
|
package org.ssssssss.magicboot.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.client.RestClientException;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
import org.ssssssss.magicboot.constant.CertificateConstant;
|
||||||
|
import org.ssssssss.magicboot.constant.URLConstant;
|
||||||
|
import org.ssssssss.magicboot.utils.CaffeineCacheUtil;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/crm")
|
||||||
|
@Slf4j
|
||||||
|
public class CRMTokenController {
|
||||||
|
|
||||||
|
private RestTemplate restTemplate = new RestTemplate();
|
||||||
|
|
||||||
|
@PostMapping("/getToken")
|
||||||
|
public void getCRMToken() {
|
||||||
|
//封装请求
|
||||||
|
Map tokenParams = new HashMap<>();
|
||||||
|
tokenParams.put("appId", CertificateConstant.APP_ID);
|
||||||
|
tokenParams.put("appSecret", CertificateConstant.APP_SECRET);
|
||||||
|
tokenParams.put("permanentCode", CertificateConstant.PERMANENT_CODE);
|
||||||
|
|
||||||
|
JSONObject tokenResponse = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
tokenResponse = restTemplate.postForObject(URLConstant.GET_CORPACCESSTOKEN_URL, tokenParams, JSONObject.class);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
//判断是否成功
|
||||||
|
if ("success".equals(tokenResponse.getString("errorMessage"))) {
|
||||||
|
String corpAccessToken = tokenResponse.getString("corpAccessToken");
|
||||||
|
|
||||||
|
//移除
|
||||||
|
CaffeineCacheUtil.remove("corpAccessToken");
|
||||||
|
|
||||||
|
//存入新的
|
||||||
|
CaffeineCacheUtil.put("corpAccessToken", corpAccessToken);
|
||||||
|
} else {
|
||||||
|
log.info("获取纷享销客token失败{}", tokenResponse);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -9,7 +9,7 @@ public class CaffeineCacheUtil {
|
|||||||
|
|
||||||
private static final Cache<Object, Object> cache = Caffeine.newBuilder()
|
private static final Cache<Object, Object> cache = Caffeine.newBuilder()
|
||||||
.maximumSize(100) // 最大缓存容量
|
.maximumSize(100) // 最大缓存容量
|
||||||
.expireAfterWrite(120, TimeUnit.MINUTES) // 120分钟后过期
|
.expireAfterWrite(90, TimeUnit.MINUTES) // 120分钟后过期
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user