获取失败问题
This commit is contained in:
parent
e0fc346f26
commit
c361fe651d
|
|
@ -139,9 +139,12 @@ public class UserAuthorizationServiceImpl implements UserAuthorizationService {
|
|||
private void initAc(UserInfo userInfo) {
|
||||
if (StrUtil.isBlank(userInfo.getWechatAcOpenId()) &&
|
||||
(userInfo.getAcQrcodeValidTime() == null || userInfo.getAcQrcodeValidTime().isBefore(LocalDateTime.now()))) {
|
||||
userInfo.setWechatAcQrcode(acAccountUtil.createQrCode(userInfo.getId()));
|
||||
userInfo.setAcQrcodeValidTime(LocalDateTime.now().plusDays(29));
|
||||
userInfoService.updateById(userInfo);
|
||||
String qrCode = acAccountUtil.createQrCode(userInfo.getId());
|
||||
if (StrUtil.isNotBlank(qrCode)) {
|
||||
userInfo.setWechatAcQrcode(qrCode);
|
||||
userInfo.setAcQrcodeValidTime(LocalDateTime.now().plusDays(29));
|
||||
userInfoService.updateById(userInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,9 +49,10 @@ public class AcAccountUtil {
|
|||
* 获取临时二维码用于关注公众号 30天(即2592000秒)后过期
|
||||
*/
|
||||
public String createQrCode(Long userId) {
|
||||
String accessToken = Convert.toStr(redisService.get("accessToken"));
|
||||
if (StrUtil.isNotEmpty(accessToken)) {
|
||||
return accessToken;
|
||||
String accessToken = getAccessToken();
|
||||
if (StrUtil.isBlank(accessToken)) {
|
||||
log.error("获取 access_token 失败");
|
||||
return "";
|
||||
}
|
||||
JSONObject bodyJson = new JSONObject();
|
||||
//二维码有效时间(秒),最大2592000,仅临时二维码需要
|
||||
|
|
@ -64,7 +65,7 @@ public class AcAccountUtil {
|
|||
actionInfo.put("scene", scene);
|
||||
bodyJson.put("action_info", actionInfo);
|
||||
|
||||
String resp = HttpUtil.post(StrUtil.format("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={}", getAccessToken()), bodyJson);
|
||||
String resp = HttpUtil.post(StrUtil.format("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={}", accessToken), bodyJson);
|
||||
/**
|
||||
* {
|
||||
* "ticket": "gQH47joAAAAAAAAAASxodHRwOi8vd2VpeGlu...",
|
||||
|
|
@ -73,6 +74,10 @@ public class AcAccountUtil {
|
|||
* }
|
||||
*/
|
||||
JSONObject respInfo = JSONObject.parseObject(resp);
|
||||
if (respInfo.get("url") == null) {
|
||||
log.error("创建临时二维码失败, 响应内容: {}", resp);
|
||||
return "";
|
||||
}
|
||||
return respInfo.get("url").toString();
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +93,7 @@ public class AcAccountUtil {
|
|||
JSONObject respInfo = JSONObject.parseObject(resp);
|
||||
if (!respInfo.containsKey("access_token")) {
|
||||
log.warn("公众号获取token失败, 响应内容: {}", resp);
|
||||
throw new RuntimeException(resp);
|
||||
return "";
|
||||
}
|
||||
accessToken = respInfo.getString("access_token");
|
||||
int expiresIn = respInfo.getInteger("expires_in");
|
||||
|
|
|
|||
Loading…
Reference in New Issue