|
@@ -118,7 +118,7 @@ func (c *TemplateMsgSendClient) ClearQuota() (result *ClearQuotaResponse, err er
|
|
|
}
|
|
|
|
|
|
// AddUserTemplateRecord 新增模板消息推送记录
|
|
|
-func AddUserTemplateRecord(userId, sendStatus, sendType int, openid, resource, sendData, result string) (err error) {
|
|
|
+func AddUserTemplateRecord(wxAppId string, userId, sendStatus, sendType int, openid, resource, sendData, result string) (err error) {
|
|
|
item := &user_template_record.UserTemplateRecord{
|
|
|
UserID: userId,
|
|
|
OpenID: openid,
|
|
@@ -129,14 +129,15 @@ func AddUserTemplateRecord(userId, sendStatus, sendType int, openid, resource, s
|
|
|
CreateTime: time.Now().Format(utils.FormatDateTime),
|
|
|
SendStatus: sendStatus,
|
|
|
SendType: sendType,
|
|
|
+ WxAppId: wxAppId,
|
|
|
}
|
|
|
err = item.Create()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// SendMultiTemplateMsg 推送模板消息至多个用户
|
|
|
-func SendMultiTemplateMsg(sendMap map[string]interface{}, items []*OpenIdList, resource string, sendType int) (err error) {
|
|
|
- ws := GetWxChat()
|
|
|
+func SendMultiTemplateMsg(wxAppId, wxAppSecret string, sendMap map[string]interface{}, items []*OpenIdList, resource string, sendType int) (err error) {
|
|
|
+ ws := GetWxChat(wxAppId, wxAppSecret)
|
|
|
accessToken, err := ws.GetAccessToken()
|
|
|
if err != nil {
|
|
|
return
|
|
@@ -164,7 +165,7 @@ func SendMultiTemplateMsg(sendMap map[string]interface{}, items []*OpenIdList, r
|
|
|
sendStatus = 0
|
|
|
}
|
|
|
resultJson, _ := json.Marshal(result)
|
|
|
- _ = AddUserTemplateRecord(v.UserId, sendStatus, sendType, v.OpenId, resource, string(data), string(resultJson))
|
|
|
+ _ = AddUserTemplateRecord(wxAppId, v.UserId, sendStatus, sendType, v.OpenId, resource, string(data), string(resultJson))
|
|
|
}(item)
|
|
|
}
|
|
|
if e != nil {
|
|
@@ -232,7 +233,7 @@ func SendQuestionReplyWxMsg(questionId, userId int, questionTitle string) (err e
|
|
|
if wxAppPath != "" {
|
|
|
sendMap["miniprogram"] = map[string]interface{}{"appid": WxYbAppId, "pagepath": wxAppPath}
|
|
|
}
|
|
|
- err = SendMultiTemplateMsg(sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION)
|
|
|
+ err = SendMultiTemplateMsg(WxAppId, WxAppSecret, sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -285,13 +286,13 @@ func SendVoiceBroadcastWxMsg(broadcastId int, sectionName, broadcastName string)
|
|
|
if wxAppPath != "" {
|
|
|
sendMap["miniprogram"] = map[string]interface{}{"appid": WxYbAppId, "pagepath": wxAppPath}
|
|
|
}
|
|
|
- err = SendMultiTemplateMsgNoReturn(sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_VOICE_BROADCAST)
|
|
|
+ err = SendMultiTemplateMsgNoReturn(WxAppId, WxAppSecret, sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_VOICE_BROADCAST)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// SendMultiTemplateMsg 推送模板消息至多个用户中间出错不返回
|
|
|
-func SendMultiTemplateMsgNoReturn(sendMap map[string]interface{}, items []*OpenIdList, resource string, sendType int) (err error) {
|
|
|
- ws := GetWxChat()
|
|
|
+func SendMultiTemplateMsgNoReturn(wxAppId, wxAppSecret string, sendMap map[string]interface{}, items []*OpenIdList, resource string, sendType int) (err error) {
|
|
|
+ ws := GetWxChat(wxAppId, wxAppSecret)
|
|
|
accessToken, err := ws.GetAccessToken()
|
|
|
if err != nil {
|
|
|
return
|
|
@@ -319,7 +320,7 @@ func SendMultiTemplateMsgNoReturn(sendMap map[string]interface{}, items []*OpenI
|
|
|
sendStatus = 0
|
|
|
}
|
|
|
resultJson, _ := json.Marshal(result)
|
|
|
- _ = AddUserTemplateRecord(v.UserId, sendStatus, sendType, v.OpenId, resource, string(data), string(resultJson))
|
|
|
+ _ = AddUserTemplateRecord(wxAppId, v.UserId, sendStatus, sendType, v.OpenId, resource, string(data), string(resultJson))
|
|
|
}(item)
|
|
|
}
|
|
|
if e != nil {
|
|
@@ -330,8 +331,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
|
|
@@ -341,25 +342,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{})
|
|
@@ -375,7 +362,7 @@ func SendQuestionToAdmin(questionId, userId int, questionTitle string) (err erro
|
|
|
sendData["keyword2"] = map[string]interface{}{"value": keyword2, "color": "#173177"}
|
|
|
sendData["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
|
|
|
|
|
|
- sendMap["template_id"] = TemplateIdWithCommunityQuestion
|
|
|
+ sendMap["template_id"] = TemplateIdWithCommunityQuestionNotifyAdmin
|
|
|
sendMap["data"] = sendData
|
|
|
|
|
|
wxAppPath := fmt.Sprintf("/pages-question/detail/index?type=question&id=%d", questionId)
|
|
@@ -386,13 +373,13 @@ func SendQuestionToAdmin(questionId, userId int, questionTitle string) (err erro
|
|
|
if wxAppPath != "" {
|
|
|
sendMap["miniprogram"] = map[string]interface{}{"appid": WxMobileCrmAppId, "pagepath": wxAppPath}
|
|
|
}
|
|
|
- err = SendMultiTemplateMsg(sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION)
|
|
|
+ err = SendMultiTemplateMsg(AdminWxAppId, AdminWxAppSecret, sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION)
|
|
|
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
|
|
@@ -402,25 +389,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{})
|
|
@@ -436,7 +409,7 @@ func SendQuestionCommentToAdmin(commentId, userId int, commentContent string) (e
|
|
|
sendData["keyword2"] = map[string]interface{}{"value": keyword2, "color": "#173177"}
|
|
|
sendData["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
|
|
|
|
|
|
- sendMap["template_id"] = TemplateIdWithCommunityQuestion
|
|
|
+ sendMap["template_id"] = TemplateIdWithCommunityQuestionNotifyAdmin
|
|
|
sendMap["data"] = sendData
|
|
|
|
|
|
wxAppPath := fmt.Sprintf("/pages-question/detail/index?type=comment&id=%d", commentId)
|
|
@@ -447,6 +420,6 @@ func SendQuestionCommentToAdmin(commentId, userId int, commentContent string) (e
|
|
|
if wxAppPath != "" {
|
|
|
sendMap["miniprogram"] = map[string]interface{}{"appid": WxMobileCrmAppId, "pagepath": wxAppPath}
|
|
|
}
|
|
|
- err = SendMultiTemplateMsg(sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION)
|
|
|
+ err = SendMultiTemplateMsg(AdminWxAppId, AdminWxAppSecret, sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION)
|
|
|
return
|
|
|
}
|