|
@@ -46,7 +46,7 @@ func SendWxMsgWithFrequency(first, activityName, reserveResults, activityTime, a
|
|
|
sendData["activity_address"] = map[string]interface{}{"value": activityAddress, "color": "#173177"}
|
|
|
sendData["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
|
|
|
sendMap["data"] = sendData
|
|
|
- WxSendTemplateMsg(sendUrl, sendMap, openIdList)
|
|
|
+ WxSendTemplateMsg(sendUrl, sendMap, openIdList, strconv.Itoa(activityId), utils.TEMPLATE_MSG_CYGX_ACTIVITY_ADD)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -96,46 +96,7 @@ func SendWxMsgWithAsk(name, askTime, askMsg, title string, openIdList []*models.
|
|
|
sendData["keyword4"] = map[string]interface{}{"value": keyword4, "color": "#173177"}
|
|
|
sendData["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
|
|
|
sendMap["data"] = sendData
|
|
|
- WxSendTemplateMsg(sendUrl, sendMap, openIdList)
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-func WxSendTemplateMsg(sendUrl string, sendMap map[string]interface{}, items []*models.OpenIdList) (err error) {
|
|
|
- for _, v := range items {
|
|
|
- sendMap["touser"] = v.OpenId
|
|
|
- data, err := json.Marshal(sendMap)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("SendTemplateMsgOne Marshal Err:", err.Error())
|
|
|
- return err
|
|
|
- }
|
|
|
- utils.FileLog.Info("One SendData:%s", string(data))
|
|
|
- fmt.Println(string(data))
|
|
|
- err = SendTemplateMsg(sendUrl, data)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("send err:", err.Error())
|
|
|
- return err
|
|
|
- }
|
|
|
- }
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-func SendTemplateMsg(sendUrl string, data []byte) (err error) {
|
|
|
- client := http.Client{}
|
|
|
- resp, err := client.Post(sendUrl, "application/json", bytes.NewBuffer(data))
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- defer resp.Body.Close()
|
|
|
-
|
|
|
- body, _ := ioutil.ReadAll(resp.Body)
|
|
|
- utils.FileLog.Info("SendResult:%s", string(body))
|
|
|
- var templateResponse models.SendTemplateResponse
|
|
|
- err = json.Unmarshal(body, &templateResponse)
|
|
|
- fmt.Println(templateResponse.Errcode)
|
|
|
- fmt.Println(templateResponse.Errmsg)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
+ WxSendTemplateMsg(sendUrl, sendMap, openIdList, strconv.Itoa(articleId), utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -172,7 +133,8 @@ func SendWxMsgWithCompanyRemind(first, keyword1, keyword2, remark string, openId
|
|
|
sendData["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
|
|
|
sendMap["data"] = sendData
|
|
|
fmt.Println(accessToken)
|
|
|
- WxSendTemplateMsg(sendUrl, sendMap, openIdList)
|
|
|
+ fmt.Println(sendUrl)
|
|
|
+ //WxSendTemplateMsg(sendUrl, sendMap, openIdList)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -214,7 +176,7 @@ func SendWxMsgWithArticleClassToAdmin(keyWord1, keyWord2, keyWord3, keyWord4 str
|
|
|
sendData["keyword3"] = map[string]interface{}{"value": keyword3, "color": "#173177"}
|
|
|
sendData["keyword4"] = map[string]interface{}{"value": keyword4, "color": "#173177"}
|
|
|
sendMap["data"] = sendData
|
|
|
- WxSendTemplateMsg(sendUrl, sendMap, openIdList)
|
|
|
+ WxSendTemplateMsg(sendUrl, sendMap, openIdList, strconv.Itoa(articleId), utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -226,3 +188,65 @@ func SendWxMsgWithArticleClassToAdmin(keyWord1, keyWord2, keyWord3, keyWord4 str
|
|
|
//弘则研究:
|
|
|
//MwZ5wxfd0O1Yt0Pkf6OkfWP4USQzZbiEo5SkZ26735s 活动预约通知
|
|
|
//dYg6iHooRq74PyCXmw_Ns7qdJZmbtLoKS2p2FKeaXl0 项目状态变更通知
|
|
|
+
|
|
|
+func WxSendTemplateMsg(sendUrl string, sendMap map[string]interface{}, items []*models.OpenIdList, resource string, sendType int) (err error) {
|
|
|
+ for _, v := range items {
|
|
|
+ sendMap["touser"] = v.OpenId
|
|
|
+ data, err := json.Marshal(sendMap)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("SendTemplateMsgOne Marshal Err:", err.Error())
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ utils.FileLog.Info("One SendData:%s", string(data))
|
|
|
+ fmt.Println(string(data))
|
|
|
+ err = SendTemplateMsg(sendUrl, data, resource, sendType, v)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("send err:", err.Error())
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func SendTemplateMsg(sendUrl string, data []byte, resource string, sendType int, dataItem *models.OpenIdList) (err error) {
|
|
|
+ client := http.Client{}
|
|
|
+ resp, err := client.Post(sendUrl, "application/json", bytes.NewBuffer(data))
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer resp.Body.Close()
|
|
|
+
|
|
|
+ body, _ := ioutil.ReadAll(resp.Body)
|
|
|
+ utils.FileLog.Info("SendResult:%s", string(body))
|
|
|
+ var templateResponse models.SendTemplateResponse
|
|
|
+ err = json.Unmarshal(body, &templateResponse)
|
|
|
+ fmt.Println(templateResponse.Errcode)
|
|
|
+ fmt.Println(templateResponse.Errmsg)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ //新增模板消息推送记录
|
|
|
+ {
|
|
|
+ tr := new(models.UserTemplateRecord)
|
|
|
+ tr.UserId = dataItem.UserId
|
|
|
+ tr.OpenId = dataItem.OpenId
|
|
|
+ tr.Resource = resource
|
|
|
+ tr.SendData = string(data)
|
|
|
+ tr.Result = string(body)
|
|
|
+ tr.CreateDate = time.Now().Format(utils.FormatDate)
|
|
|
+ tr.CreateTime = time.Now().Format(utils.FormatDateTime)
|
|
|
+ if templateResponse.Errcode == 0 {
|
|
|
+ tr.SendStatus = 1
|
|
|
+ } else {
|
|
|
+ tr.SendStatus = 0
|
|
|
+ }
|
|
|
+ tr.SendType = sendType
|
|
|
+ go func() {
|
|
|
+ err = models.AddUserTemplateRecord(tr)
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Info(fmt.Sprintf("AddUserTemplateRecord Err:%s", err.Error()))
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|