|
@@ -4,89 +4,15 @@ import (
|
|
|
"bytes"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
- "hongze/hongze_mobile_admin/models/tables/report"
|
|
|
"hongze/hongze_mobile_admin/models/tables/user_template_record"
|
|
|
"hongze/hongze_mobile_admin/models/tables/wx_user"
|
|
|
"hongze/hongze_mobile_admin/services/alarm_msg"
|
|
|
"hongze/hongze_mobile_admin/utils"
|
|
|
"io/ioutil"
|
|
|
"net/http"
|
|
|
- "strconv"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
-func SendWxTemplateMsg(reportId int) (err error) {
|
|
|
- var msg string
|
|
|
- defer func() {
|
|
|
- if err != nil {
|
|
|
- go alarm_msg.SendAlarmMsg(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg), 3)
|
|
|
- //go utils.SendEmail("发送模版消息失败"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
|
|
|
- utils.FileLog.Info("发送模版消息失败,Err:%s,%s", err.Error(), msg)
|
|
|
- }
|
|
|
- if msg != "" {
|
|
|
- utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
|
|
|
- }
|
|
|
- }()
|
|
|
- utils.FileLog.Info("%s", "services SendMsg")
|
|
|
-
|
|
|
- report, err := report.GetReportById(reportId)
|
|
|
- if err != nil {
|
|
|
- msg = "GetReportInfo Err:" + err.Error()
|
|
|
- return
|
|
|
- }
|
|
|
- if report == nil {
|
|
|
- utils.FileLog.Info("报告信息不存在")
|
|
|
- return
|
|
|
- }
|
|
|
- accessToken, err := WxGetAccessToken()
|
|
|
- if err != nil {
|
|
|
- msg = "GetWxAccessToken Err:" + err.Error()
|
|
|
- return
|
|
|
- }
|
|
|
- if accessToken == "" {
|
|
|
- msg = "accessToken is empty"
|
|
|
- return
|
|
|
- }
|
|
|
- //获取openid列表
|
|
|
- openIdStr := WxUsersGet()
|
|
|
- openIdList, err := wx_user.GetOpenIdList(openIdStr)
|
|
|
- if err != nil {
|
|
|
- msg = "get openIdList err:" + err.Error()
|
|
|
- return
|
|
|
- }
|
|
|
- fmt.Println("openIdListCount:", len(openIdList))
|
|
|
- sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
|
|
|
- fmt.Println("send start")
|
|
|
- utils.FileLog.Info("send start")
|
|
|
- //if report.MsgIsSend == 0 {
|
|
|
- sendMap := make(map[string]interface{})
|
|
|
- sendData := make(map[string]interface{})
|
|
|
-
|
|
|
- redirectUrl := utils.TemplateRedirectUrl + strconv.Itoa(reportId)
|
|
|
- keyword1 := "弘则日度点评"
|
|
|
- first := "Hi,最新一期日度点评已上线,欢迎查看"
|
|
|
- keyword2 := report.Title
|
|
|
- //keyword3 := report.PublishTime.Format(utils.FormatDateTime)
|
|
|
- keyword3 := report.PublishTime
|
|
|
- keyword4 := report.Abstract
|
|
|
-
|
|
|
- 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["keyword3"] = map[string]interface{}{"value": keyword3, "color": "#173177"}
|
|
|
- sendData["keyword4"] = map[string]interface{}{"value": keyword4, "color": "#173177"}
|
|
|
-
|
|
|
- sendMap["template_id"] = utils.TemplateIdByProduct
|
|
|
- sendMap["url"] = redirectUrl
|
|
|
- sendMap["data"] = sendData
|
|
|
- sendTemplateMsg(sendUrl, sendMap, openIdList, strconv.Itoa(reportId), utils.TEMPLATE_MSG_REPORT)
|
|
|
-
|
|
|
- //}
|
|
|
- fmt.Println("send end")
|
|
|
- utils.FileLog.Info("send end")
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
func sendTemplateMsg(sendUrl string, sendMap map[string]interface{}, items []*wx_user.OpenIdList, resource string, sendType int) (err error) {
|
|
|
for _, v := range items {
|
|
|
sendMap["touser"] = v.OpenId
|
|
@@ -175,7 +101,7 @@ func SendCompanyApplyWxTemplateMsg(mobile, redirectUrl, wxAppPath string, wxMsgM
|
|
|
}()
|
|
|
utils.FileLog.Info("%s", "services SendMsg")
|
|
|
|
|
|
- accessToken, err := WxGetAccessToken()
|
|
|
+ accessToken, err := WxGetAccessToken(utils.AdminWxAppId, utils.AdminWxAppSecret)
|
|
|
if err != nil {
|
|
|
msg = "GetWxAccessToken Err:" + err.Error()
|
|
|
return
|
|
@@ -241,7 +167,7 @@ func SendCompanyApplyWxTemplateMsg(mobile, redirectUrl, wxAppPath string, wxMsgM
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// 路演->销售收到处理结果
|
|
|
+// SendWxMsgWithRoadshowDetailResult 路演->销售收到处理结果
|
|
|
func SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, remark, mobile, redirectUrl, wxAppPath string) (err error) {
|
|
|
var msg string
|
|
|
defer func() {
|
|
@@ -256,7 +182,7 @@ func SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, remark, mobile
|
|
|
}()
|
|
|
utils.FileLog.Info("%s", "services SendMsg")
|
|
|
|
|
|
- accessToken, err := WxGetAccessToken()
|
|
|
+ accessToken, err := WxGetAccessToken(utils.AdminWxAppId, utils.AdminWxAppSecret)
|
|
|
if err != nil {
|
|
|
msg = "GetWxAccessToken Err:" + err.Error()
|
|
|
return
|
|
@@ -302,7 +228,7 @@ func SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, remark, mobile
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// 路演->研究员收到待处理的申请
|
|
|
+// SendWxMsgWithRoadshowPending 路演->研究员收到待处理的申请
|
|
|
func SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, mobile string) (err error) {
|
|
|
//utils.WxMsgTemplateIdWithRoadshowPending
|
|
|
var msg string
|
|
@@ -318,7 +244,7 @@ func SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4,
|
|
|
}()
|
|
|
utils.FileLog.Info("%s", "services SendMsg")
|
|
|
|
|
|
- accessToken, err := WxGetAccessToken()
|
|
|
+ accessToken, err := WxGetAccessToken(utils.AdminWxAppId, utils.AdminWxAppSecret)
|
|
|
if err != nil {
|
|
|
msg = "GetWxAccessToken Err:" + err.Error()
|
|
|
return
|
|
@@ -364,7 +290,7 @@ func SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4,
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// 路演->研究员收到活动删除通知
|
|
|
+// SendWxMsgWithRoadshowDeleteNotice 路演->研究员收到活动删除通知
|
|
|
func SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, remark, wxAppPath, mobile string) (err error) {
|
|
|
var msg string
|
|
|
defer func() {
|
|
@@ -379,7 +305,7 @@ func SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, remark, wxAppP
|
|
|
}()
|
|
|
utils.FileLog.Info("%s", "services SendMsg")
|
|
|
|
|
|
- accessToken, err := WxGetAccessToken()
|
|
|
+ accessToken, err := WxGetAccessToken(utils.AdminWxAppId, utils.AdminWxAppSecret)
|
|
|
if err != nil {
|
|
|
msg = "GetWxAccessToken Err:" + err.Error()
|
|
|
return
|
|
@@ -420,7 +346,7 @@ func SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, remark, wxAppP
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// 给销售发送 用印申请已签回的模版消息
|
|
|
+// SendSealFinishedWxTemplateMsg 给销售发送 用印申请已签回的模版消息
|
|
|
func SendSealFinishedWxTemplateMsg(mobile string, companyName string, sealId int) (err error) {
|
|
|
var msg string
|
|
|
defer func() {
|
|
@@ -434,7 +360,7 @@ func SendSealFinishedWxTemplateMsg(mobile string, companyName string, sealId int
|
|
|
}
|
|
|
}()
|
|
|
utils.FileLog.Info("%s", "services SendMsg")
|
|
|
- accessToken, err := WxGetAccessToken()
|
|
|
+ accessToken, err := WxGetAccessToken(utils.AdminWxAppId, utils.AdminWxAppSecret)
|
|
|
if err != nil {
|
|
|
msg = "GetWxAccessToken Err:" + err.Error()
|
|
|
return
|
|
@@ -493,7 +419,7 @@ func SendYbQuestionDistributeWxMsg(questionId, userId int, openid, questionTitle
|
|
|
}
|
|
|
}()
|
|
|
|
|
|
- accessToken, err := WxGetAccessToken()
|
|
|
+ accessToken, err := WxGetAccessToken(utils.AdminWxAppId, utils.AdminWxAppSecret)
|
|
|
if err != nil {
|
|
|
errMsg = "GetWxAccessToken Err:" + err.Error()
|
|
|
return
|