Kaynağa Gözat

Merge branch 'feature/migrate_wechat_msg' of hongze/hongze_yb into master

xyxie 2 yıl önce
ebeveyn
işleme
01cef1cd2e

+ 1 - 5
logic/yb_community_question/yb_community_question_comment.go

@@ -466,12 +466,8 @@ func wxMessageToAdmin(adminInfo admin.Admin, communityQuestionComment *yb_commun
 	if global.CONFIG.Serve.RunMode == "debug" {
 		adminInfo.Mobile = `18221983795`
 	}
-	wxUser, err := wx_user.GetByMobile(adminInfo.Mobile)
-	if err != nil {
-		return
-	}
 
-	err = wechat.SendQuestionCommentToAdmin(int(communityQuestionComment.CommunityQuestionCommentID), int(wxUser.UserID), communityQuestionComment.Content)
+	err = wechat.SendQuestionCommentToAdmin(int(communityQuestionComment.CommunityQuestionCommentID), int(adminInfo.AdminID), adminInfo.OpenId, communityQuestionComment.Content)
 	return
 }
 

+ 1 - 0
models/tables/admin/admin.go

@@ -27,6 +27,7 @@ type Admin struct {
 	GroupName               string    `gorm:"column:group_name;type:varchar(100)" json:"groupName"`                  // 分组名称
 	Authority               int8      `gorm:"column:authority;type:tinyint(4);default:0" json:"authority"`           // 管理权限,0:无,1:部门负责人,2:小组负责人,3:超级管理员
 	Position                string    `gorm:"column:position;type:varchar(100)" json:"position"`                     // 职位
+	OpenId                  string    `gorm:"column:open_id;type:varchar(100)" json:"open_id"`                       // 弘则部门openid
 }
 
 // TableName get sql table name.获取数据库表名

+ 1 - 5
services/community/question.go

@@ -594,11 +594,7 @@ func wxMessageToAdmin(adminInfo admin.Admin, ybCommunityQuestion *yb_community_q
 	if global.CONFIG.Serve.RunMode == "debug" {
 		adminInfo.Mobile = `18221983795`
 	}
-	wxUser, err := wx_user.GetByMobile(adminInfo.Mobile)
-	if err != nil {
-		return
-	}
 
-	err = wechat.SendQuestionToAdmin(ybCommunityQuestion.CommunityQuestionID, int(wxUser.UserID), ybCommunityQuestion.QuestionContent)
+	err = wechat.SendQuestionToAdmin(ybCommunityQuestion.CommunityQuestionID, int(adminInfo.AdminID), adminInfo.OpenId, ybCommunityQuestion.QuestionContent)
 	return
 }

+ 16 - 47
services/wechat/template_msg.go

@@ -47,6 +47,7 @@ type OpenIdList struct {
 }
 
 type SendWxTemplate struct {
+	WxAppId        string   `description:"公众号appId"`
 	First          string   `description:"模板消息first字段"`
 	Keyword1       string   `description:"模板消息keyword1字段"`
 	Keyword2       string   `description:"模板消息keyword2字段"`
@@ -297,6 +298,7 @@ func SendQuestionReplyWxMsg(questionId, userId int, questionTitle string) (err e
 	}
 
 	sendInfo := new(SendWxTemplate)
+	sendInfo.WxAppId = WxAppId
 	sendInfo.First = first
 	sendInfo.Keyword1 = keyword1
 	sendInfo.Keyword2 = keyword2
@@ -309,7 +311,6 @@ func SendQuestionReplyWxMsg(questionId, userId int, questionTitle string) (err e
 	sendInfo.OpenIdArr = openIdArr
 
 	err = SendTemplateMsg(sendInfo)
-
 	return
 }
 
@@ -368,8 +369,8 @@ func SendVoiceBroadcastWxMsg(broadcastId int, sectionName, broadcastName string)
 	for i, v := range openIdList {
 		openIdArr[i] = v.OpenId
 	}
-
 	sendInfo := new(SendWxTemplate)
+	sendInfo.WxAppId = WxAppId
 	sendInfo.First = first
 	sendInfo.Keyword1 = keyword1
 	sendInfo.Keyword2 = keyword2
@@ -382,7 +383,6 @@ func SendVoiceBroadcastWxMsg(broadcastId int, sectionName, broadcastName string)
 	sendInfo.OpenIdArr = openIdArr
 
 	err = SendTemplateMsg(sendInfo)
-
 	return
 }
 
@@ -427,8 +427,8 @@ func SendMultiTemplateMsgNoReturn(sendMap map[string]interface{}, items []*OpenI
 }
 
 // SendQuestionToAdmin 推送研报小程序模板消息-用户提问时,通知到管理员
