|
|
@ -52,6 +52,12 @@ public class WeChatAouth2Service {
|
|
|
|
@Value("${oauth2.weixin.secret}")
|
|
|
|
@Value("${oauth2.weixin.secret}")
|
|
|
|
private String secret;
|
|
|
|
private String secret;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${oauth2.weixin.appidShare}")
|
|
|
|
|
|
|
|
private String appid_share;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${oauth2.weixin.secretShare}")
|
|
|
|
|
|
|
|
private String secret_share;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private UserInfoService userInfoService;
|
|
|
|
private UserInfoService userInfoService;
|
|
|
|
|
|
|
|
|
|
|
@ -62,7 +68,7 @@ public class WeChatAouth2Service {
|
|
|
|
private UserInfoDao userInfoDao;
|
|
|
|
private UserInfoDao userInfoDao;
|
|
|
|
|
|
|
|
|
|
|
|
public Result getShareToken(WeChatShareReq weChatShareReq){
|
|
|
|
public Result getShareToken(WeChatShareReq weChatShareReq){
|
|
|
|
Aouth2WeChatTokenResponse accessToken = getAccessToken(weChatShareReq.getCode());
|
|
|
|
Aouth2WeChatTokenResponse accessToken = getAccessShareToken(weChatShareReq.getCode());
|
|
|
|
if(accessToken == null || accessToken.getAccess_token() == null )
|
|
|
|
if(accessToken == null || accessToken.getAccess_token() == null )
|
|
|
|
return Result.failed("分享微信失败");
|
|
|
|
return Result.failed("分享微信失败");
|
|
|
|
|
|
|
|
|
|
|
@ -161,7 +167,23 @@ public class WeChatAouth2Service {
|
|
|
|
url.append("&grant_type=authorization_code");
|
|
|
|
url.append("&grant_type=authorization_code");
|
|
|
|
String string = new String(get(url.toString()));
|
|
|
|
String string = new String(get(url.toString()));
|
|
|
|
|
|
|
|
|
|
|
|
log.info("refreshAccessToken:" + string);
|
|
|
|
log.info("getAccessToken:" + string);
|
|
|
|
|
|
|
|
Aouth2WeChatTokenResponse aouth2WeChatTokenResponse = JSON.parseObject(string, Aouth2WeChatTokenResponse.class);
|
|
|
|
|
|
|
|
saveTokenToRedis(aouth2WeChatTokenResponse);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return aouth2WeChatTokenResponse;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Aouth2WeChatTokenResponse getAccessShareToken(String code){
|
|
|
|
|
|
|
|
StringBuffer url = new StringBuffer();
|
|
|
|
|
|
|
|
url.append(Constants.HTTPS_API_WEIXIN_QQ_COM_SNS_OAUTH2_ACCESS_TOKEN);
|
|
|
|
|
|
|
|
url.append("?appid=").append(urlEncode(appid_share));
|
|
|
|
|
|
|
|
url.append("&secret=").append(urlEncode(secret_share));
|
|
|
|
|
|
|
|
url.append("&code=").append(urlEncode(code));
|
|
|
|
|
|
|
|
url.append("&grant_type=authorization_code");
|
|
|
|
|
|
|
|
String string = new String(get(url.toString()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.info("getAccessShareToken:" + string);
|
|
|
|
Aouth2WeChatTokenResponse aouth2WeChatTokenResponse = JSON.parseObject(string, Aouth2WeChatTokenResponse.class);
|
|
|
|
Aouth2WeChatTokenResponse aouth2WeChatTokenResponse = JSON.parseObject(string, Aouth2WeChatTokenResponse.class);
|
|
|
|
saveTokenToRedis(aouth2WeChatTokenResponse);
|
|
|
|
saveTokenToRedis(aouth2WeChatTokenResponse);
|
|
|
|
|
|
|
|
|
|
|
|