|
@@ -36,6 +36,7 @@ func (this *WechatCommonController) WechatLoginByGzh() {
|
|
|
br.ErrMsg = "Code 为空"
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
var token string
|
|
|
item, err := services.WxGetUserOpenIdByCodeGzh(code)
|
|
|
if err != nil {
|
|
@@ -45,7 +46,7 @@ func (this *WechatCommonController) WechatLoginByGzh() {
|
|
|
}
|
|
|
if item.Errcode != 0 {
|
|
|
br.Msg = "获取用户信息失败"
|
|
|
- br.ErrMsg = "获取access_token 失败 errcode:" + strconv.Itoa(item.Errcode) + " ;errmsg:" + item.Errmsg
|
|
|
+ br.ErrMsg = "获取access_token 失败 errcode:" + strconv.Itoa(item.Errcode) + " ;errmsg:" + item.Errmsg+"appid:" + utils.WxPublicAppId+"secret:"+utils.WxPublicAppSecret
|
|
|
return
|
|
|
}
|
|
|
openId := item.Openid
|
|
@@ -85,8 +86,8 @@ func (this *WechatCommonController) WechatLoginByGzh() {
|
|
|
br.ErrMsg = "获取unionid失败,unionid:" + wxUserInfo.Unionid
|
|
|
return
|
|
|
}
|
|
|
- total, err := models.GetCygxUserRecordCount(openId)
|
|
|
- if err != nil {
|
|
|
+ mfyxUserRecord, err := models.GetCygxUserRecordByOpenid(openId)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
br.Msg = "获取用户信息失败"
|
|
|
br.ErrMsg = "查询数量失败,Err:" + err.Error()
|
|
|
return
|
|
@@ -107,18 +108,47 @@ func (this *WechatCommonController) WechatLoginByGzh() {
|
|
|
items.Country = wxUserInfo.Country
|
|
|
items.Headimgurl = wxUserInfo.Headimgurl
|
|
|
items.CreateTime = time.Now()
|
|
|
+ items.Subscribe = 1
|
|
|
+ items.SubscribeTime = time.Now()
|
|
|
if user != nil {
|
|
|
items.CygxUserId = user.UserId
|
|
|
items.CygxBindAccount = user.Mobile
|
|
|
+ if mfyxUserRecord != nil && mfyxUserRecord.CygxUserId != user.UserId {
|
|
|
+ err = models.UpdateCygxUserRecordMobile(user.UserId, user.Mobile, unionId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "修复用户信息失败"
|
|
|
+ br.ErrMsg = "修复用户信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- if total == 0 {
|
|
|
- _, err = models.AddCygxUserRecord(items)
|
|
|
+ if mfyxUserRecord == nil {
|
|
|
+ _, err = models.AddMfyxGzhUserRecord(items)
|
|
|
if err != nil {
|
|
|
br.Msg = "获取用户信息失败"
|
|
|
br.ErrMsg = "添加openid失败,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
+ userRecord := &models.UserRecord{
|
|
|
+ OpenId: openId, //用户open_id
|
|
|
+ UnionId: unionId, //用户union_id
|
|
|
+ Subscribe: 0,
|
|
|
+ NickName: wxUserInfo.Nickname, //用户昵称,最大长度:32
|
|
|
+ RealName: "", //用户实际名称,最大长度:32
|
|
|
+ Sex: wxUserInfo.Sex, //普通用户性别,1为男性,2为女性
|
|
|
+ Province: wxUserInfo.Province, //普通用户个人资料填写的省份,最大长度:30
|
|
|
+ City: wxUserInfo.City, //普通用户个人资料填写的城市,最大长度:30
|
|
|
+ Country: wxUserInfo.Country, //国家,如中国为CN,最大长度:30
|
|
|
+ Headimgurl: wxUserInfo.Headimgurl, //用户第三方(微信)头像,最大长度:512
|
|
|
+ CreateTime: time.Now(), //创建时间,关系添加时间、用户授权时间
|
|
|
+ CreatePlatform: 12, //注册平台,1:日度点评公众号,2:管理后台,3:pc端网站,4:查研观向小程序;默认:1
|
|
|
+ SessionKey: wxUserInfo.SessionKey, //微信小程序会话密钥,最大长度:255
|
|
|
+ }
|
|
|
+ _, err = models.AddUserRecord(userRecord)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
timeUnix := time.Now().Unix()
|
|
|
timeUnixStr := strconv.FormatInt(timeUnix, 10)
|
|
|
|
|
@@ -172,6 +202,9 @@ func (this *WechatCommonController) WechatLoginByGzh() {
|
|
|
}
|
|
|
resp.Headimgurl = user.HeadimgurlRecord
|
|
|
}
|
|
|
+ if resp.Headimgurl == "" {
|
|
|
+ resp.Headimgurl = utils.DefaultHeadimgurl
|
|
|
+ }
|
|
|
resp.Token = token
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|
|
@@ -351,11 +384,11 @@ func (this *WechatController) UserInfo() {
|
|
|
detail.HasPermission = hasPermission
|
|
|
|
|
|
} else {
|
|
|
- ur, _ := models.GetUserRecordByOpenId(user.OpenId)
|
|
|
+ ur, _ := models.GetCygxUserRecordByOpenid(user.OpenId)
|
|
|
if ur != nil {
|
|
|
detail.NickName = ur.NickName
|
|
|
- detail.Email = ur.BindAccount
|
|
|
- detail.Mobile = ur.BindAccount
|
|
|
+ detail.Email = ur.CygxBindAccount
|
|
|
+ detail.Mobile = ur.CygxBindAccount
|
|
|
detail.NickName = ur.NickName
|
|
|
detail.Headimgurl = ur.Headimgurl
|
|
|
}
|
|
@@ -377,7 +410,7 @@ func (this *WechatController) UserInfo() {
|
|
|
// @Success 200 {object} models.WechatSign
|
|
|
// @router /notify [get,post]
|
|
|
func (this *WechatCommonController) Notify() {
|
|
|
- echostr := this.GetString("echostr")
|
|
|
+ //echostr := this.GetString("echostr")
|
|
|
method := this.Ctx.Input.Method()
|
|
|
if method == "POST" {
|
|
|
body := this.Ctx.Input.RequestBody
|
|
@@ -474,8 +507,9 @@ func (this *WechatCommonController) Notify() {
|
|
|
} else {
|
|
|
returnResult = xmlTpl
|
|
|
}
|
|
|
+ returnResult = "hongze"
|
|
|
this.Ctx.WriteString(returnResult)
|
|
|
} else {
|
|
|
- this.Ctx.WriteString(echostr)
|
|
|
+ this.Ctx.WriteString("hongze")
|
|
|
}
|
|
|
}
|