package services import ( "encoding/json" "errors" "hongze/hongze_mobile_admin/models/tables/admin" "hongze/hongze_mobile_admin/utils" "strconv" "time" ) //AdminWxLogin 内部员工公众号(弘则部门)微信登录 func AdminWxLogin(wxAccessToken *WxAccessToken, wxUserInfo *WxUserInfo) (ret admin.WxLoginResp, err error, errMsg string) { errMsg = `微信登录失败` openId := wxAccessToken.Openid unionId := wxAccessToken.Unionid if unionId == "" { unionId = wxUserInfo.Unionid } //firstLogin==1,强制绑定手机号或者邮箱 _, err = admin.GetAdminWxByAdminOpenId(openId) if err != nil { if err.Error() == utils.ErrNoRow() { //wxUser.FirstLogin = 1 /*err = ERR_ADMIN_NOT_BIND errMsg = "用户没有绑定" return*/ err = nil timeUnix := time.Now().Unix() timeUnixStr := strconv.FormatInt(timeUnix, 10) ret.BindToken = utils.MD5(openId) + utils.MD5(timeUnixStr) //把openid 相关信息保存到redis content := make(map[string]string, 2) content["open_id"] = openId content["union_id"] = unionId contentStr, _ := json.Marshal(content) err = utils.Rc.Put(utils.HZ_MOBILE_ADMIN_WXLOGIN_TOKEN+ret.BindToken, contentStr, 24*time.Hour) if err != nil { err = errors.New("保存登录信息到redis中失败 Err "+err.Error()) errMsg = "保存登录信息失败" return } ret.BindFlag = false return } errMsg = "查询账号失败" return } ret.BindFlag = true return }