f
This commit is contained in:
@@ -118,7 +118,37 @@ func (l *WxMiniAuthLogic) GetSessionKey(code string) (*SessionKeyResp, error) {
|
||||
|
||||
// 检查微信返回的错误码
|
||||
if sessionKeyResp.ErrCode != 0 {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR),
|
||||
// 针对不同的微信错误码返回更明确的错误信息
|
||||
var errMsg string
|
||||
switch sessionKeyResp.ErrCode {
|
||||
case 40029:
|
||||
// code 无效(已使用、已过期或格式错误)
|
||||
errMsg = "微信授权码无效或已过期,请重新打开小程序"
|
||||
l.Errorf("微信code无效: errcode=%d, errmsg=%s, code前6位=%s",
|
||||
sessionKeyResp.ErrCode, sessionKeyResp.ErrMsg,
|
||||
func() string {
|
||||
if len(code) > 6 {
|
||||
return code[:6] + "..."
|
||||
}
|
||||
return code
|
||||
}())
|
||||
case 40013:
|
||||
// 无效的 AppID
|
||||
errMsg = "小程序配置错误,请联系管理员"
|
||||
l.Errorf("微信AppID无效: errcode=%d, errmsg=%s", sessionKeyResp.ErrCode, sessionKeyResp.ErrMsg)
|
||||
case 40125:
|
||||
// 无效的 AppSecret
|
||||
errMsg = "小程序配置错误,请联系管理员"
|
||||
l.Errorf("微信AppSecret无效: errcode=%d, errmsg=%s", sessionKeyResp.ErrCode, sessionKeyResp.ErrMsg)
|
||||
case 45011:
|
||||
// 频率限制
|
||||
errMsg = "请求过于频繁,请稍后再试"
|
||||
l.Errorf("微信API频率限制: errcode=%d, errmsg=%s", sessionKeyResp.ErrCode, sessionKeyResp.ErrMsg)
|
||||
default:
|
||||
errMsg = fmt.Sprintf("微信授权失败: %s", sessionKeyResp.ErrMsg)
|
||||
l.Errorf("微信接口返回错误: errcode=%d, errmsg=%s", sessionKeyResp.ErrCode, sessionKeyResp.ErrMsg)
|
||||
}
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg(errMsg),
|
||||
"微信接口返回错误: errcode=%d, errmsg=%s",
|
||||
sessionKeyResp.ErrCode, sessionKeyResp.ErrMsg)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user