|
@@ -301,25 +301,44 @@ func (this *WechatCommonController) Notify() {
|
|
</xml>`
|
|
</xml>`
|
|
createTime := strconv.FormatInt(time.Now().Unix(), 10)
|
|
createTime := strconv.FormatInt(time.Now().Unix(), 10)
|
|
xmlTpl = fmt.Sprintf(xmlTpl, openId, utils.WxId, createTime, contactMsg)
|
|
xmlTpl = fmt.Sprintf(xmlTpl, openId, utils.WxId, createTime, contactMsg)
|
|
- accessToken, err := services.GetWxAccessTokenByXzs()
|
|
|
|
|
|
+
|
|
|
|
+ total, err := models.GetCygxUserRecordCount(openId)
|
|
if err != nil {
|
|
if err != nil {
|
|
- utils.FileLog.Info("accessToken:" + err.Error())
|
|
|
|
- }
|
|
|
|
- if accessToken == "" {
|
|
|
|
- utils.FileLog.Info("access_token 为空 openId:" + openId)
|
|
|
|
|
|
+ utils.FileLog.Info("GetCygxUserRecordCount:" + err.Error())
|
|
}
|
|
}
|
|
- wxUserInfo, err := services.WxGetUserInfo(openId, accessToken)
|
|
|
|
- if err != nil {
|
|
|
|
- utils.FileLog.Info("accessToken:" + err.Error())
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- if wxUserInfo.Errcode != 0 {
|
|
|
|
- userInfoJson, _ := json.Marshal(wxUserInfo)
|
|
|
|
- utils.FileLog.Info("获取用户信息失败,err:" + string(userInfoJson))
|
|
|
|
|
|
+ var unionId string
|
|
|
|
+ if total == 0 {
|
|
|
|
+ accessToken, err := services.GetWxAccessTokenByXzs()
|
|
|
|
+ if err != nil {
|
|
|
|
+ utils.FileLog.Info("accessToken:" + err.Error())
|
|
|
|
+ }
|
|
|
|
+ if accessToken == "" {
|
|
|
|
+ utils.FileLog.Info("access_token 为空 openId:" + openId)
|
|
|
|
+ }
|
|
|
|
+ wxUserInfo, err := services.WxGetUserInfo(openId, accessToken)
|
|
|
|
+ if err != nil {
|
|
|
|
+ utils.FileLog.Info("accessToken:" + err.Error())
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if wxUserInfo.Errcode != 0 {
|
|
|
|
+ userInfoJson, _ := json.Marshal(wxUserInfo)
|
|
|
|
+ utils.FileLog.Info("获取用户信息失败,err:" + string(userInfoJson))
|
|
|
|
+ }
|
|
|
|
+ unionId = wxUserInfo.Unionid
|
|
|
|
+ if unionId != "" {
|
|
|
|
+ services.AddCygxUserRecord(wxUserInfo)
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ userRecordDetail, err := models.GetCygxUserRecordByOpenid(openId)
|
|
|
|
+ if err != nil {
|
|
|
|
+ utils.FileLog.Info("GetCygxUserRecordByOpenid:" + err.Error())
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ unionId = userRecordDetail.UnionId
|
|
}
|
|
}
|
|
- unionId := wxUserInfo.Unionid
|
|
|
|
if unionId == "" {
|
|
if unionId == "" {
|
|
utils.FileLog.Info("获取unionid失败,openId:" + openId)
|
|
utils.FileLog.Info("获取unionid失败,openId:" + openId)
|
|
|
|
+ return
|
|
}
|
|
}
|
|
wxUser, err := models.GetUserRecordByUnionId(unionId)
|
|
wxUser, err := models.GetUserRecordByUnionId(unionId)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -334,10 +353,12 @@ func (this *WechatCommonController) Notify() {
|
|
case "subscribe":
|
|
case "subscribe":
|
|
fmt.Println("关注")
|
|
fmt.Println("关注")
|
|
go models.UserSubscribe(1, wxUser.UserId)
|
|
go models.UserSubscribe(1, wxUser.UserId)
|
|
|
|
+ go models.CygxUserSubscribe(1, unionId)
|
|
break
|
|
break
|
|
case "unsubscribe":
|
|
case "unsubscribe":
|
|
fmt.Println("取消关注")
|
|
fmt.Println("取消关注")
|
|
go models.UserSubscribe(0, wxUser.UserId)
|
|
go models.UserSubscribe(0, wxUser.UserId)
|
|
|
|
+ go models.CygxUserSubscribe(0, unionId)
|
|
break
|
|
break
|
|
case "CLICK":
|
|
case "CLICK":
|
|
returnResult = xmlTpl
|
|
returnResult = xmlTpl
|