-func SendQuestionToAdmin(questionId, userId int, questionTitle string) (err error) {
-	if userId == 0 {
+func SendQuestionToAdmin(questionId, adminId int, adminOpenId string, questionTitle string) (err error) {
+	if adminId == 0 || adminOpenId == "" {
 		return
 	}
 	var errMsg string
@@ -438,25 +438,11 @@ func SendQuestionToAdmin(questionId, userId int, questionTitle string) (err erro
 			go alarm_msg.SendAlarmMsg(alarmMsg, 3)
 		}
 	}()
-	// 校验用户是否取消关注公众号
-	userRecord, e := user_record.GetByUserId(userId, utils.USER_RECORD_PLATFORM_RDDP)
-	if e != nil {
-		// 用户无公众号信息
-		if e == utils.ErrNoRow {
-			return
-		}
-		err = errors.New("获取用户Record信息失败, Err:" + e.Error())
-		return
-	}
-	// 取消关注则不推送
-	if userRecord.Subscribe == 0 {
-		return
-	}
 
 	openIdList := make([]*OpenIdList, 0)
 	openIdList = append(openIdList, &OpenIdList{
-		OpenId: userRecord.OpenID,
-		UserId: userId,
+		OpenId: adminOpenId,
+		UserId: 0,
 	})
 
 	//sendMap := make(map[string]interface{})
@@ -471,7 +457,6 @@ func SendQuestionToAdmin(questionId, userId int, questionTitle string) (err erro
 	//sendData["keyword1"] = map[string]interface{}{"value": keyword1, "color": "#173177"}
 	//sendData["keyword2"] = map[string]interface{}{"value": keyword2, "color": "#173177"}
 	//sendData["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
-
 	//sendMap["template_id"] = TemplateIdWithCommunityQuestion
 	//sendMap["data"] = sendData
 
@@ -489,27 +474,26 @@ func SendQuestionToAdmin(questionId, userId int, questionTitle string) (err erro
 	for i, v := range openIdList {
 		openIdArr[i] = v.OpenId
 	}
-
 	sendInfo := new(SendWxTemplate)
+	sendInfo.WxAppId = AdminWxAppId
 	sendInfo.First = first
 	sendInfo.Keyword1 = keyword1
 	sendInfo.Keyword2 = keyword2
 	sendInfo.Remark = remark
 	sendInfo.RedirectUrl = wxAppPath
-	sendInfo.TemplateId = TemplateIdWithCommunityQuestion
+	sendInfo.TemplateId = TemplateIdWithCommunityQuestionNotifyAdmin
 	sendInfo.RedirectTarget = 2
 	sendInfo.Resource = wxAppPath
 	sendInfo.SendType = utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION
 	sendInfo.OpenIdArr = openIdArr
 
 	err = SendTemplateMsg(sendInfo)
-
 	return
 }
 
 // SendQuestionCommentToAdmin 推送研报小程序模板消息-用户评论问答时,通知到管理员
-func SendQuestionCommentToAdmin(commentId, userId int, commentContent string) (err error) {
-	if userId == 0 {
+func SendQuestionCommentToAdmin(commentId, adminId int, adminOpenId string,  commentContent string) (err error) {
+	if adminId == 0 || adminOpenId == "" {
 		return
 	}
 	var errMsg string
@@ -519,25 +503,11 @@ func SendQuestionCommentToAdmin(commentId, userId int, commentContent string) (e
 			go alarm_msg.SendAlarmMsg(alarmMsg, 3)
 		}
 	}()
-	// 校验用户是否取消关注公众号
-	userRecord, e := user_record.GetByUserId(userId, utils.USER_RECORD_PLATFORM_RDDP)
-	if e != nil {
-		// 用户无公众号信息
-		if e == utils.ErrNoRow {
-			return
-		}
-		err = errors.New("获取用户Record信息失败, Err:" + e.Error())
-		return
-	}
-	// 取消关注则不推送
-	if userRecord.Subscribe == 0 {
-		return
-	}
 
 	openIdList := make([]*OpenIdList, 0)
 	openIdList = append(openIdList, &OpenIdList{
-		OpenId: userRecord.OpenID,
-		UserId: userId,
+		OpenId: adminOpenId,
+		UserId: 0,
 	})
 
 	//sendMap := make(map[string]interface{})
@@ -552,7 +522,6 @@ func SendQuestionCommentToAdmin(commentId, userId int, commentContent string) (e
 	//sendData["keyword1"] = map[string]interface{}{"value": keyword1, "color": "#173177"}
 	//sendData["keyword2"] = map[string]interface{}{"value": keyword2, "color": "#173177"}
 	//sendData["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
-
 	//sendMap["template_id"] = TemplateIdWithCommunityQuestion
 	//sendMap["data"] = sendData
 
@@ -570,14 +539,14 @@ func SendQuestionCommentToAdmin(commentId, userId int, commentContent string) (e
 	for i, v := range openIdList {
 		openIdArr[i] = v.OpenId
 	}
-
 	sendInfo := new(SendWxTemplate)
+	sendInfo.WxAppId = AdminWxAppId
 	sendInfo.First = first
 	sendInfo.Keyword1 = keyword1
 	sendInfo.Keyword2 = keyword2
 	sendInfo.Remark = remark
 	sendInfo.RedirectUrl = wxAppPath
-	sendInfo.TemplateId = TemplateIdWithCommunityQuestion
+	sendInfo.TemplateId = TemplateIdWithCommunityQuestionNotifyAdmin
 	sendInfo.RedirectTarget = 2
 	sendInfo.Resource = wxAppPath
 	sendInfo.SendType = utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION
@@ -585,4 +554,4 @@ func SendQuestionCommentToAdmin(commentId, userId int, commentContent string) (e
 
 	err = SendTemplateMsg(sendInfo)
 	return
-}
+}

+ 14 - 1
services/wechat/wechat.go

@@ -23,6 +23,7 @@ var (
 	WxAppId                         string
 	WxAppSecret                     string
 	TemplateIdWithCommunityQuestion string // 问答社区回复模板消息ID
+	TemplateIdWithCommunityQuestionNotifyAdmin string // 问答社区 有提问通知管理员
 	WxYbAppId                       string // 研报小程序AppID
 	PcWxAppId                       string //pc版AppId
 	PcWxAppSecret                   string //pc版AppSecret
@@ -30,6 +31,10 @@ var (
 	WxMobileCrmAppId     string //随手办公小程序appid
 	WxMobileCrmId        string //随手办公小程序id
 	WxAppMobileCrmSecret string //随手办公小程序秘钥
+
+	//内部员工公众号(弘则部门)
+	AdminWxAppId                    string
+	AdminWxAppSecret                string
 )
 
 func init() {
@@ -39,12 +44,17 @@ func init() {
 	WxMobileCrmId = `wx67b68e39913e511e`
 	WxAppMobileCrmSecret = `660b0375f701a19220bb8a662b41c77c`
 
+	//内部员工公众号(弘则部门)
+	AdminWxAppId = "wx1392111da5426e9e"
+	AdminWxAppSecret = "30eceb7cf29bf2f046031155ab55d7b4"
+
 	if global.CONFIG.Serve.RunMode == "debug" {
 		WxAppId = "wx9b5d7291e581233a"
 		WxAppSecret = "f4d52e34021eee262dce9682b31f8861"
 		WxId = "gh_5dc508325c6f"
 
 		TemplateIdWithCommunityQuestion = "CB7bOl7f3viMG4s1uhRo7WM0Jbx3WvodKuIZ8A_z8fM"
+		TemplateIdWithCommunityQuestionNotifyAdmin = "rciDm9ThigRBGi1SZ4TFd74XA4aoAxSz_ugdv_tZ450"
 		PcWxAppId = "wxcba9a7ec590ee2d5"
 		PcWxAppSecret = "aa58d257e2521d768cbf1bf89989769d"
 
@@ -54,6 +64,7 @@ func init() {
 		WxId = "gh_b67e0049fb8c"
 
 		TemplateIdWithCommunityQuestion = "dYg6iHooRq74PyCXmw_Ns7qdJZmbtLoKS2p2FKeaXl0"
+		TemplateIdWithCommunityQuestionNotifyAdmin = "rciDm9ThigRBGi1SZ4TFd74XA4aoAxSz_ugdv_tZ450"
 		PcWxAppId = "wx4da95782cfc8c5eb"
 		PcWxAppSecret = "8f82ebf2ba3aa06ce44541726385df64"
 
@@ -71,7 +82,6 @@ func GetWxChat() (officialAccount *officialaccount.OfficialAccount) {
 		Cache:          memory,
 	}
 	officialAccount = wc.GetOfficialAccount(conf)
-
 	wechatAccessToken := &WechatAccessToken{}
 	officialAccount.SetAccessTokenHandle(wechatAccessToken)
 	return
@@ -96,6 +106,7 @@ func GetJsConfig(signUrl string) (jsConf *js.Config, err error) {
 type WechatAccessToken struct {
 }
 
+
 // GetAccessToken 获取accessToken
 func (wechat WechatAccessToken) GetAccessToken() (accessToken string, err error) {
 	wxToken, err := wx_token.GetById()
@@ -157,3 +168,5 @@ func PcWxGetUserInfo(openId, accessToken string) (item *pc.WxUserInfo, err error
 	err = json.Unmarshal(result, &item)
 	return
 }
+
+

+ 1 - 0
utils/constants.go

@@ -130,6 +130,7 @@ const ALIYUN_YBIMG_HOST = "https://hzstatic.hzinsights.com/static/yb_wx/"
 const HZ_DEFAULT_AVATAR = "https://hzstatic.hzinsights.com/static/yb_wx/hz_default_avatar.png"
 
 const HZPHONE = "057187186319" //弘则电话
+const HZ_ADMIN_WX_ACCESS_TOEKN = "hz_admin:wx:access_token:"
 
 //模板消息推送类型
 const (