Browse Source

Merge branch 'feature/admin_wechat_login' into debug

# Conflicts:
#	controllers/admin_wx.go
#	controllers/base_common.go
#	controllers/wechat.go
#	models/tables/admin/admin.go
#	services/admin_wechat.go
#	services/sms.go
#	services/wechat.go
#	utils/config.go
xiexiaoyuan 2 years ago
parent
commit
f9901e795e
2 changed files with 8 additions and 9 deletions
  1. 7 7
      controllers/admin_wx.go
  2. 1 2
      services/wechat.go

+ 7 - 7
controllers/admin_wx.go

@@ -119,7 +119,7 @@ func (c *AdminWxController) SendSmsCode()  {
 // @Param   Code     query   string  true       "短信验证码"
 // @Success 200 {object} wechat.WxLoginResp
 // @router /bind_mobile [post]
-func (c *AdminWxController) BindMobile()  {
+func (c *AdminWxController) BindMobile() {
 	var req admin.BindMobileReq
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
 	if err != nil {
@@ -139,18 +139,18 @@ func (c *AdminWxController) BindMobile()  {
 		return
 	}
 	//校验验证码
-	_, err = utils.Rc.RedisString(utils.HZ_MOBILE_ADMIN_WXLOGIN_MOBILE_CODE+req.Mobile)
+	_, err = utils.Rc.RedisString(utils.HZ_MOBILE_ADMIN_WXLOGIN_MOBILE_CODE + req.Mobile)
 	if err != nil {
 		c.FailWithMessage("验证码错误或者已过期", "验证码错误或者已过期"+err.Error())
 		return
 	}
 	//获取token,如果没有token不允许发送验证码
-	infoJson, err := utils.Rc.RedisString(utils.HZ_MOBILE_ADMIN_WXLOGIN_TOKEN+req.Token)
+	infoJson, err := utils.Rc.RedisString(utils.HZ_MOBILE_ADMIN_WXLOGIN_TOKEN + req.Token)
 	if err != nil {
 		c.FailWithMessage("授权信息不存在", "授权信息不存在"+err.Error())
 		return
 	}
-	info := map[string]string{"open_id":"", "union_id":""}
+	info := map[string]string{"open_id": "", "union_id": ""}
 	err = json.Unmarshal([]byte(infoJson), &info)
 	if err != nil {
 		c.FailWithMessage("授权信息解析失败", "授权信息解析失败"+err.Error())
@@ -167,15 +167,15 @@ func (c *AdminWxController) BindMobile()  {
 	if err != nil {
 		if err.Error() == utils.ErrNoRow() {
 			err = nil
-		}else{
+		} else {
 			c.FailWithMessage("查询管理员信息失败", "查询管理员信息失败"+err.Error())
 			return
 		}
-	}else{
+	} else {
 		if adminInfo.Mobile != req.Mobile {
 			c.FailWithMessage("该微信已被其他账号绑定", "该微信已被其他账号绑定")
 			return
-		}else{
+		} else {
 			c.Ok()
 			return
 		}

+ 1 - 2
services/wechat.go

@@ -140,8 +140,7 @@ func WxGetRedisAccessToken(wxAppId, wxAppSecret string) (accessToken string, err
 			err = errors.New("获取access_token 失败 errcode:" + token.Errmsg + " ;errmsg:" + token.Errmsg)
 			return "", err
 		}
-		redisTimeExpire := time.Duration(token.ExpiresIn - 600) * time.Second
-		err = utils.Rc.Put(utils.HZ_ADMIN_WX_ACCESS_TOEKN+wxAppId, token.AccessToken, redisTimeExpire)
+		err = utils.Rc.Put(utils.HZ_ADMIN_WX_ACCESS_TOEKN+wxAppId, token.AccessToken, 110 * time.Minute)
 		if err != nil {
 			err = errors.New("保存access_token失败 " + err.Error())
 			return accessToken, err