|
@@ -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字段"`
|
|
@@ -175,7 +176,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,
|
|
@@ -186,14 +187,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
|
|
@@ -221,7 +223,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 {
|
|
@@ -297,6 +299,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 +312,6 @@ func SendQuestionReplyWxMsg(questionId, userId int, questionTitle string) (err e
|
|
|
sendInfo.OpenIdArr = openIdArr
|
|
|
|
|
|
err = SendTemplateMsg(sendInfo)
|
|
|
-
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -368,8 +370,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,13 +384,12 @@ func SendVoiceBroadcastWxMsg(broadcastId int, sectionName, broadcastName string)
|
|
|
sendInfo.OpenIdArr = openIdArr
|
|
|
|
|
|
err = SendTemplateMsg(sendInfo)
|
|
|
-
|
|
|
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
|
|
@@ -416,7 +417,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 {
|
|
@@ -427,8 +428,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 +439,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 +458,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 +475,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 +504,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 +523,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 +540,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
|