Closed json7 closed 4 years ago
var ( req model_wechat.AuthReq )
if err := c.ShouldBindJSON(&req); err != nil { response.Error(c, 500, nil, "c.ShouldBindJSON:"+err.Error()) return } resp, err := weapp.Login(config.WechatConfig.Appid, config.WechatConfig.Secret, req.Code) if err != nil { response.Error(c, 500, nil, "weapp.Login:"+err.Error()) return } if err := resp.GetResponseError(); err != nil { response.Error(c, 500, nil, "weapp.Login resp.GetResponseError:"+err.Error()) return } //处理用户信息 raw := sha1.Sum([]byte(req.UserInfo.RawData + resp.SessionKey)) wxUserInfo, err := weapp.DecryptUserInfo(resp.SessionKey, req.UserInfo.RawData, req.UserInfo.EncryptedData, hex.EncodeToString(raw[:]), req.UserInfo.IV) if err != nil { response.Error(c, 500, nil, "weapp.DecryptUserInfo:"+err.Error()) return } //处理用户手机号信息 var ( mobile *weapp.Mobile ) //如果手机信息不为空 if !reflect.DeepEqual(req.PhoneInfo, model_wechat.PhoneInfo{}) { mobile, err = weapp.DecryptMobile(resp.SessionKey, req.PhoneInfo.EncryptedData, req.PhoneInfo.Iv) if err != nil { response.Error(c, 500, nil, "weapp.DecryptMobile:"+err.Error()) //这里会报错 weapp.DecryptMobile:invalid character '¼' looking for beginning of value 每次character会变化,随机性的出现 return } }
前端 wx.login调用顺序错误,引发sessinkey失效
这个接口必须先通过登陆流程才能是否,否则报错是正常的;
var ( req model_wechat.AuthReq )