|
@@ -3,11 +3,14 @@ package services
|
|
|
import (
|
|
|
"bytes"
|
|
|
"encoding/json"
|
|
|
+ "errors"
|
|
|
"fmt"
|
|
|
"hongze/hongze_task/models"
|
|
|
+ "hongze/hongze_task/services/alarm_msg"
|
|
|
"hongze/hongze_task/utils"
|
|
|
"io/ioutil"
|
|
|
"net/http"
|
|
|
+ "strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -160,3 +163,98 @@ func SendWxMsgWithActivityAppointmentRemind(first, keyword1, keyword2, keyword3,
|
|
|
WxSendTemplateMsg(sendUrl, sendMap, openIdList)
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+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 SendTemplateMsgV2(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", utils.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(models.BaseResponse)
|
|
|
+ err = json.Unmarshal(b, &result)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if result.Ret != 200 {
|
|
|
+ err = errors.New(string(b))
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// SendYbVoiceBroadcastWxMsg 推送研报语音播报模板消息
|
|
|
+func SendYbVoiceBroadcastWxMsg(broadcastId int, sectionName, broadcastName string) (err error) {
|
|
|
+ var msg string
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ errMsg := "SendYbVoiceBroadcastWxMsg-定时任务发送语音播报模版消息失败; Err: " + err.Error() + "; Msg: " + msg
|
|
|
+ utils.FileLog.Info("%s", errMsg)
|
|
|
+ go alarm_msg.SendAlarmMsg(errMsg, 3)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ openIdList, err := models.GetOpenIdListV2()
|
|
|
+ if err != nil {
|
|
|
+ msg = "get openIdList err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ openIdArr := make([]string, 0)
|
|
|
+ for _, v := range openIdList {
|
|
|
+ openIdArr = append(openIdArr, v.OpenId)
|
|
|
+ }
|
|
|
+
|
|
|
+ first := "您好,有新的语音播报待查看"
|
|
|
+ keyword1 := fmt.Sprint(sectionName, ":", broadcastName)
|
|
|
+ keyword2 := "待查看"
|
|
|
+ remark := "请点击详情查看"
|
|
|
+ wxAppPath := fmt.Sprintf("pages-voice/voiceDetail?voiceId=%d", broadcastId)
|
|
|
+ sendInfo := new(SendWxTemplate)
|
|
|
+ sendInfo.First = first
|
|
|
+ sendInfo.Keyword1 = keyword1
|
|
|
+ sendInfo.Keyword2 = keyword2
|
|
|
+ sendInfo.RedirectUrl = wxAppPath
|
|
|
+ sendInfo.TemplateId = utils.YbCommonTemplateId
|
|
|
+ sendInfo.RedirectTarget = 1
|
|
|
+ sendInfo.Resource = wxAppPath
|
|
|
+ sendInfo.SendType = utils.TEMPLATE_MSG_YB_VOICE_BROADCAST
|
|
|
+ sendInfo.OpenIdArr = openIdArr
|
|
|
+ sendInfo.Remark = remark
|
|
|
+ err = SendTemplateMsgV2(sendInfo)
|
|
|
+ return
|
|
|
+}
|