|
@ -13,11 +13,13 @@ import com.yihu.jw.wechat.service.WxAccessTokenService;
|
|
|
import com.yihu.jw.wechat.service.WxUrlConfigService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.json.JSONObject;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
@ -28,6 +30,7 @@ import java.security.MessageDigest;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.UUID;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
* Created by Trick on 2018/12/3.
|
|
@ -45,6 +48,8 @@ public class WechatInfoEndPoint extends EnvelopRestEndpoint {
|
|
|
private WechatInfoService wechatInfoService;
|
|
|
@Value("${wechat.id}")
|
|
|
private String wxId;
|
|
|
@Autowired
|
|
|
private StringRedisTemplate redisTemplate;
|
|
|
|
|
|
@Autowired
|
|
|
private WxUrlConfigService wxUrlConfigService;
|
|
@ -96,7 +101,15 @@ public class WechatInfoEndPoint extends EnvelopRestEndpoint {
|
|
|
@RequestMapping(value = "getOpenidByCode", method = {RequestMethod.POST, RequestMethod.GET})
|
|
|
@ResponseBody
|
|
|
public Envelop getOpenidByCode(String code) throws Exception {
|
|
|
String openid = wechatInfoService.getOpenidByCode(code, wxId);
|
|
|
//通过redis获取openid, 获取不到,则调用微信接口去取
|
|
|
String key = wxId+":code";
|
|
|
String openid = redisTemplate.opsForValue().get(key);
|
|
|
if(StringUtils.isNotBlank(openid)){
|
|
|
return success(PatientRequestMapping.Wechat.api_success,openid);
|
|
|
}
|
|
|
openid = wechatInfoService.getOpenidByCode(code, wxId);
|
|
|
redisTemplate.opsForValue().set(key,openid);
|
|
|
redisTemplate.expire(key,10, TimeUnit.SECONDS);
|
|
|
return success(PatientRequestMapping.Wechat.api_success,openid);
|
|
|
}
|
|
|
|