fix wechat login and share

main
Revers 8 months ago
parent 9ab1eedea1
commit 6e3fb0fd9e

@ -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);

@ -12,6 +12,6 @@ spring:
oauth2: oauth2:
weixin: weixin:
appid: wxae6fb76efa147314 appid: wxae6fb76efa147314
# appid: wx667f580d1605650b
secret: 741727f12d1b262ac855b905bf2e60e2 secret: 741727f12d1b262ac855b905bf2e60e2
# secret: 4bb42de98cb422d733ac7d50e7cade3b appidShare: wx667f580d1605650b
secretShare: 4bb42de98cb422d733ac7d50e7cade3b
Loading…
Cancel
Save