|
@@ -6,14 +6,17 @@ import (
|
|
|
"encoding/json"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
+ "hongze/hongze_yb/controller/response"
|
|
|
"hongze/hongze_yb/global"
|
|
|
"hongze/hongze_yb/models/tables/user_record"
|
|
|
"hongze/hongze_yb/models/tables/user_template_record"
|
|
|
"hongze/hongze_yb/models/tables/wx_user"
|
|
|
"hongze/hongze_yb/services/alarm_msg"
|
|
|
+ "hongze/hongze_yb/services/wx_app"
|
|
|
"hongze/hongze_yb/utils"
|
|
|
"io/ioutil"
|
|
|
"net/http"
|
|
|
+ "strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -43,6 +46,60 @@ type OpenIdList struct {
|
|
|
UserId int
|
|
|
}
|
|
|
|
|
|
+type SendWxTemplate struct {
|
|
|
+ First string `description:"模板消息first字段"`
|
|
|
+ Keyword1 string `description:"模板消息keyword1字段"`
|
|
|
+ Keyword2 string `description:"模板消息keyword2字段"`
|
|
|
+ Keyword3 string `description:"模板消息keyword3字段"`
|
|
|
+ Keyword4 string `description:"模板消息keyword4字段"`
|
|
|
+ Remark string `description:"模板消息remark字段"`
|
|
|
+ TemplateId string `description:"模板id"`
|
|
|
+ RedirectUrl string `description:"跳转地址"`
|
|
|
+ RedirectTarget int `description:"小程序跳转目标:1:弘则研报小程序,2:随手办公小程序"`
|
|
|
+ Resource string `description:"资源唯一标识"`
|
|
|
+ SendType int `description:"发送的消息类型:1:报告,2:指标更新提醒,3:审批通知,4:销售领取客户通知,5:活动取消通知,6活动更改时间通知,7:关注的作者发布报告通知,8:发送日报(周报、双周报、月报)模板消息,9:活动预约/报名时间通知"`
|
|
|
+ OpenIdArr []string `description:"消息接收者openid"`
|
|
|
+}
|
|
|
+
|
|
|
+//推送模板消息
|
|
|
+func SendTemplateMsg(sendInfo *SendWxTemplate) (err error) {
|
|
|
+ postData, err := json.Marshal(sendInfo)
|
|
|
+ if err != nil {
|
|
|
+ alarm_msg.SendAlarmMsg("SendTemplateMsg json.Marshal Err:"+err.Error(), 1)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ body := ioutil.NopCloser(strings.NewReader(string(postData)))
|
|
|
+ client := &http.Client{}
|
|
|
+ req, err := http.NewRequest("POST", wx_app.SendWxTemplateMsgUrl, body)
|
|
|
+ if err != nil {
|
|
|
+ alarm_msg.SendAlarmMsg("SendTemplateMsg http.NewRequest Err:"+err.Error(), 1)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ contentType := "application/json;charset=utf-8"
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
+ req.Header.Set("Authorization", utils.SendTemplateMsgAuthorization)
|
|
|
+ resp, err := client.Do(req)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("http client.Do Err:" + err.Error())
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ defer resp.Body.Close()
|
|
|
+ b, err := ioutil.ReadAll(resp.Body)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ result := new(response.BaseResponse)
|
|
|
+ err = json.Unmarshal(b, &result)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if result.Ret != 200 {
|
|
|
+ err = errors.New(string(b))
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// TemplateMsgSendClient.SendMsg 推送消息
|
|
|
func (c *TemplateMsgSendClient) SendMsg() (sendRes *SendTemplateResponse, err error) {
|
|
|
// 请求接口
|
|
@@ -208,31 +265,51 @@ func SendQuestionReplyWxMsg(questionId, userId int, questionTitle string) (err e
|
|
|
UserId: userId,
|
|
|
})
|
|
|
|
|
|
- sendMap := make(map[string]interface{})
|
|
|
- sendData := make(map[string]interface{})
|
|
|
+ //sendMap := make(map[string]interface{})
|
|
|
+ //sendData := make(map[string]interface{})
|
|
|
|
|
|
first := "您好,您的提问已被回复"
|
|
|
keyword1 := questionTitle
|
|
|
keyword2 := "待查看"
|
|
|
remark := "请点击详情查看回复"
|
|
|
|
|
|
- sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
|
|
|
- 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
|
|
|
-
|
|
|
+ //sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
|
|
|
+ //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
|
|
|
+ //
|
|
|
wxAppPath := fmt.Sprintf("pages-question/answerDetail?id=%d", questionId)
|
|
|
if global.CONFIG.Serve.RunMode == "debug" {
|
|
|
// 仅测试环境测试用
|
|
|
wxAppPath = "pages-report/reportDetail?reportId=3800"
|
|
|
}
|
|
|
- if wxAppPath != "" {
|
|
|
- sendMap["miniprogram"] = map[string]interface{}{"appid": WxYbAppId, "pagepath": wxAppPath}
|
|
|
+ //if wxAppPath != "" {
|
|
|
+ // sendMap["miniprogram"] = map[string]interface{}{"appid": WxYbAppId, "pagepath": wxAppPath}
|
|
|
+ //}
|
|
|
+ //err = SendMultiTemplateMsg(sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION)
|
|
|
+
|
|
|
+ openIdArr := make([]string, len(openIdList))
|
|
|
+ for i, v := range openIdList {
|
|
|
+ openIdArr[i] = v.OpenId
|
|
|
}
|
|
|
- err = SendMultiTemplateMsg(sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION)
|
|
|
+
|
|
|
+ sendInfo := new(SendWxTemplate)
|
|
|
+ sendInfo.First = first
|
|
|
+ sendInfo.Keyword1 = keyword1
|
|
|
+ sendInfo.Keyword2 = keyword2
|
|
|
+ sendInfo.Remark = remark
|
|
|
+ sendInfo.RedirectUrl = wxAppPath
|
|
|
+ sendInfo.TemplateId = TemplateIdWithCommunityQuestion
|
|
|
+ sendInfo.RedirectTarget = 1
|
|
|
+ sendInfo.Resource = wxAppPath
|
|
|
+ sendInfo.SendType = utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION
|
|
|
+ sendInfo.OpenIdArr = openIdArr
|
|
|
+
|
|
|
+ err = SendTemplateMsg(sendInfo)
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -261,31 +338,51 @@ func SendVoiceBroadcastWxMsg(broadcastId int, sectionName, broadcastName string)
|
|
|
// OpenId: "oN0jD1cuiBLxV1IRpu74_oHnoOjk",
|
|
|
// UserId: 52709,
|
|
|
// })
|
|
|
- sendMap := make(map[string]interface{})
|
|
|
- sendData := make(map[string]interface{})
|
|
|
+ //sendMap := make(map[string]interface{})
|
|
|
+ //sendData := make(map[string]interface{})
|
|
|
|
|
|
first := "您好,有新的语音播报待查看"
|
|
|
keyword1 := sectionName + ":" + broadcastName
|
|
|
keyword2 := "待查看"
|
|
|
remark := "请点击详情查看"
|
|
|
|
|
|
- sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
|
|
|
- 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"}
|
|
|
+ //sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
|
|
|
+ //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
|
|
|
+ //sendMap["template_id"] = TemplateIdWithCommunityQuestion
|
|
|
+ //sendMap["data"] = sendData
|
|
|
|
|
|
wxAppPath := fmt.Sprintf("pages-voice/voiceDetail?voiceId=%d", broadcastId)
|
|
|
if global.CONFIG.Serve.RunMode == "debug" {
|
|
|
// 仅测试环境测试用
|
|
|
wxAppPath = "pages-report/reportDetail?reportId=3800"
|
|
|
}
|
|
|
- if wxAppPath != "" {
|
|
|
- sendMap["miniprogram"] = map[string]interface{}{"appid": WxYbAppId, "pagepath": wxAppPath}
|
|
|
+ //if wxAppPath != "" {
|
|
|
+ // sendMap["miniprogram"] = map[string]interface{}{"appid": WxYbAppId, "pagepath": wxAppPath}
|
|
|
+ //}
|
|
|
+ //err = SendMultiTemplateMsgNoReturn(sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_VOICE_BROADCAST)
|
|
|
+
|
|
|
+ openIdArr := make([]string, len(openIdList))
|
|
|
+ for i, v := range openIdList {
|
|
|
+ openIdArr[i] = v.OpenId
|
|
|
}
|
|
|
- err = SendMultiTemplateMsgNoReturn(sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_VOICE_BROADCAST)
|
|
|
+
|
|
|
+ sendInfo := new(SendWxTemplate)
|
|
|
+ sendInfo.First = first
|
|
|
+ sendInfo.Keyword1 = keyword1
|
|
|
+ sendInfo.Keyword2 = keyword2
|
|
|
+ sendInfo.Remark = remark
|
|
|
+ sendInfo.RedirectUrl = wxAppPath
|
|
|
+ sendInfo.TemplateId = TemplateIdWithCommunityQuestion
|
|
|
+ sendInfo.RedirectTarget = 1
|
|
|
+ sendInfo.Resource = wxAppPath
|
|
|
+ sendInfo.SendType = utils.TEMPLATE_MSG_YB_VOICE_BROADCAST
|
|
|
+ sendInfo.OpenIdArr = openIdArr
|
|
|
+
|
|
|
+ err = SendTemplateMsg(sendInfo)
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -362,31 +459,51 @@ func SendQuestionToAdmin(questionId, userId int, questionTitle string) (err erro
|
|
|
UserId: userId,
|
|
|
})
|
|
|
|
|
|
- sendMap := make(map[string]interface{})
|
|
|
- sendData := make(map[string]interface{})
|
|
|
+ //sendMap := make(map[string]interface{})
|
|
|
+ //sendData := make(map[string]interface{})
|
|
|
|
|
|
first := "您好,有新的提问待分配"
|
|
|
keyword1 := questionTitle
|
|
|
keyword2 := "待查看"
|
|
|
remark := "请点击详情查看回复"
|
|
|
|
|
|
- sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
|
|
|
- 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"}
|
|
|
+ //sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
|
|
|
+ //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
|
|
|
+ //sendMap["template_id"] = TemplateIdWithCommunityQuestion
|
|
|
+ //sendMap["data"] = sendData
|
|
|
|
|
|
wxAppPath := fmt.Sprintf("/pages-question/detail/index?type=question&id=%d", questionId)
|
|
|
if global.CONFIG.Serve.RunMode == "debug" {
|
|
|
// 仅测试环境测试用
|
|
|
wxAppPath = "pages-approve/seal/list"
|
|
|
}
|
|
|
- if wxAppPath != "" {
|
|
|
- sendMap["miniprogram"] = map[string]interface{}{"appid": WxMobileCrmAppId, "pagepath": wxAppPath}
|
|
|
+ //if wxAppPath != "" {
|
|
|
+ // sendMap["miniprogram"] = map[string]interface{}{"appid": WxMobileCrmAppId, "pagepath": wxAppPath}
|
|
|
+ //}
|
|
|
+ //err = SendMultiTemplateMsg(sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION)
|
|
|
+
|
|
|
+ openIdArr := make([]string, len(openIdList))
|
|
|
+ for i, v := range openIdList {
|
|
|
+ openIdArr[i] = v.OpenId
|
|
|
}
|
|
|
- err = SendMultiTemplateMsg(sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION)
|
|
|
+
|
|
|
+ sendInfo := new(SendWxTemplate)
|
|
|
+ sendInfo.First = first
|
|
|
+ sendInfo.Keyword1 = keyword1
|
|
|
+ sendInfo.Keyword2 = keyword2
|
|
|
+ sendInfo.Remark = remark
|
|
|
+ sendInfo.RedirectUrl = wxAppPath
|
|
|
+ sendInfo.TemplateId = TemplateIdWithCommunityQuestion
|
|
|
+ sendInfo.RedirectTarget = 2
|
|
|
+ sendInfo.Resource = wxAppPath
|
|
|
+ sendInfo.SendType = utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION
|
|
|
+ sendInfo.OpenIdArr = openIdArr
|
|
|
+
|
|
|
+ err = SendTemplateMsg(sendInfo)
|
|
|
+
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -423,30 +540,49 @@ func SendQuestionCommentToAdmin(commentId, userId int, commentContent string) (e
|
|
|
UserId: userId,
|
|
|
})
|
|
|
|
|
|
- sendMap := make(map[string]interface{})
|
|
|
- sendData := make(map[string]interface{})
|
|
|
+ //sendMap := make(map[string]interface{})
|
|
|
+ //sendData := make(map[string]interface{})
|
|
|
|
|
|
first := "您好,有新的评论待查看"
|
|
|
keyword1 := commentContent
|
|
|
keyword2 := "待查看"
|
|
|
remark := "请点击详情查看回复"
|
|
|
|
|
|
- sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
|
|
|
- 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"}
|
|
|
+ //sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
|
|
|
+ //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
|
|
|
+ //sendMap["template_id"] = TemplateIdWithCommunityQuestion
|
|
|
+ //sendMap["data"] = sendData
|
|
|
|
|
|
wxAppPath := fmt.Sprintf("/pages-question/detail/index?type=comment&id=%d", commentId)
|
|
|
if global.CONFIG.Serve.RunMode == "debug" {
|
|
|
// 仅测试环境测试用
|
|
|
wxAppPath = "pages-approve/seal/list"
|
|
|
}
|
|
|
- if wxAppPath != "" {
|
|
|
- sendMap["miniprogram"] = map[string]interface{}{"appid": WxMobileCrmAppId, "pagepath": wxAppPath}
|
|
|
+ //if wxAppPath != "" {
|
|
|
+ // sendMap["miniprogram"] = map[string]interface{}{"appid": WxMobileCrmAppId, "pagepath": wxAppPath}
|
|
|
+ //}
|
|
|
+ //err = SendMultiTemplateMsg(sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION)
|
|
|
+
|
|
|
+ openIdArr := make([]string, len(openIdList))
|
|
|
+ for i, v := range openIdList {
|
|
|
+ openIdArr[i] = v.OpenId
|
|
|
}
|
|
|
- err = SendMultiTemplateMsg(sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION)
|
|
|
+
|
|
|
+ sendInfo := new(SendWxTemplate)
|
|
|
+ sendInfo.First = first
|
|
|
+ sendInfo.Keyword1 = keyword1
|
|
|
+ sendInfo.Keyword2 = keyword2
|
|
|
+ sendInfo.Remark = remark
|
|
|
+ sendInfo.RedirectUrl = wxAppPath
|
|
|
+ sendInfo.TemplateId = TemplateIdWithCommunityQuestion
|
|
|
+ sendInfo.RedirectTarget = 2
|
|
|
+ sendInfo.Resource = wxAppPath
|
|
|
+ sendInfo.SendType = utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION
|
|
|
+ sendInfo.OpenIdArr = openIdArr
|
|
|
+
|
|
|
+ err = SendTemplateMsg(sendInfo)
|
|
|
return
|
|
|
}
|