Commit fb86319b authored by 杨阳's avatar 杨阳

1. 登录方式更换成 平台的微信登录

2. 认证字段返回bug fixed 3. 登录权限 bug修复 4. 农户信息入库问题测试 5. 修改userId字段 => amosUserId 6. 生成二维码参数值调整 (region->1, personal > 2) 7. 获取access_token的刷新机制
parent fa2b3210
......@@ -19,6 +19,13 @@ public interface IWxService {
* @return
*/
String getAccessToken();
/**
* 强制刷新缓存中的小程序Token
* https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/access-token/auth.getAccessToken.html
*
* @return
*/
String refreshAccessToken();
/**
* 统一产生第三方页面二维码
......
package com.yeejoin.amos.boot.module.hygf.biz.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.biz.common.utils.HttpUtils;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
......@@ -10,6 +11,7 @@ import com.yeejoin.amos.boot.module.hygf.api.service.IWxService;
import com.yeejoin.amos.boot.module.jxiop.api.util.HttpUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......@@ -89,6 +91,17 @@ public class WxServiceImpl implements IWxService {
return accessToken.getAccess_token();
}
@Override
public String refreshAccessToken() {
// 坑,redis取出来的值 微信说失效了 现在解决方案 是改小失效时间
String redisKey = SMALL_PRO_TOKEN + ":" + appId;
AccessTokenDto accessToken = buildTokenParam(SMALL_PRO_TOKEN_URL, grant_type, appId, secret);
if (accessToken.getErrcode() == null) {
redisUtil.set(redisKey, accessToken.getAccess_token(), accessToken.getExpires_in() - 5);
}
return accessToken.getAccess_token();
}
private AccessTokenDto buildTokenParam(String url, String grant_type, String appid, String secret) {
StringBuffer buildUrl = new StringBuffer();
buildUrl.append(url).append("grant_type=" + grant_type).append("&appid=" + appid).append("&secret=" + secret);
......@@ -195,6 +208,21 @@ public class WxServiceImpl implements IWxService {
response.addHeader("Access-Control-Allow-Headers", "Content-Disposition");
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
String smallProQrCodeStr = new String(smallProQrCode);
if (StringUtils.isNotBlank(smallProQrCodeStr)) {
try {
JSONObject resultJson = JSONObject.parseObject(smallProQrCodeStr);
log.info("生成二维码access_token错误, result => {}, 尝试重新获取access_token", resultJson);
if (resultJson != null && "40001".equals(resultJson.getString("errcode"))) {
access_token = refreshAccessToken();
smallProQrCodeVo = buildQrParam(SMALL_PRO_QRCODE_URL, access_token, scene, page, width,
auto_color, line_color, is_hyaline);
smallProQrCode = smallProQrCodeVo.getBuffer();
}
} catch (JSONException e) {
// 如果json解析异常则说明正常的获取到图片流
}
}
String picStr = Base64.getEncoder().encodeToString(smallProQrCode);
return picStr;
/*OutputStream os = null;
......
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