|
@@ -640,3 +640,68 @@ func (this *WechatController) UpdateWxAccesstoken() {
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|
|
|
}
|
|
|
+
|
|
|
+// @Title 微信登录小助手接口
|
|
|
+// @Description 微信登录小助手接口
|
|
|
+// @Param Code query string true "微信唯一编码code"
|
|
|
+// @Success 200 {object} models.WxLoginResp
|
|
|
+// @router /loginByxzs [get]
|
|
|
+func (this *WechatCommonController) WechatLoginByxzs() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ code := this.GetString("Code")
|
|
|
+ if code == "" {
|
|
|
+ br.Msg = "参数错误"
|
|
|
+ br.ErrMsg = "Code 为空"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ item, err := services.WxGetUserOpenIdByCodeXzs(code)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取用户信息失败"
|
|
|
+ br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if item.Errcode != 0 {
|
|
|
+ br.Msg = "获取用户信息失败"
|
|
|
+ br.ErrMsg = "获取access_token 失败 errcode:" + strconv.Itoa(item.Errcode) + " ;errmsg:" + item.Errmsg
|
|
|
+ return
|
|
|
+ }
|
|
|
+ openId := item.Openid
|
|
|
+ if openId == "" {
|
|
|
+ br.Msg = "获取用户信息失败"
|
|
|
+ br.ErrMsg = "获取openid失败,openid:" + item.Openid
|
|
|
+ return
|
|
|
+ }
|
|
|
+ unionId := item.Unionid
|
|
|
+ if unionId == "" {
|
|
|
+ br.Msg = "获取用户信息失败"
|
|
|
+ br.ErrMsg = "获取unionid失败,unionid:" + item.Openid
|
|
|
+ return
|
|
|
+ }
|
|
|
+ total, err := models.GetCygxUserRecordCount(openId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取用户信息失败"
|
|
|
+ br.ErrMsg = "查询数量失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if total == 0 {
|
|
|
+ items := new(models.CygxUserRecord)
|
|
|
+ items.OpenId = openId
|
|
|
+ items.UnionId = unionId
|
|
|
+ items.CreateTime = time.Now()
|
|
|
+ _, err = models.AddCygxUserRecord(items)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取用户信息失败"
|
|
|
+ br.ErrMsg = "添加openid失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+ br.Data = item
|
|
|
+}
|