fix(wx): 优化获取手机号失败时的token缓存清理逻辑
- 解析不同类型的错误码以确保正确识别token相关错误 - 增加isTokenRelatedError方法判断特定错误码是否属于token相关错误 - 在获取手机号失败时清理对应的access_token缓存,防止token失效问题 - 输出详细日志便于排查微信获取手机号失败的异常情况 - 修正小程序二维码生成中env_version注释说明提升可读性 - 新增高级开发工程师专家配置数据
This commit is contained in:
@@ -33,7 +33,18 @@
|
|||||||
"usedAt": 1775720823455,
|
"usedAt": 1775720823455,
|
||||||
"industryId": "all"
|
"industryId": "all"
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"11ef16ee251d4624968d1e84c0fb1de9": [
|
||||||
|
{
|
||||||
|
"expertId": "SeniorDeveloper",
|
||||||
|
"name": "Will",
|
||||||
|
"profession": "高级开发工程师",
|
||||||
|
"avatarUrl": "https://acc-1258344699.cos.accelerate.myqcloud.com/workbuddy/experts/avatars/02-Engineering/SeniorDeveloper/SeniorDeveloper.png",
|
||||||
|
"promptUrl": "https://acc-1258344699.cos.accelerate.myqcloud.com/workbuddy/experts/experts/02-Engineering/SeniorDeveloper/SeniorDeveloper_zh.md",
|
||||||
|
"usedAt": 1775866025894,
|
||||||
|
"industryId": "all"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"lastUpdated": 1775727841457
|
"lastUpdated": 1775866842655
|
||||||
}
|
}
|
||||||
@@ -147,7 +147,7 @@ public class QrLoginServiceImpl implements QrLoginService {
|
|||||||
// 小程序端通过 router.params.scene 获取此 token
|
// 小程序端通过 router.params.scene 获取此 token
|
||||||
params.put("scene", token);
|
params.put("scene", token);
|
||||||
params.put("page", "passport/qr-confirm/index"); // 小程序确认页面路径(子包)
|
params.put("page", "passport/qr-confirm/index"); // 小程序确认页面路径(子包)
|
||||||
params.put("env_version", "release"); // 正式版小程序 release
|
params.put("env_version", "release"); // release/trial/develop
|
||||||
params.put("width", 280); // 二维码宽度
|
params.put("width", 280); // 二维码宽度
|
||||||
params.put("auto_color", false); // 不自动配置颜色
|
params.put("auto_color", false); // 不自动配置颜色
|
||||||
// HashMap<String, Object> lineColor = new HashMap<>();
|
// HashMap<String, Object> lineColor = new HashMap<>();
|
||||||
|
|||||||
@@ -602,16 +602,29 @@ public class WxLoginController extends BaseController {
|
|||||||
JSONObject phoneInfo = JSON.parseObject(json.getString("phone_info"));
|
JSONObject phoneInfo = JSON.parseObject(json.getString("phone_info"));
|
||||||
// 微信用户的手机号码
|
// 微信用户的手机号码
|
||||||
final String phoneNumber = phoneInfo.getString("phoneNumber");
|
final String phoneNumber = phoneInfo.getString("phoneNumber");
|
||||||
// 验证手机号码
|
|
||||||
// if (userParam.getNotVerifyPhone() == null && !Validator.isMobile(phoneNumber)) {
|
|
||||||
// String key = ACCESS_TOKEN_KEY.concat(":").concat(getTenantId().toString());
|
|
||||||
// redisTemplate.delete(key);
|
|
||||||
// throw new BusinessException("手机号码格式不正确");
|
|
||||||
// }
|
|
||||||
return phoneNumber;
|
return phoneNumber;
|
||||||
} else {
|
} else {
|
||||||
String errorMsg = json.getString("errmsg");
|
String errorMsg = json.getString("errmsg");
|
||||||
|
Integer errCodeInt = null;
|
||||||
|
if (errcode instanceof Integer) {
|
||||||
|
errCodeInt = (Integer) errcode;
|
||||||
|
} else if (errcode instanceof Long) {
|
||||||
|
errCodeInt = ((Long) errcode).intValue();
|
||||||
|
} else if (errcode instanceof String) {
|
||||||
|
try {
|
||||||
|
errCodeInt = Integer.parseInt((String) errcode);
|
||||||
|
} catch (NumberFormatException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
System.err.println("微信获取手机号失败: errcode=" + errcode + ", errmsg=" + errorMsg);
|
System.err.println("微信获取手机号失败: errcode=" + errcode + ", errmsg=" + errorMsg);
|
||||||
|
|
||||||
|
// 判断是否是 token 相关错误,如果是则清理缓存
|
||||||
|
if (isTokenRelatedError(errCodeInt, errorMsg)) {
|
||||||
|
String key = ACCESS_TOKEN_KEY.concat(":").concat(tenantId != null ? tenantId.toString() : getTenantId().toString());
|
||||||
|
redisTemplate.delete(key);
|
||||||
|
System.err.println("已清理access_token缓存,key=" + key);
|
||||||
|
}
|
||||||
|
|
||||||
throw new BusinessException("获取手机号失败:" + errorMsg);
|
throw new BusinessException("获取手机号失败:" + errorMsg);
|
||||||
}
|
}
|
||||||
} catch (BusinessException be) {
|
} catch (BusinessException be) {
|
||||||
@@ -627,6 +640,25 @@ public class WxLoginController extends BaseController {
|
|||||||
throw new BusinessException("获取手机号失败,请检查参数");
|
throw new BusinessException("获取手机号失败,请检查参数");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否是 token 相关的错误码,需要清理缓存
|
||||||
|
*/
|
||||||
|
private boolean isTokenRelatedError(Integer errCode, String errMsg) {
|
||||||
|
if (errCode == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// token 相关错误码
|
||||||
|
return errCode == 40001 // AppSecret错误
|
||||||
|
|| errCode == 40013 // appid无效
|
||||||
|
|| errCode == 40125 // appsecret无效
|
||||||
|
|| errCode == 42001 // access_token超时
|
||||||
|
|| errCode == 42002 // refresh_token超时
|
||||||
|
|| errCode == 42003 // code超时
|
||||||
|
|| errCode == 41002 // appid不正确
|
||||||
|
|| errCode == 41008 // 缺少access_token参数
|
||||||
|
|| errCode == 40014; // 不合法的access_token
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成随机账号
|
* 生成随机账号
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user