|
@@ -59,7 +59,8 @@ func (this *WechatController) Notify() {
|
|
|
<Content><![CDATA[%s]]></Content>
|
|
|
</xml>`
|
|
|
createTime := strconv.FormatInt(time.Now().Unix(), 10)
|
|
|
- xmlTpl = fmt.Sprintf(xmlTpl, openId, utils.DW_WX_Id, createTime, contactMsg)
|
|
|
+ WxId := "gh_5dc508325c6f" // 研报公众号原始id
|
|
|
+ xmlTpl = fmt.Sprintf(xmlTpl, openId, WxId, createTime, contactMsg)
|
|
|
|
|
|
if item.MsgType == "event" {
|
|
|
switch item.Event {
|
|
@@ -95,7 +96,7 @@ func subscribe(openId string) {
|
|
|
|
|
|
// openId已存在
|
|
|
if userRecord != nil {
|
|
|
- if userRecord.UserId > 0 { //已经绑定了的话,那么就去修改用户状态
|
|
|
+ if userRecord.UserId > 0 && userRecord.UnionId != "" { //已经绑定了的话,那么就去修改用户状态
|
|
|
models.UserSubscribe(1, openId)
|
|
|
} else {
|
|
|
// 没有绑定的话,那么校验下unionid,然后再去修改
|
|
@@ -110,23 +111,10 @@ func subscribe(openId string) {
|
|
|
unionId = wxUserItem.UnionID
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- updateCol := make([]string, 0)
|
|
|
+ userRecord.UnionId = unionId
|
|
|
userRecord.Subscribe = 1
|
|
|
userRecord.SubscribeTime = time.Now()
|
|
|
- updateCol = append(updateCol, "Subscribe")
|
|
|
- if unionId != `` {
|
|
|
- userRecord.UnionId = unionId
|
|
|
- // 通过unionid获取已绑定用户的user_record信息
|
|
|
- bindUserRecord, _ := models.GetBindUserRecordByUnionId(unionId)
|
|
|
- if bindUserRecord != nil {
|
|
|
- userRecord.UserId = bindUserRecord.UserId
|
|
|
- userRecord.RealName = bindUserRecord.RealName
|
|
|
- userRecord.Sex = bindUserRecord.Sex
|
|
|
- updateCol = append(updateCol, "UserId", "RealName")
|
|
|
- }
|
|
|
- }
|
|
|
- err = userRecord.Update(updateCol)
|
|
|
+ err = userRecord.Update([]string{"union_id", "subscribe", "subscribe_time"})
|
|
|
if err != nil {
|
|
|
fmt.Println("关注后,通过openid更新user_record异常,ERR:", err)
|
|
|
}
|
|
@@ -142,7 +130,6 @@ func subscribe(openId string) {
|
|
|
return
|
|
|
}
|
|
|
newUserRecord := &models.UserRecord{
|
|
|
- UserRecordId: 0,
|
|
|
OpenId: openId,
|
|
|
UnionId: wxUserItem.UnionID,
|
|
|
Subscribe: 1,
|
|
@@ -155,19 +142,6 @@ func subscribe(openId string) {
|
|
|
Headimgurl: wxUserItem.Headimgurl,
|
|
|
CreateTime: time.Now(),
|
|
|
}
|
|
|
- if wxUserItem.UnionID != `` {
|
|
|
- // 通过unionid获取已绑定用户的user_record信息
|
|
|
- bindUserRecord, _ := models.GetBindUserRecordByUnionId(wxUserItem.UnionID)
|
|
|
- if bindUserRecord != nil {
|
|
|
- newUserRecord.UserId = bindUserRecord.UserId
|
|
|
- newUserRecord.RealName = bindUserRecord.RealName
|
|
|
- newUserRecord.Sex = bindUserRecord.Sex
|
|
|
- newUserRecord.Province = bindUserRecord.Province
|
|
|
- newUserRecord.City = bindUserRecord.City
|
|
|
- newUserRecord.Country = bindUserRecord.Country
|
|
|
- newUserRecord.Headimgurl = bindUserRecord.Headimgurl
|
|
|
- }
|
|
|
- }
|
|
|
insertId, err := newUserRecord.Insert()
|
|
|
newUserRecord.UserRecordId = int(insertId)
|
|
|
if err != nil {
|
|
@@ -292,18 +266,27 @@ func (this *WechatController) Subscribe() {
|
|
|
br.ErrMsg = "获取失败,Err:" + info.ErrMsg
|
|
|
return
|
|
|
}
|
|
|
- u := &models.UserRecord{
|
|
|
- OpenId: info.OpenId,
|
|
|
- }
|
|
|
- insertId, err := u.Insert()
|
|
|
- if err != nil {
|
|
|
- br.Msg = "新增失败"
|
|
|
- br.ErrMsg = "新增失败,Err:" + err.Error()
|
|
|
+ userRecord, err := models.GetUserRecordByOpenId(info.OpenId)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取用户关注记录失败"
|
|
|
+ br.ErrMsg = "获取用户关注记录失败,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
- u.UserRecordId = int(insertId)
|
|
|
- if u.UnionId == "" {
|
|
|
- wxInfo, er := wechat.GetUserInfo(u.OpenId)
|
|
|
+ // 如果不存在就新增一条记录
|
|
|
+ if userRecord == nil {
|
|
|
+ userRecord := &models.UserRecord{
|
|
|
+ OpenId: info.OpenId,
|
|
|
+ }
|
|
|
+ insertId, err := userRecord.Insert()
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "新增失败"
|
|
|
+ br.ErrMsg = "新增失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ userRecord.UserRecordId = int(insertId)
|
|
|
+ }
|
|
|
+ if userRecord.UnionId == "" {
|
|
|
+ wxInfo, er := wechat.GetUserInfo(userRecord.OpenId)
|
|
|
if er != nil {
|
|
|
br.Msg = "获取失败"
|
|
|
br.ErrMsg = "获取失败,Err:" + er.Error()
|
|
@@ -311,8 +294,8 @@ func (this *WechatController) Subscribe() {
|
|
|
}
|
|
|
wxBody, _ := json.Marshal(wxInfo)
|
|
|
alarm_msg.SendAlarmMsg(string(wxBody), 1)
|
|
|
- u.UnionId = wxInfo.UnionID
|
|
|
- er = u.Update([]string{"union_id"})
|
|
|
+ userRecord.UnionId = wxInfo.UnionID
|
|
|
+ er = userRecord.Update([]string{"union_id"})
|
|
|
if er != nil {
|
|
|
br.Msg = "获取失败"
|
|
|
br.ErrMsg = "获取失败,Err:" + er.Error()
|
|
@@ -320,7 +303,7 @@ func (this *WechatController) Subscribe() {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- user, err := models.GetUserByUnionId(u.UnionId)
|
|
|
+ user, err := models.GetUserByUnionId(userRecord.UnionId)
|
|
|
if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
br.Msg = "获取用户信息失败"
|
|
|
br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
|