Commit a10a6026 authored by Administrator's avatar Administrator

小程序获取token存redis错误的问题

parent 66cdb628
......@@ -163,17 +163,18 @@ public class ResourcesController {
*/
private String getMicroAccessToken(String partnerId){
String accessToken = (String) valueOperations.get("micro_gk:access_token_" + partnerId);
log.info("===== redis access_token:"+ accessToken);
// if(StringUtils.isEmpty(accessToken)){
log.info("===== redis access_token:" + accessToken);
if (StringUtils.isEmpty(accessToken)) {
Partner partner = partnerService.getPartnerById(partnerId);
String aokenUrl ="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+partner.getAppId()+"&secret="+partner.getAppSecret();
String aokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + partner.getAppId() + "&secret=" + partner.getAppSecret();
String json = HttpUtil.doGet(aokenUrl, null);
log.info("URL:"+aokenUrl+", 返回结果:"+json);
Map<String, Object> resultMap = JsonUtil.fromJson(json, new TypeReference<Map<String, Object>>() {});
log.info("URL:" + aokenUrl + ", 返回结果:" + json);
Map<String, Object> resultMap = JsonUtil.fromJson(json, new TypeReference<Map<String, Object>>() {
});
accessToken = resultMap.get("access_token").toString();
String expiresIn = resultMap.get("expires_in").toString();
valueOperations.set("micro_gk:access_token_" + partnerId, TimeUnit.SECONDS, Long.parseLong(expiresIn));
// }
valueOperations.set("micro_gk:access_token_" + partnerId, accessToken, Long.parseLong(expiresIn), TimeUnit.SECONDS);
}
return accessToken;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment