wechat_send_msg.go 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942
  1. package services
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "errors"
  6. "fmt"
  7. "hongze/hz_crm_api/models"
  8. "hongze/hz_crm_api/models/cygx"
  9. "hongze/hz_crm_api/models/system"
  10. "hongze/hz_crm_api/services/alarm_msg"
  11. "hongze/hz_crm_api/utils"
  12. "io/ioutil"
  13. "net/http"
  14. "strconv"
  15. "strings"
  16. "time"
  17. )
  18. func SendWxTemplateMsg(reportId int) (err error) {
  19. var msg string
  20. defer func() {
  21. if err != nil {
  22. go alarm_msg.SendAlarmMsg("发送模版消息失败,Err:"+err.Error()+";msg:"+msg, 3)
  23. //go utils.SendEmail("发送模版消息失败"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  24. utils.FileLog.Info(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg))
  25. }
  26. if msg != "" {
  27. utils.FileLog.Info(fmt.Sprintf("发送模版消息失败,msg:%s", msg))
  28. }
  29. }()
  30. utils.FileLog.Info("%s", "services SendMsg")
  31. report, err := models.GetReportById(reportId)
  32. if err != nil {
  33. msg = "GetReportInfo Err:" + err.Error()
  34. return
  35. }
  36. if report == nil {
  37. utils.FileLog.Info("报告信息不存在")
  38. return
  39. }
  40. //accessToken, err := models.GetWxAccessToken()
  41. //if err != nil {
  42. // msg = "GetWxAccessToken Err:" + err.Error()
  43. // return
  44. //}
  45. //if accessToken == "" {
  46. // msg = "accessToken is empty"
  47. // return
  48. //}
  49. openIdArr, err := models.GetOpenIdArr()
  50. if err != nil {
  51. msg = "get GetOpenIdArr err:" + err.Error()
  52. return
  53. }
  54. //sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
  55. //fmt.Println("send start")
  56. //utils.FileLog.Info("send start")
  57. ////if report.MsgIsSend == 0 {
  58. //sendMap := make(map[string]interface{})
  59. //sendData := make(map[string]interface{})
  60. redirectUrl := utils.TemplateRedirectUrl + strconv.Itoa(reportId)
  61. keyword1 := "弘则日度点评"
  62. first := "Hi,最新一期日度点评已上线,欢迎查看"
  63. if CheckTwoWeekOrMonthReport(report.ClassifyIdFirst, report.ClassifyNameFirst) {
  64. keyword1 = fmt.Sprintf("弘则%s", report.ClassifyNameSecond)
  65. first = fmt.Sprintf("Hi,最新一期%s已上线,欢迎查看", report.ClassifyNameFirst)
  66. }
  67. keyword2 := report.Title
  68. //keyword3 := report.PublishTime.Format(utils.FormatDateTime)
  69. keyword3 := report.PublishTime
  70. keyword4 := report.Abstract
  71. //sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
  72. //sendData["keyword1"] = map[string]interface{}{"value": keyword1, "color": "#173177"}
  73. //sendData["keyword2"] = map[string]interface{}{"value": keyword2, "color": "#173177"}
  74. //sendData["keyword3"] = map[string]interface{}{"value": keyword3, "color": "#173177"}
  75. //sendData["keyword4"] = map[string]interface{}{"value": keyword4, "color": "#173177"}
  76. //
  77. //sendMap["template_id"] = utils.TemplateIdByProduct
  78. //sendMap["url"] = redirectUrl
  79. //sendMap["data"] = sendData
  80. //sendTemplateMsg(sendUrl, sendMap, openIdList, strconv.Itoa(reportId), utils.TEMPLATE_MSG_REPORT)
  81. //}
  82. sendInfo := new(SendWxTemplate)
  83. sendInfo.First = first
  84. sendInfo.Keyword1 = keyword1
  85. sendInfo.Keyword2 = keyword2
  86. sendInfo.Keyword3 = keyword3
  87. sendInfo.Keyword4 = keyword4
  88. sendInfo.TemplateId = utils.TemplateIdByProduct
  89. sendInfo.RedirectUrl = redirectUrl
  90. sendInfo.RedirectTarget = 1
  91. sendInfo.Resource = strconv.Itoa(reportId)
  92. sendInfo.SendType = utils.TEMPLATE_MSG_REPORT
  93. sendInfo.OpenIdArr = openIdArr
  94. err = SendTemplateMsg(sendInfo)
  95. return
  96. }
  97. func sendTemplateMsg(sendUrl string, sendMap map[string]interface{}, items []*models.OpenIdList, resource string, sendType int) (err error) {
  98. for _, v := range items {
  99. sendMap["touser"] = v.OpenId
  100. data, err := json.Marshal(sendMap)
  101. if err != nil {
  102. fmt.Println("SendTemplateMsgOne Marshal Err:", err.Error())
  103. utils.FileLog.Info(fmt.Sprintf("SendTemplateMsgOne Marshal Err:%s", err.Error()))
  104. return err
  105. }
  106. err = toSendTemplateMsg(sendUrl, data, resource, sendType, v)
  107. if err != nil {
  108. fmt.Println("send err:", err.Error())
  109. utils.FileLog.Info(fmt.Sprintf("ToSendTemplateMsg Err:%s", err.Error()))
  110. }
  111. }
  112. return
  113. }
  114. func toSendTemplateMsg(sendUrl string, data []byte, resource string, sendType int, dataItem *models.OpenIdList) (err error) {
  115. var msg string
  116. utils.FileLog.Info("Send:" + string(data))
  117. client := http.Client{}
  118. resp, err := client.Post(sendUrl, "application/json", bytes.NewBuffer(data))
  119. if err != nil {
  120. return
  121. }
  122. defer resp.Body.Close()
  123. body, _ := ioutil.ReadAll(resp.Body)
  124. utils.FileLog.Info("SendResult:" + string(body))
  125. var templateResponse SendTemplateResponse
  126. err = json.Unmarshal(body, &templateResponse)
  127. if err != nil {
  128. utils.FileLog.Info(fmt.Sprintf("SendResult Unmarshal Err:%s", err.Error()))
  129. return err
  130. }
  131. //新增模板消息推送记录
  132. {
  133. tr := new(models.UserTemplateRecord)
  134. tr.UserId = dataItem.UserId
  135. tr.OpenId = dataItem.OpenId
  136. tr.Resource = resource
  137. tr.SendData = string(data)
  138. tr.Result = string(body)
  139. tr.CreateDate = time.Now().Format(utils.FormatDate)
  140. tr.CreateTime = time.Now().Format(utils.FormatDateTime)
  141. if templateResponse.Errcode == 0 {
  142. tr.SendStatus = 1
  143. } else {
  144. tr.SendStatus = 0
  145. }
  146. tr.SendType = sendType
  147. go func() {
  148. err = models.AddUserTemplateRecord(tr)
  149. if err != nil {
  150. utils.FileLog.Info(fmt.Sprintf("AddUserTemplateRecord Err:%s", err.Error()))
  151. }
  152. }()
  153. }
  154. accessToken, err := models.GetWxAccessToken()
  155. if err != nil {
  156. msg = "GetWxAccessToken Err:" + err.Error()
  157. utils.FileLog.Info("获取Token失败,msg:" + msg)
  158. return
  159. }
  160. if accessToken == "" {
  161. msg = "accessToken is empty"
  162. utils.FileLog.Info("accessToken为空,msg:" + msg)
  163. return
  164. }
  165. //模板消息发送超过当日10万次限制错误处理
  166. if templateResponse.Errcode == 45009 {
  167. key := "CACHE_SendTemplateMsg_ERR"
  168. isExist := utils.Rc.IsExist(key)
  169. if isExist == true {
  170. return
  171. } else {
  172. result, _ := json.Marshal(templateResponse)
  173. if err != nil {
  174. utils.FileLog.Info(fmt.Sprintf("templateResponse Marshal Err:%s", err.Error()))
  175. return err
  176. }
  177. //发送邮件提醒异常
  178. go alarm_msg.SendAlarmMsg("模板消息发送超过当日10万次限制,templateResponse = "+string(result), 3)
  179. //go utils.SendEmail("异常提醒:", "模板消息发送超过当日10万次限制,templateResponse = "+string(result), utils.EmailSendToUsers)
  180. //设置3分钟缓存,不允许重复添加
  181. utils.Rc.SetNX(key, 1, 6*time.Minute)
  182. }
  183. //清空发送次数
  184. sendUrl := fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/clear_quota?access_token=%s", accessToken)
  185. clearData := make(map[string]interface{})
  186. clearData["appid"] = utils.WxAppId
  187. clearJson, _ := json.Marshal(clearData)
  188. utils.FileLog.Info("clear_quota data:" + string(clearJson))
  189. resp, err := client.Post(sendUrl, "application/json", bytes.NewBuffer(clearJson))
  190. if err != nil {
  191. return err
  192. }
  193. defer resp.Body.Close()
  194. clearBody, err := ioutil.ReadAll(resp.Body)
  195. utils.FileLog.Info("clear_quota result:" + string(clearBody))
  196. var clearQuotaResponse ClearQuotaResponse
  197. err = json.Unmarshal(clearBody, &clearQuotaResponse)
  198. if err != nil {
  199. utils.FileLog.Info(fmt.Sprintf("clearQuotaResponse Unmarshal Err:%s", err.Error()))
  200. return err
  201. }
  202. if clearQuotaResponse.Errcode == 0 {
  203. //发送邮件解决异常
  204. go alarm_msg.SendAlarmMsg("异常已解决,自动清理限制接口,调用成功", 3)
  205. //go utils.SendEmail("异常已解决:", "自动清理限制接口,调用成功", utils.EmailSendToUsers)
  206. //重新推送一次
  207. toSendTemplateMsg(sendUrl, data, resource, sendType, dataItem)
  208. }
  209. }
  210. return
  211. }
  212. type SendTemplateResponse struct {
  213. Errcode int `json:"errcode"`
  214. Errmsg string `json:"errmsg"`
  215. MsgID int `json:"msgid"`
  216. }
  217. type ClearQuotaResponse struct {
  218. Errcode int `json:"errcode"`
  219. Errmsg string `json:"errmsg"`
  220. }
  221. // SendCompanyApplyWxTemplateMsg 微信审批通知模板消息
  222. func SendCompanyApplyWxTemplateMsg(mobile, redirectUrl, wxAppPath string, wxMsgMap map[int]string) (err error) {
  223. var msg string
  224. defer func() {
  225. if err != nil {
  226. go alarm_msg.SendAlarmMsg("发送模版消息失败,Err:"+err.Error()+";msg:"+msg, 3)
  227. //go utils.SendEmail("发送模版消息失败"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  228. utils.FileLog.Info(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg))
  229. }
  230. if msg != "" {
  231. utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
  232. }
  233. }()
  234. utils.FileLog.Info("%s", "services SendMsg")
  235. //accessToken, err := models.GetWxAccessToken()
  236. //if err != nil {
  237. // msg = "GetWxAccessToken Err:" + err.Error()
  238. // return
  239. //}
  240. //if accessToken == "" {
  241. // msg = "accessToken is empty"
  242. // return
  243. //}
  244. utils.FileLog.Info("mobile:%s", mobile)
  245. openIdList, err := system.GetAdminOpenIdListByMobile(mobile)
  246. if err != nil {
  247. msg = "get openIdList err:" + err.Error()
  248. return
  249. }
  250. utils.FileLog.Info("openIdListCount:%s", len(openIdList))
  251. //fmt.Println("openIdListCount:", len(openIdList))
  252. if len(openIdList) > 0 && utils.TemplateIdByCompanyApply != "" {
  253. utils.FileLog.Info("start send")
  254. //sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
  255. fmt.Println("send start")
  256. utils.FileLog.Info("send start")
  257. //sendMap := make(map[string]interface{})
  258. //sendData := make(map[string]interface{})
  259. var first, keyword1, keyword2, keyword3, remark string
  260. if tmpStr, ok := wxMsgMap[0]; ok {
  261. first = tmpStr
  262. } else {
  263. first = "Hi,有新的订单需要审批"
  264. }
  265. if tmpStr, ok := wxMsgMap[1]; ok {
  266. keyword1 = tmpStr
  267. }
  268. if tmpStr, ok := wxMsgMap[2]; ok {
  269. keyword2 = tmpStr
  270. }
  271. if tmpStr, ok := wxMsgMap[3]; ok {
  272. keyword3 = tmpStr
  273. }
  274. if tmpStr, ok := wxMsgMap[4]; ok {
  275. remark = tmpStr
  276. }
  277. //sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
  278. //sendData["keyword1"] = map[string]interface{}{"value": keyword1, "color": "#173177"}
  279. //sendData["keyword2"] = map[string]interface{}{"value": keyword2, "color": "#173177"}
  280. //sendData["keyword3"] = map[string]interface{}{"value": keyword3, "color": "#173177"}
  281. //sendData["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
  282. //
  283. //sendMap["template_id"] = utils.TemplateIdByCompanyApply
  284. //sendMap["url"] = redirectUrl //跳转地址
  285. //sendMap["data"] = sendData
  286. //if wxAppPath != "" {
  287. // sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxCrmAppId, "pagepath": wxAppPath}
  288. //}
  289. //sendTemplateMsg(sendUrl, sendMap, openIdList, mobile, utils.TEMPLATE_MSG_APPLY)
  290. openIdArr := make([]string, len(openIdList))
  291. for i, v := range openIdList {
  292. openIdArr[i] = v.OpenId
  293. }
  294. sendInfo := new(SendWxTemplate)
  295. sendInfo.WxAppId = utils.AdminWxAppId
  296. sendInfo.First = first
  297. sendInfo.Keyword1 = keyword1
  298. sendInfo.Keyword2 = keyword2
  299. sendInfo.Keyword3 = keyword3
  300. sendInfo.Remark = remark
  301. sendInfo.TemplateId = utils.TemplateIdByCompanyApply
  302. sendInfo.RedirectUrl = redirectUrl
  303. sendInfo.RedirectTarget = 2
  304. sendInfo.Resource = mobile
  305. sendInfo.SendType = utils.TEMPLATE_MSG_APPLY
  306. sendInfo.OpenIdArr = openIdArr
  307. if wxAppPath != "" {
  308. sendInfo.RedirectUrl = wxAppPath
  309. }
  310. err = SendTemplateMsg(sendInfo)
  311. }
  312. utils.FileLog.Info("send end")
  313. return
  314. }
  315. // 销售跨部门领取客户通知
  316. func SendCompanyReceiveWxTemplateMsg(companyName, productName, sellerName, otherSellerMobile string) (err error) {
  317. var msg string
  318. defer func() {
  319. if err != nil {
  320. fmt.Println("err:", err)
  321. go alarm_msg.SendAlarmMsg("发送模版消息失败,Err:"+err.Error()+";msg:"+msg, 3)
  322. //go utils.SendEmail("发送模版消息失败"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  323. utils.FileLog.Info(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg))
  324. }
  325. if msg != "" {
  326. utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
  327. }
  328. }()
  329. utils.FileLog.Info("%s", "services SendMsg")
  330. //TemplateIdByCompanyReceive
  331. //accessToken, err := models.GetWxAccessToken()
  332. //
  333. //if err != nil {
  334. // msg = "GetWxAccessToken Err:" + err.Error()
  335. // return
  336. //}
  337. //if accessToken == "" {
  338. // msg = "accessToken is empty"
  339. // return
  340. //}
  341. utils.FileLog.Info("mobile:%s", otherSellerMobile)
  342. openIdList, err := system.GetAdminOpenIdListByMobile(otherSellerMobile)
  343. if err != nil {
  344. msg = "get openIdList err:" + err.Error()
  345. return
  346. }
  347. utils.FileLog.Info("openIdListCount:%s", len(openIdList))
  348. redirectUrl := ""
  349. if len(openIdList) > 0 && utils.TemplateIdByCompanyApply != "" {
  350. utils.FileLog.Info("start send")
  351. //sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
  352. fmt.Println("send start")
  353. utils.FileLog.Info("send start")
  354. //sendMap := make(map[string]interface{})
  355. //sendData := make(map[string]interface{})
  356. first := fmt.Sprint("您有客户被", productName, "销售-", sellerName, "领取,请留意。")
  357. keyword1 := companyName
  358. //keyword2 := "客户跨部门领取"
  359. keyword2 := fmt.Sprintf("%s销售-%s跨部门领取", productName, sellerName)
  360. keyword3 := ""
  361. remark := ""
  362. //sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
  363. //sendData["keyword1"] = map[string]interface{}{"value": keyword1, "color": "#173177"}
  364. //sendData["keyword2"] = map[string]interface{}{"value": keyword2, "color": "#173177"}
  365. //sendData["keyword3"] = map[string]interface{}{"value": keyword3, "color": "#173177"}
  366. //sendData["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
  367. //
  368. //sendMap["template_id"] = utils.TemplateIdByCompanyReceive
  369. //sendMap["url"] = redirectUrl //跳转地址
  370. //sendMap["data"] = sendData
  371. //sendTemplateMsg(sendUrl, sendMap, openIdList, otherSellerMobile, utils.TEMPLATE_MSG_RECEIVE)
  372. openIdArr := make([]string, len(openIdList))
  373. for i, v := range openIdList {
  374. openIdArr[i] = v.OpenId
  375. }
  376. sendInfo := new(SendWxTemplate)
  377. sendInfo.WxAppId = utils.AdminWxAppId
  378. sendInfo.First = first
  379. sendInfo.Keyword1 = keyword1
  380. sendInfo.Keyword2 = keyword2
  381. sendInfo.Keyword3 = keyword3
  382. sendInfo.Remark = remark
  383. sendInfo.TemplateId = utils.TemplateIdByCompanyReceive
  384. sendInfo.RedirectUrl = redirectUrl
  385. sendInfo.RedirectTarget = 2
  386. sendInfo.Resource = otherSellerMobile
  387. sendInfo.SendType = utils.TEMPLATE_MSG_RECEIVE
  388. sendInfo.OpenIdArr = openIdArr
  389. err = SendTemplateMsg(sendInfo)
  390. }
  391. utils.FileLog.Info("send end")
  392. return
  393. }
  394. func SendArticleWxTemplateMsg(nickName, aticleTiele, publishDate, abstract, industryName, msgType string, articleId, departmentId, industrialManagementId int, isResearch bool) (err error) {
  395. var msg string
  396. defer func() {
  397. if err != nil {
  398. fmt.Println("err:", err)
  399. go alarm_msg.SendAlarmMsg("发送模版消息失败,Err:"+err.Error()+";msg:"+msg, 3)
  400. //go utils.SendEmail("发送模版消息失败"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  401. utils.FileLog.Info(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg))
  402. }
  403. if msg != "" {
  404. utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
  405. }
  406. }()
  407. var openIdList []*cygx.OpenIdList
  408. var resource string
  409. if msgType == "Department" {
  410. openIdList, err = cygx.GetFollowDepartmentOpenIdList(departmentId)
  411. resource = strconv.Itoa(departmentId)
  412. } else {
  413. openIdList, err = cygx.GetFollowindustrialOpenIdList(industrialManagementId)
  414. resource = strconv.Itoa(industrialManagementId)
  415. }
  416. if err != nil {
  417. msg = "get openIdList err:" + err.Error()
  418. return
  419. }
  420. if len(openIdList) == 0 {
  421. return err
  422. }
  423. if len(openIdList) > 0 && utils.TemplateIdByProduct != "" {
  424. var first string
  425. var keyword1 string
  426. var keyword2 string
  427. if msgType == "Department" {
  428. first = fmt.Sprint("您关注的作者发布了新的报告")
  429. keyword1 = "作者昵称--" + nickName
  430. } else {
  431. first = fmt.Sprint("您关注的产业有更新报告")
  432. keyword1 = industryName
  433. }
  434. if isResearch {
  435. first = "您关注的主题有更新报告"
  436. abstract = "--"
  437. }
  438. keyword2 = aticleTiele
  439. keyword3 := publishDate
  440. keyword4 := abstract
  441. remark := ""
  442. openIdArr := make([]string, len(openIdList))
  443. for i, v := range openIdList {
  444. openIdArr[i] = v.OpenId
  445. }
  446. sendInfo := new(SendWxTemplate)
  447. sendInfo.First = first
  448. sendInfo.Keyword1 = keyword1
  449. sendInfo.Keyword2 = keyword2
  450. sendInfo.Keyword3 = keyword3
  451. sendInfo.Keyword4 = keyword4
  452. sendInfo.Remark = remark
  453. sendInfo.TemplateId = utils.TemplateIdByProductXzs
  454. sendInfo.RedirectUrl = "pageMy/reportDetail/reportDetail?id=" + strconv.Itoa(articleId)
  455. sendInfo.RedirectTarget = 3
  456. sendInfo.Resource = resource
  457. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE
  458. sendInfo.OpenIdArr = openIdArr
  459. err = SendTemplateMsg(sendInfo)
  460. }
  461. return
  462. }
  463. // SendDayReportWxTemplateMsg 发送日报(周报、双周报、月报)模板消息
  464. //func SendDayReportWxTemplateMsg(researchReport *models.ResearchReport) (err error) {
  465. // var msg string
  466. // defer func() {
  467. // if err != nil {
  468. // go alarm_msg.SendAlarmMsg("发送日报(周报)模版消息失败,Err:"+err.Error()+";msg:"+msg, 3)
  469. // //go utils.SendEmail("发送日报(周报)模版消息失败"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  470. // utils.FileLog.Info(fmt.Sprintf("发送日报(周报)模版消息失败,Err:%s,%s", err.Error(), msg))
  471. // }
  472. // if msg != "" {
  473. // utils.FileLog.Info("发送日报(周报)模版消息失败,msg:%s", msg)
  474. // }
  475. // }()
  476. //
  477. // utils.FileLog.Info("%s", "services SendMsg")
  478. // resource := strconv.Itoa(researchReport.ResearchReportId)
  479. // //跳转地址
  480. // redirectUrl := fmt.Sprint(utils.DayReportTemplateRedirectUrl, researchReport.ResearchReportId, "/", researchReport.Type)
  481. // first := "Hi,最新一期晨报已上线,欢迎查看"
  482. // keyword1 := "弘则晨报"
  483. // keyword2 := researchReport.ResearchReportName
  484. // keyword3 := researchReport.ResearchReportDate.Format(utils.FormatDate)
  485. // keyword4 := researchReport.ResearchReportName
  486. // switch researchReport.Type {
  487. // case "day":
  488. // first = "Hi,最新一期晨报已上线,欢迎查看"
  489. // keyword1 = "弘则晨报"
  490. // case "week":
  491. // first = "Hi,最新一期周报已上线,欢迎查看"
  492. // keyword1 = "弘则周报"
  493. // case "two_week":
  494. // first = "Hi,最新一期双周报已上线,欢迎查看"
  495. // keyword1 = "弘则双周报"
  496. // case "month":
  497. // first = "Hi,最新一期月报已上线,欢迎查看"
  498. // keyword1 = "弘则月报"
  499. //
  500. // // 模板消息的名称替换
  501. // tmpReport, _ := models.GetReportByOldReportId(researchReport.ResearchReportId)
  502. // if tmpReport != nil {
  503. // keyword1 = fmt.Sprintf("弘则%s", tmpReport.ClassifyNameSecond)
  504. // }
  505. // case "other":
  506. // first = "Hi,最新一期点评已上线,欢迎查看"
  507. // keyword1 = "数据点评"
  508. // }
  509. //
  510. // //accessToken, err := models.GetWxAccessToken()
  511. // //if err != nil {
  512. // // msg = "GetWxAccessToken Err:" + err.Error()
  513. // // return
  514. // //}
  515. // //fmt.Println(accessToken)
  516. // //if accessToken == "" {
  517. // // msg = "accessToken is empty"
  518. // // return
  519. // //}
  520. // openIdList, err := models.GetOpenIdList()
  521. // if err != nil {
  522. // msg = "get openIdList err:" + err.Error()
  523. // return
  524. // }
  525. // fmt.Println("openIdListCount:", len(openIdList))
  526. // //sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
  527. // fmt.Println("send start")
  528. // utils.FileLog.Info("send start")
  529. // //if report.MsgIsSend == 0 {
  530. // //sendMap := make(map[string]interface{})
  531. // //sendData := make(map[string]interface{})
  532. //
  533. // //sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
  534. // //sendData["keyword1"] = map[string]interface{}{"value": keyword1, "color": "#173177"}
  535. // //sendData["keyword2"] = map[string]interface{}{"value": keyword2, "color": "#173177"}
  536. // //sendData["keyword3"] = map[string]interface{}{"value": keyword3, "color": "#173177"}
  537. // //sendData["keyword4"] = map[string]interface{}{"value": keyword4, "color": "#173177"}
  538. //
  539. // //sendMap["template_id"] = utils.TemplateIdByProduct
  540. // //sendMap["url"] = redirectUrl
  541. // //sendMap["data"] = sendData
  542. // //sendTemplateMsg(sendUrl, sendMap, openIdList, resource, utils.TEMPLATE_MSG_CYGX_DAY_REPORT)
  543. // //}
  544. //
  545. // openIdArr := make([]string, len(openIdList))
  546. // for i, v := range openIdList {
  547. // openIdArr[i] = v.OpenId
  548. // }
  549. //
  550. // sendInfo := new(SendWxTemplate)
  551. // sendInfo.First = first
  552. // sendInfo.Keyword1 = keyword1
  553. // sendInfo.Keyword2 = keyword2
  554. // sendInfo.Keyword3 = keyword3
  555. // sendInfo.Keyword4 = keyword4
  556. // sendInfo.TemplateId = utils.TemplateIdByProduct
  557. // sendInfo.RedirectUrl = redirectUrl
  558. // sendInfo.RedirectTarget = 1
  559. // sendInfo.Resource = resource
  560. // sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_DAY_REPORT
  561. // sendInfo.OpenIdArr = openIdArr
  562. //
  563. // err = SendTemplateMsg(sendInfo)
  564. //
  565. // fmt.Println("send end")
  566. // utils.FileLog.Info("send end")
  567. // return
  568. //}
  569. // SendWxMsgWithActivityAppointmentRemind 活动预约/报名时间通知
  570. func SendWxMsgWithActivityAppointmentRemind(first, keyword1, keyword2, remark, wxAppPath string, openIdList []*models.OpenIdList) (err error) {
  571. var msg string
  572. defer func() {
  573. if err != nil {
  574. go alarm_msg.SendAlarmMsg("发送模版消息失败,Err:"+err.Error()+";msg:"+msg, 3)
  575. //go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  576. utils.FileLog.Info(fmt.Sprintf("发送模版消息失败,Err:%s", err.Error()))
  577. }
  578. }()
  579. //utils.FileLog.Info("%s", "services SendMsg")
  580. //accessToken, err := models.GetWxAccessToken()
  581. //if err != nil {
  582. // msg = "GetWxAccessToken Err:" + err.Error()
  583. // return
  584. //}
  585. //if accessToken == "" {
  586. // msg = "accessToken is empty"
  587. // return
  588. //}
  589. //sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
  590. //sendMap := make(map[string]interface{})
  591. //sendData := make(map[string]interface{})
  592. //sendMap["template_id"] = utils.WxMsgTemplateIdActivityChangeApply
  593. //sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
  594. //sendData["keyword1"] = map[string]interface{}{"value": keyword1, "color": "#173177"}
  595. //sendData["keyword2"] = map[string]interface{}{"value": keyword2, "color": "#173177"}
  596. //sendData["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
  597. //if wxAppPath != "" {
  598. // sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxYbAppId, "pagepath": wxAppPath}
  599. //}
  600. //sendMap["data"] = sendData
  601. //sendTemplateMsg(sendUrl, sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_ACTIVITY_APPOINTMENT)
  602. openIdArr := make([]string, len(openIdList))
  603. for i, v := range openIdList {
  604. openIdArr[i] = v.OpenId
  605. }
  606. sendInfo := new(SendWxTemplate)
  607. sendInfo.First = first
  608. sendInfo.Keyword1 = keyword1
  609. sendInfo.Keyword2 = keyword2
  610. sendInfo.Remark = remark
  611. sendInfo.TemplateId = utils.WxMsgTemplateIdActivityChangeApply
  612. sendInfo.RedirectUrl = wxAppPath
  613. sendInfo.RedirectTarget = 1
  614. sendInfo.Resource = wxAppPath
  615. sendInfo.SendType = utils.TEMPLATE_MSG_ACTIVITY_APPOINTMENT
  616. sendInfo.OpenIdArr = openIdArr
  617. err = SendTemplateMsg(sendInfo)
  618. return
  619. }
  620. // 路演->研究员收到待处理的申请
  621. func SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath string, openIdList []*system.OpenIdList) (err error) {
  622. var msg string
  623. defer func() {
  624. if err != nil {
  625. go alarm_msg.SendAlarmMsg("发送模版消息失败,Err:"+err.Error()+";msg:"+msg, 3)
  626. //go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  627. utils.FileLog.Info(fmt.Sprintf("发送模版消息失败,Err:%s", err.Error()))
  628. }
  629. }()
  630. utils.FileLog.Info("%s", "services SendMsg")
  631. //accessToken, err := models.GetWxAccessToken()
  632. //if err != nil {
  633. // msg = "GetWxAccessToken Err:" + err.Error()
  634. // return
  635. //}
  636. //if accessToken == "" {
  637. // msg = "accessToken is empty"
  638. // return
  639. //}
  640. //sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
  641. //sendMap := make(map[string]interface{})
  642. //sendData := make(map[string]interface{})
  643. //sendMap["template_id"] = utils.WxMsgTemplateIdWithRoadshowPending
  644. //sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
  645. //sendData["keyword1"] = map[string]interface{}{"value": keyword1, "color": "#173177"}
  646. //sendData["keyword2"] = map[string]interface{}{"value": keyword2, "color": "#173177"}
  647. //sendData["keyword3"] = map[string]interface{}{"value": keyword3, "color": "#173177"}
  648. //sendData["keyword4"] = map[string]interface{}{"value": keyword4, "color": "#173177"}
  649. //sendData["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
  650. //if wxAppPath != "" && utils.RunMode == "release" {
  651. // sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxCrmAppId, "pagepath": wxAppPath}
  652. //}
  653. //sendMap["data"] = sendData
  654. //sendTemplateMsg(sendUrl, sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_ACTIVITY_APPOINTMENT)
  655. openIdArr := make([]string, len(openIdList))
  656. for i, v := range openIdList {
  657. openIdArr[i] = v.OpenId
  658. }
  659. sendInfo := new(SendWxTemplate)
  660. sendInfo.WxAppId = utils.AdminWxAppId
  661. sendInfo.First = first
  662. sendInfo.Keyword1 = keyword1
  663. sendInfo.Keyword2 = keyword2
  664. sendInfo.Keyword3 = keyword3
  665. sendInfo.Keyword4 = keyword4
  666. sendInfo.Remark = remark
  667. sendInfo.TemplateId = utils.WxMsgTemplateIdWithRoadshowPending
  668. if wxAppPath != "" && utils.RunMode == "release" {
  669. sendInfo.RedirectUrl = wxAppPath
  670. }
  671. sendInfo.RedirectTarget = 2
  672. sendInfo.Resource = wxAppPath
  673. sendInfo.SendType = utils.TEMPLATE_MSG_ACTIVITY_APPOINTMENT
  674. sendInfo.OpenIdArr = openIdArr
  675. err = SendTemplateMsg(sendInfo)
  676. return
  677. }
  678. // 路演->销售收到处理结果
  679. func SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, keyword3, keyword4, keyword5, remark, wxAppPath string, openIdList []*system.OpenIdList) (err error) {
  680. var msg string
  681. defer func() {
  682. if err != nil {
  683. go alarm_msg.SendAlarmMsg("发送模版消息失败,Err:"+err.Error()+";msg:"+msg, 3)
  684. //go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  685. utils.FileLog.Info(fmt.Sprintf("发送模版消息失败,Err:%s", err.Error()))
  686. }
  687. }()
  688. utils.FileLog.Info("%s", "services SendMsg")
  689. //accessToken, err := models.GetWxAccessToken()
  690. //if err != nil {
  691. // msg = "GetWxAccessToken Err:" + err.Error()
  692. // return
  693. //}
  694. //if accessToken == "" {
  695. // msg = "accessToken is empty"
  696. // return
  697. //}
  698. //sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
  699. //sendMap := make(map[string]interface{})
  700. //sendData := make(map[string]interface{})
  701. //sendMap["template_id"] = utils.WxMsgTemplateIdWithRoadshowDetailResult
  702. //sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
  703. //sendData["keyword1"] = map[string]interface{}{"value": keyword1, "color": "#173177"}
  704. //sendData["keyword2"] = map[string]interface{}{"value": keyword2, "color": "#173177"}
  705. //sendData["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
  706. //
  707. //if wxAppPath != "" && utils.RunMode == "release" {
  708. // sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxCrmAppId, "pagepath": wxAppPath}
  709. //}
  710. //sendMap["data"] = sendData
  711. //sendTemplateMsg(sendUrl, sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_ACTIVITY_APPOINTMENT)
  712. openIdArr := make([]string, len(openIdList))
  713. for i, v := range openIdList {
  714. openIdArr[i] = v.OpenId
  715. }
  716. sendInfo := new(SendWxTemplate)
  717. sendInfo.WxAppId = utils.AdminWxAppId
  718. sendInfo.First = first
  719. sendInfo.Keyword1 = keyword1
  720. sendInfo.Keyword2 = keyword2
  721. sendInfo.Keyword3 = keyword3
  722. sendInfo.Keyword4 = keyword4
  723. sendInfo.Keyword5 = keyword5
  724. sendInfo.Remark = remark
  725. sendInfo.TemplateId = utils.WxMsgTemplateIdWithRoadshowDetailResult
  726. if wxAppPath != "" && utils.RunMode == "release" {
  727. sendInfo.RedirectUrl = wxAppPath
  728. }
  729. sendInfo.RedirectTarget = 2
  730. sendInfo.Resource = wxAppPath
  731. sendInfo.SendType = utils.TEMPLATE_MSG_ACTIVITY_APPOINTMENT
  732. sendInfo.OpenIdArr = openIdArr
  733. err = SendTemplateMsg(sendInfo)
  734. return
  735. }
  736. // 路演->研究员收到活动删除通知
  737. func SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, remark, wxAppPath string, openIdList []*system.OpenIdList) (err error) {
  738. var msg string
  739. defer func() {
  740. if err != nil {
  741. go alarm_msg.SendAlarmMsg("发送模版消息失败,Err:"+err.Error()+";msg:"+msg, 3)
  742. //go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  743. utils.FileLog.Info(fmt.Sprintf("发送模版消息失败,Err:%s", err.Error()))
  744. }
  745. }()
  746. utils.FileLog.Info("%s", "services SendMsg")
  747. //accessToken, err := models.GetWxAccessToken()
  748. //if err != nil {
  749. // msg = "GetWxAccessToken Err:" + err.Error()
  750. // return
  751. //}
  752. //if accessToken == "" {
  753. // msg = "accessToken is empty"
  754. // return
  755. //}
  756. //sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
  757. //sendMap := make(map[string]interface{})
  758. //sendData := make(map[string]interface{})
  759. //sendMap["template_id"] = utils.WxMsgTemplateIdWithRoadshowDeleteNotice
  760. //sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
  761. //sendData["keyword1"] = map[string]interface{}{"value": keyword1, "color": "#173177"}
  762. //sendData["keyword2"] = map[string]interface{}{"value": keyword2, "color": "#173177"}
  763. //sendData["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
  764. //if wxAppPath != "" && utils.RunMode == "release" {
  765. // sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxCrmAppId, "pagepath": wxAppPath}
  766. //}
  767. //sendMap["data"] = sendData
  768. //sendTemplateMsg(sendUrl, sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_ACTIVITY_APPOINTMENT)
  769. openIdArr := make([]string, len(openIdList))
  770. for i, v := range openIdList {
  771. openIdArr[i] = v.OpenId
  772. }
  773. sendInfo := new(SendWxTemplate)
  774. sendInfo.WxAppId = utils.AdminWxAppId
  775. sendInfo.First = first
  776. sendInfo.Keyword1 = keyword1
  777. sendInfo.Keyword2 = keyword2
  778. sendInfo.Remark = remark
  779. sendInfo.TemplateId = utils.WxMsgTemplateIdWithRoadshowDeleteNotice
  780. if wxAppPath != "" && utils.RunMode == "release" {
  781. sendInfo.RedirectUrl = wxAppPath
  782. }
  783. sendInfo.RedirectTarget = 2
  784. sendInfo.Resource = wxAppPath
  785. sendInfo.SendType = utils.TEMPLATE_MSG_ACTIVITY_APPOINTMENT
  786. sendInfo.OpenIdArr = openIdArr
  787. err = SendTemplateMsg(sendInfo)
  788. return
  789. }
  790. // SendMiniProgramReportWxMsg 推送报告微信模板消息-小程序链接
  791. func SendMiniProgramReportWxMsg(reportId int) (err error) {
  792. var msg string
  793. reportIdStr := strconv.Itoa(reportId)
  794. defer func() {
  795. if err != nil {
  796. fmt.Println("msg:", msg)
  797. utils.FileLog.Error(fmt.Sprintf("SendMiniProgramReportWxMsg, 发送报告模版消息失败, ReportId:%s, Err:%s", reportIdStr, err.Error()))
  798. go alarm_msg.SendAlarmMsg("SendMiniProgramReportWxMsg发送报告模版消息失败;"+"ReportId:"+reportIdStr+",Err:"+err.Error()+";msg:"+msg, 3)
  799. //go utils.SendEmail("SendMiniProgramReportWxMsg发送报告模版消息失败"+"【"+utils.APPNAME+"】"+"【"+utils.RunMode+"】"+time.Now().Format("2006-01-02 15:04:05"), "ReportId:"+reportIdStr+";"+msg+";Err:"+err.Error(), toUser)
  800. }
  801. }()
  802. utils.FileLog.Info("%s", "services SendMsg")
  803. report, err := models.GetReportById(reportId)
  804. if err != nil {
  805. msg = "GetReportInfo Err:" + err.Error()
  806. return
  807. }
  808. if report == nil {
  809. utils.FileLog.Info("报告信息不存在")
  810. return
  811. }
  812. //if report.MsgIsSend == 1 {
  813. // return
  814. //}
  815. //accessToken, err := models.GetWxAccessToken()
  816. //if err != nil {
  817. // msg = "GetWxAccessToken Err:" + err.Error()
  818. // return
  819. //}
  820. //if accessToken == "" {
  821. // msg = "accessToken is empty"
  822. // return
  823. //}
  824. var openIdArr []string
  825. if report.ClassifyIdSecond <= 0 {
  826. openIdArr, err = models.GetOpenIdArr()
  827. if err != nil {
  828. msg = "get GetOpenIdArr err:" + err.Error()
  829. return
  830. }
  831. } else {
  832. classify, err := models.GetClassifyById(report.ClassifyIdSecond)
  833. if err != nil {
  834. msg = "获取报告分类失败 err:" + err.Error()
  835. return err
  836. }
  837. if classify.IsMassSend == 1 {
  838. openIdArr, err = models.GetOpenIdArr()
  839. if err != nil {
  840. msg = "get GetOpenIdArr err:" + err.Error()
  841. return err
  842. }
  843. } else {
  844. openIdArr, err = models.GetOpenIdArrByClassifyNameSecond(report.ClassifyNameSecond)
  845. if err != nil {
  846. msg = "GetOpenIdArrByClassifyNameSecond err:" + err.Error()
  847. return err
  848. }
  849. }
  850. }
  851. //sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
  852. //fmt.Println("send start")
  853. //utils.FileLog.Info("send start")
  854. //sendMap := make(map[string]interface{})
  855. //sendData := make(map[string]interface{})
  856. title := fmt.Sprintf("弘则%s", report.ClassifyNameFirst)
  857. if CheckTwoWeekOrMonthReport(report.ClassifyIdFirst, report.ClassifyNameFirst) {
  858. title = fmt.Sprintf("弘则%s", report.ClassifyNameSecond)
  859. }
  860. //redirectUrl := utils.TemplateRedirectUrl + strconv.Itoa(reportId)
  861. first := fmt.Sprintf("Hi,最新一期%s已上线,欢迎查看", report.ClassifyNameFirst)
  862. keyword1 := title
  863. keyword2 := report.Title
  864. keyword3 := report.PublishTime
  865. keyword4 := report.Abstract
  866. //sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
  867. //sendData["keyword1"] = map[string]interface{}{"value": keyword1, "color": "#173177"}
  868. //sendData["keyword2"] = map[string]interface{}{"value": keyword2, "color": "#173177"}
  869. //sendData["keyword3"] = map[string]interface{}{"value": keyword3, "color": "#173177"}
  870. //sendData["keyword4"] = map[string]interface{}{"value": keyword4, "color": "#173177"}
  871. //
  872. //sendMap["template_id"] = utils.TemplateIdByProduct
  873. ////sendMap["url"] = redirectUrl
  874. //sendMap["data"] = sendData
  875. var wxAppPath string
  876. if report.ChapterType == utils.REPORT_TYPE_WEEK {
  877. wxAppPath = fmt.Sprintf("pages-report/chapterList?reportId=%s", reportIdStr)
  878. } else {
  879. wxAppPath = fmt.Sprintf("pages-report/reportDetail?reportId=%s", reportIdStr)
  880. }
  881. //if wxAppPath != "" {
  882. // sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxYbAppId, "pagepath": wxAppPath}
  883. //}
  884. //err = sendTemplateMsg(sendUrl, sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_REPORT)
  885. sendInfo := new(SendWxTemplate)
  886. sendInfo.First = first
  887. sendInfo.Keyword1 = keyword1
  888. sendInfo.Keyword2 = keyword2
  889. sendInfo.Keyword3 = keyword3
  890. sendInfo.Keyword4 = keyword4
  891. sendInfo.TemplateId = utils.TemplateIdByProduct
  892. sendInfo.RedirectUrl = wxAppPath
  893. sendInfo.Resource = wxAppPath
  894. sendInfo.SendType = utils.TEMPLATE_MSG_REPORT
  895. sendInfo.OpenIdArr = openIdArr
  896. sendInfo.RedirectTarget = 1
  897. err = SendTemplateMsg(sendInfo)
  898. return
  899. }
  900. // CheckTwoWeekOrMonthReport 校验推送报告是否为双周报或者月报
  901. func CheckTwoWeekOrMonthReport(classifyId int, classifyName string) (ok bool) {
  902. if utils.RunMode == "debug" {
  903. miniStrArr := []string{
  904. "双周报", "月报",
  905. }
  906. if utils.InArrayByStr(miniStrArr, classifyName) {
  907. ok = true
  908. }
  909. } else {
  910. // 此处生产环境用ID主要是担心分类改了名字...
  911. IdArr := []int{
  912. 96, 112,
  913. }
  914. if utils.InArrayByInt(IdArr, classifyId) {
  915. ok = true
  916. }
  917. }
  918. return
  919. }
  920. // 专项调研活动模板消息通知
  921. func SendWxMsgWithCygxActivitySpecial(activityId int) (err error) {
  922. var msg string
  923. defer func() {
  924. if err != nil {
  925. go alarm_msg.SendAlarmMsg("发送模版消息失败,Err:"+err.Error()+";msg:"+msg, 3)
  926. //go utils.SendEmail("发送模版消息失败"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  927. utils.FileLogCygx.Info(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg))
  928. }
  929. }()
  930. activityInfo, err := cygx.GetAddActivityInfoSpecialById(activityId)
  931. if err != nil {
  932. msg = "GetReportInfo Err:" + err.Error()
  933. return
  934. }
  935. var openIdList []*cygx.OpenIdList
  936. openIdList, err = cygx.GetActivitySpecialOpenIdList()
  937. if err != nil {
  938. msg = "get openIdList err:" + err.Error()
  939. return
  940. }
  941. if len(openIdList) == 0 {
  942. return err
  943. }
  944. //sendMap := make(map[string]interface{})
  945. //sendData := make(map[string]interface{})
  946. //var first string
  947. //var keyword1 string
  948. //var keyword2 string
  949. //first = "专项调研【" + activityInfo.ResearchTheme + "】已开启预报名"
  950. //
  951. //redirectUrl := ""
  952. //sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
  953. //sendData["keyword1"] = map[string]interface{}{"value": keyword1, "color": "#173177"}
  954. //sendData["keyword2"] = map[string]interface{}{"value": keyword2, "color": "#173177"}
  955. //sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
  956. //if utils.RunMode == "release" {
  957. // sendMap["template_id"] = utils.WxMsgTemplateIdActivityChangeApplyXzs
  958. //} else {
  959. // sendMap["template_id"] = utils.WxMsgTemplateIdActivityChangeApply
  960. //}
  961. //sendMap["url"] = redirectUrl
  962. //sendMap["data"] = sendData
  963. //sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxCygxAppId, "pagepath": "activityPages/specialDetail/specialDetail?id=" + strconv.Itoa(activityId)}
  964. //sendTemplateMsg(sendUrl, sendMap, openIdList, strconv.Itoa(activityId), utils.TEMPLATE_MSG_CYGX_ACTIVITY_UPDATE)
  965. openIdArr := make([]string, len(openIdList))
  966. for i, v := range openIdList {
  967. openIdArr[i] = v.OpenId
  968. }
  969. var first, keyword1, keyword2, keyword3, keyword4, remark, redirectUrl string
  970. keyword1 = "专项调研【" + activityInfo.ResearchTheme + "】"
  971. keyword2 = "已开启预报名"
  972. //if activityInfo.SpecialType == 1 {
  973. // keyword2 += "线上 预期时间:" + activityInfo.ActivityTimeText
  974. //} else {
  975. // keyword2 += "线下 " + "(" + activityInfo.City + ") 预期时间:" + activityInfo.ActivityTimeText
  976. //}
  977. redirectUrl = utils.WX_MSG_PATH_ACTIVITY_SPECIAL_DETAIL + strconv.Itoa(activityId)
  978. sendInfo := new(SendWxTemplate)
  979. sendInfo.First = first
  980. sendInfo.Keyword1 = keyword1
  981. sendInfo.Keyword2 = keyword2
  982. sendInfo.Keyword3 = keyword3
  983. sendInfo.Keyword4 = keyword4
  984. sendInfo.Remark = remark
  985. sendInfo.TemplateId = utils.WxMsgTemplateIdActivityChangeApplyXzs
  986. sendInfo.RedirectUrl = redirectUrl
  987. sendInfo.RedirectTarget = 3
  988. sendInfo.Resource = strconv.Itoa(activityId)
  989. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ACTIVITY_UPDATE
  990. sendInfo.OpenIdArr = openIdArr
  991. err = SendTemplateMsg(sendInfo)
  992. if err != nil {
  993. err = errors.New("SendTemplateMsg, Err: " + err.Error())
  994. return
  995. }
  996. return
  997. }
  998. // SendYbQuestionDistributeWxMsg 推送研报小程序模板消息-问答社区分配
  999. func SendYbQuestionDistributeWxMsg(questionId, adminId int, openid, questionTitle, remark string) (err error) {
  1000. var errMsg string
  1001. defer func() {
  1002. if err != nil {
  1003. alarmMsg := fmt.Sprintf("SendMiniProgramReportWxMsg-推送问答社区分配模版消息失败; QuestionId: %d; Err: %s; Msg: %s", questionId, err.Error(), errMsg)
  1004. utils.FileLog.Error(alarmMsg)
  1005. go alarm_msg.SendAlarmMsg(alarmMsg, 3)
  1006. }
  1007. }()
  1008. //accessToken, err := models.GetWxAccessToken()
  1009. //if err != nil {
  1010. // errMsg = "GetWxAccessToken Err:" + err.Error()
  1011. // return
  1012. //}
  1013. //if accessToken == "" {
  1014. // errMsg = "accessToken is empty"
  1015. // return
  1016. //}
  1017. openIdList := make([]*system.OpenIdList, 0)
  1018. openIdList = append(openIdList, &system.OpenIdList{
  1019. OpenId: openid,
  1020. AdminId: adminId,
  1021. })
  1022. //sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
  1023. //sendMap := make(map[string]interface{})
  1024. //sendData := make(map[string]interface{})
  1025. first := "您好,有新的提问待回复"
  1026. keyword1 := questionTitle
  1027. keyword2 := "待回复"
  1028. if remark == "" {
  1029. //remark = "请点击详情尽快处理"
  1030. keyword2 = remark
  1031. }
  1032. //sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
  1033. //sendData["keyword1"] = map[string]interface{}{"value": keyword1, "color": "#173177"}
  1034. //sendData["keyword2"] = map[string]interface{}{"value": keyword2, "color": "#173177"}
  1035. //sendData["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
  1036. //
  1037. //sendMap["template_id"] = utils.WxMsgTemplateIdWithYbCommunityQuestion
  1038. //sendMap["data"] = sendData
  1039. wxAppPath := fmt.Sprintf("pages-question/answerDetail?id=%d", questionId)
  1040. if utils.RunMode == "debug" {
  1041. // 仅测试环境测试用
  1042. wxAppPath = "pages-report/chapterList?reportId=3800"
  1043. }
  1044. //if wxAppPath != "" {
  1045. // sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxYbAppId, "pagepath": wxAppPath}
  1046. //}
  1047. //err = sendTemplateMsg(sendUrl, sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION)
  1048. openIdArr := make([]string, len(openIdList))
  1049. for i, v := range openIdList {
  1050. openIdArr[i] = v.OpenId
  1051. }
  1052. sendInfo := new(SendWxTemplate)
  1053. sendInfo.WxAppId = utils.AdminWxAppId
  1054. sendInfo.First = first
  1055. sendInfo.Keyword1 = keyword1
  1056. sendInfo.Keyword2 = keyword2
  1057. sendInfo.Remark = remark
  1058. sendInfo.RedirectUrl = wxAppPath
  1059. sendInfo.TemplateId = utils.WxMsgTemplateIdWithYbCommunityQuestion
  1060. sendInfo.RedirectTarget = 1
  1061. sendInfo.Resource = wxAppPath
  1062. sendInfo.SendType = utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION
  1063. sendInfo.OpenIdArr = openIdArr
  1064. err = SendTemplateMsg(sendInfo)
  1065. return
  1066. }
  1067. // 给销售发送 开启或禁用"添加客户/领取客户"权限的通知
  1068. func SendCompanyReceivePermissionWxTemplateMsg(sellerMobile string, enabled int) (err error) {
  1069. var msg string
  1070. defer func() {
  1071. if err != nil {
  1072. fmt.Println("err:", err)
  1073. go alarm_msg.SendAlarmMsg("发送模版消息失败,Err:"+err.Error()+";msg:"+msg, 3)
  1074. utils.FileLog.Info(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg))
  1075. }
  1076. if msg != "" {
  1077. utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
  1078. }
  1079. }()
  1080. utils.FileLog.Info("%s", "services SendMsg")
  1081. //accessToken, err := models.GetWxAccessToken()
  1082. //if err != nil {
  1083. // msg = "GetWxAccessToken Err:" + err.Error()
  1084. // return
  1085. //}
  1086. //if accessToken == "" {
  1087. // msg = "accessToken is empty"
  1088. // return
  1089. //}
  1090. utils.FileLog.Info("mobile:%s", sellerMobile)
  1091. openIdList, err := system.GetAdminOpenIdListByMobile(sellerMobile)
  1092. if err != nil {
  1093. msg = "get openIdList err:" + err.Error()
  1094. return
  1095. }
  1096. utils.FileLog.Info("openIdListCount:%s", len(openIdList))
  1097. redirectUrl := ""
  1098. if len(openIdList) > 0 && utils.TemplateIdByCompanyApply != "" {
  1099. utils.FileLog.Info("start send")
  1100. //sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
  1101. fmt.Println("send start")
  1102. utils.FileLog.Info("send start")
  1103. //sendMap := make(map[string]interface{})
  1104. //sendData := make(map[string]interface{})
  1105. enabledStr := ""
  1106. if enabled >= 1 {
  1107. enabledStr = "已开启"
  1108. } else {
  1109. enabledStr = "已关闭"
  1110. }
  1111. first := "权限变更通知"
  1112. keyword1 := fmt.Sprint("添加/领取客户权限", enabledStr)
  1113. keyword2 := enabledStr + `(有疑问请联系管理员)`
  1114. remark := "如有疑问请联系ficc/权益管理员"
  1115. //sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
  1116. //sendData["keyword1"] = map[string]interface{}{"value": keyword1, "color": "#173177"}
  1117. //sendData["keyword2"] = map[string]interface{}{"value": keyword2, "color": "#173177"}
  1118. //sendData["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
  1119. //sendMap["template_id"] = utils.TemplateIdByCompanyReceivePermission
  1120. //sendMap["url"] = redirectUrl //跳转地址
  1121. //sendMap["data"] = sendData
  1122. //sendTemplateMsg(sendUrl, sendMap, openIdList, sellerMobile, utils.TEMPLATE_MSG_RECEIVE_PERMISSION)
  1123. openIdArr := make([]string, len(openIdList))
  1124. for i, v := range openIdList {
  1125. openIdArr[i] = v.OpenId
  1126. }
  1127. sendInfo := new(SendWxTemplate)
  1128. sendInfo.WxAppId = utils.AdminWxAppId
  1129. sendInfo.First = first
  1130. sendInfo.Keyword1 = keyword1
  1131. sendInfo.Keyword2 = keyword2
  1132. sendInfo.Remark = remark
  1133. sendInfo.RedirectUrl = redirectUrl
  1134. sendInfo.TemplateId = utils.TemplateIdByCompanyReceivePermission
  1135. sendInfo.RedirectTarget = 0
  1136. sendInfo.Resource = sellerMobile
  1137. sendInfo.SendType = utils.TEMPLATE_MSG_RECEIVE_PERMISSION
  1138. sendInfo.OpenIdArr = openIdArr
  1139. err = SendTemplateMsg(sendInfo)
  1140. }
  1141. utils.FileLog.Info("send end")
  1142. return
  1143. }
  1144. // SendYbPriceDrivenWxMsg 推送研报小程序价格驱动模板消息
  1145. func SendYbPriceDrivenWxMsg(varietyTagId int, title, publishTime string) (err error) {
  1146. var msg string
  1147. defer func() {
  1148. if err != nil {
  1149. errMsg := "SendYbPriceDrivenWxMsg 发送报告模版消息失败; Err: " + err.Error() + "; Msg: " + msg
  1150. utils.FileLog.Info("%s", errMsg)
  1151. go alarm_msg.SendAlarmMsg(errMsg, 3)
  1152. }
  1153. }()
  1154. // 标签
  1155. if varietyTagId <= 0 {
  1156. return
  1157. }
  1158. varietyTag, err := models.GetVarietyTagById(varietyTagId)
  1159. if err != nil {
  1160. msg = "GetVarietyTagById Err:" + err.Error()
  1161. return
  1162. }
  1163. //accessToken, err := models.GetWxAccessToken()
  1164. //if err != nil {
  1165. // msg = "GetWxAccessToken Err:" + err.Error()
  1166. // return
  1167. //}
  1168. //if accessToken == "" {
  1169. // msg = "accessToken is empty"
  1170. // return
  1171. //}
  1172. openIdList, err := models.GetOpenIdList()
  1173. if err != nil {
  1174. msg = "get openIdList err:" + err.Error()
  1175. return
  1176. }
  1177. utils.FileLog.Info("send start")
  1178. //sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
  1179. //sendMap := make(map[string]interface{})
  1180. //sendData := make(map[string]interface{})
  1181. first := "Hi,最新一期价格驱动已上线,欢迎查看"
  1182. keyword1 := fmt.Sprintf("%s价格驱动", varietyTag.ChartPermissionName)
  1183. keyword2 := title
  1184. keyword3 := publishTime
  1185. keyword4 := ""
  1186. //sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
  1187. //sendData["keyword1"] = map[string]interface{}{"value": keyword1, "color": "#173177"}
  1188. //sendData["keyword2"] = map[string]interface{}{"value": keyword2, "color": "#173177"}
  1189. //sendData["keyword3"] = map[string]interface{}{"value": keyword3, "color": "#173177"}
  1190. //sendData["keyword4"] = map[string]interface{}{"value": keyword4, "color": "#173177"}
  1191. //sendMap["template_id"] = utils.TemplateIdByProduct
  1192. //sendMap["data"] = sendData
  1193. wxAppPath := fmt.Sprintf("pages/pricedriven/pricedriven?default_classify_first=%d&default_classify_sub=%d", varietyTag.VarietyClassifyId, varietyTag.VarietyTagId)
  1194. if utils.RunMode == "debug" {
  1195. wxAppPath = "pages-report/chapterList?reportId=3800"
  1196. }
  1197. //if wxAppPath != "" {
  1198. // sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxYbAppId, "pagepath": wxAppPath}
  1199. //}
  1200. //err = sendTemplateMsg(sendUrl, sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_PRICE_DRIVEN)
  1201. openIdArr := make([]string, len(openIdList))
  1202. for i, v := range openIdList {
  1203. openIdArr[i] = v.OpenId
  1204. }
  1205. sendInfo := new(SendWxTemplate)
  1206. sendInfo.First = first
  1207. sendInfo.Keyword1 = keyword1
  1208. sendInfo.Keyword2 = keyword2
  1209. sendInfo.Keyword3 = keyword3
  1210. sendInfo.Keyword4 = keyword4
  1211. sendInfo.RedirectUrl = wxAppPath
  1212. sendInfo.TemplateId = utils.TemplateIdByProduct
  1213. sendInfo.RedirectTarget = 1
  1214. sendInfo.Resource = wxAppPath
  1215. sendInfo.SendType = utils.TEMPLATE_MSG_YB_PRICE_DRIVEN
  1216. sendInfo.OpenIdArr = openIdArr
  1217. err = SendTemplateMsg(sendInfo)
  1218. return
  1219. }
  1220. // 给销售发送 用印申请已签回的模版消息
  1221. func SendSealFinishedWxTemplateMsg(sellerMobile string, companyName string, sealId int) (err error) {
  1222. var msg string
  1223. defer func() {
  1224. if err != nil {
  1225. fmt.Println("err:", err)
  1226. go alarm_msg.SendAlarmMsg("发送模版消息失败,Err:"+err.Error()+";msg:"+msg, 3)
  1227. utils.FileLog.Info(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg))
  1228. }
  1229. if msg != "" {
  1230. utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
  1231. }
  1232. }()
  1233. utils.FileLog.Info("%s", "services SendMsg")
  1234. //accessToken, err := models.GetWxAccessToken()
  1235. //if err != nil {
  1236. // msg = "GetWxAccessToken Err:" + err.Error()
  1237. // return
  1238. //}
  1239. //if accessToken == "" {
  1240. // msg = "accessToken is empty"
  1241. // return
  1242. //}
  1243. utils.FileLog.Info("mobile:%s", sellerMobile)
  1244. openIdList, err := system.GetAdminOpenIdListByMobile(sellerMobile)
  1245. if err != nil {
  1246. msg = "get openIdList err:" + err.Error()
  1247. return
  1248. }
  1249. utils.FileLog.Info("openIdListCount:%s", len(openIdList))
  1250. if len(openIdList) > 0 && utils.WxMsgTemplateIdWithSealApplyFinished != "" {
  1251. utils.FileLog.Info("start send")
  1252. //sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
  1253. fmt.Println("send start")
  1254. utils.FileLog.Info("send start")
  1255. //sendMap := make(map[string]interface{})
  1256. //sendData := make(map[string]interface{})
  1257. first := "您的用印申请已签回,可前往提交转正/续约申请"
  1258. keyword1 := companyName
  1259. //keyword2 := "已签回"
  1260. keyword2 := "用印申请已签回,可前往提交转正/续约申请"
  1261. remark := "点击查看用印详情"
  1262. //sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
  1263. //sendData["keyword1"] = map[string]interface{}{"value": keyword1, "color": "#173177"}
  1264. //sendData["keyword2"] = map[string]interface{}{"value": keyword2, "color": "#173177"}
  1265. //sendData["remark"] = map[string]interface{}{"value": remark, "color": "#173177"}
  1266. //sendMap["template_id"] = utils.WxMsgTemplateIdWithSealApplyFinished
  1267. //sendMap["url"] = "" //跳转地址
  1268. //sendMap["data"] = sendData
  1269. // 随手办公小程序的跳转地址
  1270. wxAppPath := fmt.Sprintf("pages-approve/seal/detail?SealId=%d", sealId)
  1271. //sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxCrmAppId, "pagepath": wxAppPath}
  1272. //err = sendTemplateMsg(sendUrl, sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_SEAL_FINISHED)
  1273. openIdArr := make([]string, len(openIdList))
  1274. for i, v := range openIdList {
  1275. openIdArr[i] = v.OpenId
  1276. }
  1277. sendInfo := new(SendWxTemplate)
  1278. sendInfo.WxAppId = utils.AdminWxAppId
  1279. sendInfo.First = first
  1280. sendInfo.Keyword1 = keyword1
  1281. sendInfo.Keyword2 = keyword2
  1282. sendInfo.Remark = remark
  1283. sendInfo.RedirectUrl = wxAppPath
  1284. sendInfo.TemplateId = utils.WxMsgTemplateIdWithSealApplyFinished
  1285. sendInfo.RedirectTarget = 2
  1286. sendInfo.Resource = wxAppPath
  1287. sendInfo.SendType = utils.TEMPLATE_MSG_SEAL_FINISHED
  1288. sendInfo.OpenIdArr = openIdArr
  1289. err = SendTemplateMsg(sendInfo)
  1290. }
  1291. utils.FileLog.Info("send end")
  1292. return
  1293. }
  1294. // SendYbCommunityVideoWxMsg 推送研报小程序视频社区模板消息
  1295. func SendYbCommunityVideoWxMsg(videoId int, varietyTagName, title, publishTime string) (err error) {
  1296. var msg string
  1297. defer func() {
  1298. if err != nil {
  1299. errMsg := "SendYbCommunityVideoWxMsg 发送视频社区模版消息失败; Err: " + err.Error() + "; Msg: " + msg
  1300. utils.FileLog.Info("%s", errMsg)
  1301. go alarm_msg.SendAlarmMsg(errMsg, 3)
  1302. }
  1303. }()
  1304. //accessToken, err := models.GetWxAccessToken()
  1305. //if err != nil {
  1306. // msg = "GetWxAccessToken Err:" + err.Error()
  1307. // return
  1308. //}
  1309. //if accessToken == "" {
  1310. // msg = "accessToken is empty"
  1311. // return
  1312. //}
  1313. openIdList, err := models.GetOpenIdList()
  1314. if err != nil {
  1315. msg = "get openIdList err:" + err.Error()
  1316. return
  1317. }
  1318. utils.FileLog.Info("send start")
  1319. //sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
  1320. //sendMap := make(map[string]interface{})
  1321. //sendData := make(map[string]interface{})
  1322. first := "Hi,最新一期视频已发布,欢迎查看"
  1323. keyword1 := fmt.Sprintf("%s小视频", varietyTagName)
  1324. keyword2 := title
  1325. keyword3 := publishTime
  1326. keyword4 := ""
  1327. //sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
  1328. //sendData["keyword1"] = map[string]interface{}{"value": keyword1, "color": "#173177"}
  1329. //sendData["keyword2"] = map[string]interface{}{"value": keyword2, "color": "#173177"}
  1330. //sendData["keyword3"] = map[string]interface{}{"value": keyword3, "color": "#173177"}
  1331. //sendData["keyword4"] = map[string]interface{}{"value": keyword4, "color": "#173177"}
  1332. //sendMap["template_id"] = utils.TemplateIdByProduct
  1333. //sendMap["data"] = sendData
  1334. if utils.RunMode == "debug" {
  1335. videoId = 1
  1336. }
  1337. wxAppPath := fmt.Sprint(`/pages/video/videoList?videoId=`, videoId)
  1338. //if wxAppPath != "" {
  1339. // sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxYbAppId, "pagepath": wxAppPath}
  1340. //}
  1341. //err = sendTemplateMsg(sendUrl, sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_COMMUNITY_VIDEO)
  1342. openIdArr := make([]string, len(openIdList))
  1343. for i, v := range openIdList {
  1344. openIdArr[i] = v.OpenId
  1345. }
  1346. sendInfo := new(SendWxTemplate)
  1347. sendInfo.First = first
  1348. sendInfo.Keyword1 = keyword1
  1349. sendInfo.Keyword2 = keyword2
  1350. sendInfo.Keyword3 = keyword3
  1351. sendInfo.Keyword4 = keyword4
  1352. sendInfo.RedirectUrl = wxAppPath
  1353. sendInfo.TemplateId = utils.UserTemplateIdByProduct
  1354. sendInfo.RedirectTarget = 1
  1355. sendInfo.Resource = wxAppPath
  1356. sendInfo.SendType = utils.TEMPLATE_MSG_YB_COMMUNITY_VIDEO
  1357. sendInfo.OpenIdArr = openIdArr
  1358. err = SendTemplateMsg(sendInfo)
  1359. return
  1360. }
  1361. // SendYbRoadVideoWxMsg 推送研报小程序线上路演模板消息
  1362. func SendYbRoadVideoWxMsg(videoId int, title, publishTime, chartPermissionIds string) (err error) {
  1363. var msg string
  1364. defer func() {
  1365. if err != nil {
  1366. errMsg := "SendYbRoadVideoWxMsg 推送研报小程序线上路演模板消息; Err: " + err.Error() + "; Msg: " + msg
  1367. utils.FileLog.Info("%s", errMsg)
  1368. go alarm_msg.SendAlarmMsg(errMsg, 3)
  1369. }
  1370. }()
  1371. if chartPermissionIds == "" {
  1372. msg = "权限id为空,不可发送模板消息,videoId:" + strconv.Itoa(videoId)
  1373. return
  1374. }
  1375. chartPermissionNameList := make([]string, 0)
  1376. chartPermissionIdList := strings.Split(chartPermissionIds, ",")
  1377. tmpList, _ := models.GetChartPermissionByIds(chartPermissionIdList)
  1378. if len(tmpList) > 0 {
  1379. for _, v := range tmpList {
  1380. chartPermissionNameList = append(chartPermissionNameList, v.PermissionName)
  1381. }
  1382. }
  1383. openIdArr, err := models.GetOpenIdArrByChartPermissionIds(chartPermissionIds)
  1384. if err != nil {
  1385. msg = "get openIdList err:" + err.Error()
  1386. return
  1387. }
  1388. utils.FileLog.Info("send start")
  1389. first := "Hi,最新一期视频已发布,欢迎查看"
  1390. keyword1 := "线上路演"
  1391. keyword2 := title
  1392. keyword3 := publishTime
  1393. keyword4 := strings.Join(chartPermissionNameList, ",")
  1394. if utils.RunMode == "debug" {
  1395. videoId = 1
  1396. }
  1397. wxAppPath := fmt.Sprint(`/pages/roadShow/video/list?videoId=`, videoId)
  1398. //openIdArr := make([]string, len(openIdList))
  1399. //for i, v := range openIdList {
  1400. // openIdArr[i] = v.OpenId
  1401. //}bee r
  1402. sendInfo := new(SendWxTemplate)
  1403. sendInfo.First = first
  1404. sendInfo.Keyword1 = keyword1
  1405. sendInfo.Keyword2 = keyword2
  1406. sendInfo.Keyword3 = keyword3
  1407. sendInfo.Keyword4 = keyword4
  1408. sendInfo.RedirectUrl = wxAppPath
  1409. sendInfo.TemplateId = utils.UserTemplateIdByProduct
  1410. sendInfo.RedirectTarget = 1
  1411. sendInfo.Resource = wxAppPath
  1412. sendInfo.SendType = utils.TEMPLATE_MSG_YB_ROAD_VIDEO
  1413. sendInfo.OpenIdArr = openIdArr
  1414. err = SendTemplateMsg(sendInfo)
  1415. return
  1416. }
  1417. // 本周研究汇总,上周纪要汇总,报告精选
  1418. func SendWxMsgThisWeekLastWeek(first, keyword1, keyword2, keyword3, keyword4 string, openIdList []*models.OpenIdList, articleId, source int) (err error) {
  1419. var msg string
  1420. defer func() {
  1421. if err != nil {
  1422. fmt.Println("err:", err)
  1423. go alarm_msg.SendAlarmMsg("查研观向,本周研究汇总,上周纪要汇总,报告精选发送模版消息失败,Err:"+err.Error()+";msg:"+msg, 3)
  1424. utils.FileLog.Info(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg))
  1425. }
  1426. if msg != "" {
  1427. utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
  1428. }
  1429. }()
  1430. var redirectUrl string
  1431. if source == 1 {
  1432. redirectUrl = utils.WX_MSG_PATH_KEY_COMPANY_DETAIL + strconv.Itoa(articleId) + "&IsSendWx=1"
  1433. } else if source == 2 {
  1434. redirectUrl = utils.WX_MSG_PATH_THIS_WEEK_DETAIL + strconv.Itoa(articleId) + "&IsSendWx=1"
  1435. } else if source == 3 {
  1436. redirectUrl = utils.WX_MSG_PATH_LAST_WEEK_DETAIL + strconv.Itoa(articleId) + "&IsSendWx=1"
  1437. }
  1438. openIdArr := make([]string, len(openIdList))
  1439. for i, v := range openIdList {
  1440. openIdArr[i] = v.OpenId
  1441. }
  1442. sendInfo := new(SendWxTemplate)
  1443. //sendInfo.First = first
  1444. sendInfo.Keyword1 = keyword1
  1445. sendInfo.Keyword2 = keyword2
  1446. sendInfo.Keyword3 = keyword3
  1447. sendInfo.Keyword4 = keyword4
  1448. //sendInfo.Remark = remark
  1449. sendInfo.TemplateId = utils.TemplateIdByProductXzs
  1450. sendInfo.RedirectUrl = redirectUrl
  1451. sendInfo.RedirectTarget = 3
  1452. sendInfo.Resource = strconv.Itoa(articleId)
  1453. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE
  1454. sendInfo.OpenIdArr = openIdArr
  1455. err = SendTemplateMsg(sendInfo)
  1456. return
  1457. }
  1458. // 推送预约研选的纪要活动、策略报告、研选报告
  1459. func SendWxMsgWithCygxActivityAppointmentNew(first, keyword1, keyword2, keyword3, keyword4 string, item *cygx.OpenIdList, articleId int) (err error) {
  1460. var msg string
  1461. defer func() {
  1462. if err != nil {
  1463. fmt.Println("err:", err)
  1464. go alarm_msg.SendAlarmMsg("查研观向,推送预约研选的纪要活动、策略报告、研选报告,Err:"+err.Error()+";msg:"+msg, 3)
  1465. utils.FileLog.Info(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg))
  1466. }
  1467. if msg != "" {
  1468. utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
  1469. }
  1470. }()
  1471. //var accessToken string
  1472. //accessToken, err = models.GetWxAccessTokenByXzs()
  1473. //if err != nil {
  1474. // msg = "GetWxAccessToken Err:" + err.Error()
  1475. // return
  1476. //}
  1477. //if accessToken == "" {
  1478. // msg = "accessToken is empty"
  1479. // return
  1480. //}
  1481. var openIdList []*cygx.OpenIdList
  1482. openIdList = append(openIdList, item)
  1483. //sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
  1484. //sendMap := make(map[string]interface{})
  1485. //sendData := make(map[string]interface{})
  1486. //sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
  1487. //sendData["keyword1"] = map[string]interface{}{"value": keyword1, "color": "#173177"}
  1488. //sendData["keyword2"] = map[string]interface{}{"value": keyword2, "color": "#173177"}
  1489. //sendData["keyword3"] = map[string]interface{}{"value": keyword3, "color": "#173177"}
  1490. //sendData["keyword4"] = map[string]interface{}{"value": keyword4, "color": "#173177"}
  1491. //sendData["remark"] = map[string]interface{}{"value": "点击查看报告详情", "color": "#173177"}
  1492. //sendMap["template_id"] = utils.TemplateIdByProductXzs
  1493. //sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxCygxAppId, "pagepath": "pageMy/reportDetail/reportDetail?id=" + strconv.Itoa(articleId) + "&IsSendWx=1"}
  1494. //sendMap["data"] = sendData
  1495. //sendTemplateMsg(sendUrl, sendMap, openIdList, strconv.Itoa(articleId), utils.TEMPLATE_MSG_CYGX_ARTICLE)
  1496. openIdArr := make([]string, len(openIdList))
  1497. for i, v := range openIdList {
  1498. openIdArr[i] = v.OpenId
  1499. }
  1500. sendInfo := new(SendWxTemplate)
  1501. sendInfo.First = first
  1502. sendInfo.Keyword1 = keyword1
  1503. sendInfo.Keyword2 = keyword2
  1504. sendInfo.Keyword3 = keyword3
  1505. sendInfo.Keyword4 = keyword4
  1506. sendInfo.Remark = "点击查看报告详情"
  1507. sendInfo.TemplateId = utils.TemplateIdByProductXzs
  1508. sendInfo.RedirectUrl = utils.WX_MSG_PATH_ARTICLE_DETAIL + strconv.Itoa(articleId)
  1509. sendInfo.RedirectTarget = 3
  1510. sendInfo.Resource = strconv.Itoa(articleId)
  1511. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE
  1512. sendInfo.OpenIdArr = openIdArr
  1513. err = SendTemplateMsg(sendInfo)
  1514. return
  1515. }
  1516. type SendWxTemplate struct {
  1517. WxAppId string `description:"公众号appId"`
  1518. First string `description:"模板消息first字段"`
  1519. Keyword1 string `description:"模板消息keyword1字段"`
  1520. Keyword2 string `description:"模板消息keyword2字段"`
  1521. Keyword3 string `description:"模板消息keyword3字段"`
  1522. Keyword4 string `description:"模板消息keyword4字段"`
  1523. Keyword5 string `description:"模板消息keyword5字段"`
  1524. Remark string `description:"模板消息remark字段"`
  1525. TemplateId string `description:"模板id"`
  1526. RedirectUrl string `description:"跳转地址"`
  1527. RedirectTarget int `description:"小程序跳转目标:1:弘则研报小程序,2:随手办公小程序"`
  1528. Resource string `description:"资源唯一标识"`
  1529. SendType int `description:"发送的消息类型:1:报告,2:指标更新提醒,3:审批通知,4:销售领取客户通知,5:活动取消通知,6活动更改时间通知,7:关注的作者发布报告通知,8:发送日报(周报、双周报、月报)模板消息,9:活动预约/报名时间通知"`
  1530. OpenIdArr []string `description:"消息接收者openid"`
  1531. }
  1532. // 推送模板消息
  1533. func SendTemplateMsg(sendInfo *SendWxTemplate) (err error) {
  1534. postData, err := json.Marshal(sendInfo)
  1535. if err != nil {
  1536. alarm_msg.SendAlarmMsg("SendTemplateMsg json.Marshal Err:"+err.Error(), 1)
  1537. return err
  1538. }
  1539. body := ioutil.NopCloser(strings.NewReader(string(postData)))
  1540. client := &http.Client{}
  1541. req, err := http.NewRequest("POST", utils.SendWxTemplateMsgUrl, body)
  1542. if err != nil {
  1543. alarm_msg.SendAlarmMsg("SendTemplateMsg http.NewRequest Err:"+err.Error(), 1)
  1544. return err
  1545. }
  1546. contentType := "application/json;charset=utf-8"
  1547. req.Header.Set("Content-Type", contentType)
  1548. req.Header.Set("Authorization", utils.SendTemplateMsgAuthorization)
  1549. resp, err := client.Do(req)
  1550. if err != nil {
  1551. fmt.Println("http client.Do Err:" + err.Error())
  1552. return err
  1553. }
  1554. defer resp.Body.Close()
  1555. b, err := ioutil.ReadAll(resp.Body)
  1556. if err != nil {
  1557. return err
  1558. }
  1559. result := new(models.BaseResponse)
  1560. err = json.Unmarshal(b, &result)
  1561. if err != nil {
  1562. return err
  1563. }
  1564. if result.Ret != 200 {
  1565. err = errors.New(string(b))
  1566. return err
  1567. }
  1568. return
  1569. }
  1570. func SendWxMsgWithCygxMorningMeeting(meetingId, industryId int, industryName string) (err error) {
  1571. var msg string
  1572. defer func() {
  1573. if err != nil {
  1574. fmt.Println("err:", err)
  1575. go alarm_msg.SendAlarmMsg("查研观向推送晨会点评模板消息失败,Err:"+err.Error()+";msg:"+msg, 3)
  1576. utils.FileLog.Info(fmt.Sprintf("发送模版消息失败,Err:%s,%s", err.Error(), msg))
  1577. }
  1578. if msg != "" {
  1579. utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
  1580. }
  1581. }()
  1582. reviewInfo, err := cygx.GetMorningMeetingReviewById(meetingId)
  1583. if err != nil {
  1584. err = errors.New("获取晨会点评失败, Err: " + err.Error())
  1585. return
  1586. }
  1587. chapter, err := cygx.GetCygxMorningMeetingReviewsListByIdAndIndustryId(meetingId, industryId)
  1588. if err != nil {
  1589. err = errors.New("获取晨会点评章节失败, Err: " + err.Error())
  1590. return
  1591. }
  1592. meetingTime := reviewInfo.MeetingTime.Format(utils.FormatDate)
  1593. openIdList, err := models.GetCygxUserIndustryFllowOpneid(industryId)
  1594. openIdArr := make([]string, len(openIdList))
  1595. for i, v := range openIdList {
  1596. openIdArr[i] = v.OpenId
  1597. }
  1598. //保留回撤,去掉空行
  1599. content := strings.Replace(chapter.Content, "<br></p>", "", -1)
  1600. content = strings.Replace(content, "</p>", "\n", -1)
  1601. content, err = utils.GetReportContentTextSub(content)
  1602. if err != nil {
  1603. err = errors.New("获取晨会点评章节文本失败, Err: " + err.Error())
  1604. return
  1605. }
  1606. sendInfo := new(SendWxTemplate)
  1607. //sendInfo.First = "【" + industryName + "】产业,有新的跟踪点评"
  1608. sendInfo.Keyword1 = "【" + industryName + "】产业,有新的跟踪点评"
  1609. sendInfo.Keyword2 = content
  1610. sendInfo.Keyword3 = meetingTime
  1611. sendInfo.Remark = "点击进入小程序对应的产业资源包页面"
  1612. if utils.RunMode == "release" {
  1613. sendInfo.TemplateId = utils.TemplateIdByProductXzs
  1614. } else {
  1615. sendInfo.TemplateId = utils.TemplateIdByProductXzs
  1616. }
  1617. sendInfo.RedirectUrl = utils.WX_MSG_PATH_INDUSTRY_DETAIL + strconv.Itoa(industryId) + "&IsSendWx=1&ChapterId=" + strconv.Itoa(chapter.Id)
  1618. sendInfo.RedirectTarget = 3
  1619. sendInfo.Resource = strconv.Itoa(industryId)
  1620. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_MORNING_MEETING
  1621. sendInfo.OpenIdArr = openIdArr
  1622. err = SendTemplateMsg(sendInfo)
  1623. return
  1624. }
  1625. //func init() {
  1626. // fmt.Println("start send template msg")
  1627. // sendInfo := new(SendWxTemplate)
  1628. //
  1629. // openIdArr := make([]string, len(openIdList))
  1630. // keyword1 := "弘则日度点评"
  1631. // first := "Hi,最新一期日度点评已上线,欢迎查看"
  1632. // sendInfo.First = first
  1633. // sendInfo.Keyword1 = keyword1
  1634. // sendInfo.Keyword2 = "测试报告-模板消息推送"
  1635. // sendInfo.Keyword3 = time.Now().Format(utils.FormatDateTime)
  1636. // sendInfo.Keyword4 = "测试报告简介-模板消息推送"
  1637. // sendInfo.TemplateId = utils.TemplateIdByProduct
  1638. // sendInfo.RedirectUrl = "http://rddpweb.brilliantstart.cn/reportdtl?id=2441"
  1639. // sendInfo.Resource = "100"
  1640. // sendInfo.SendType = 1
  1641. //
  1642. // openIdArr = append(openIdArr, "oN0jD1eTfIAf68Y2n24RrvIGXFw4")
  1643. // sendInfo.OpenIdArr = openIdArr
  1644. // SendTemplateMsg(sendInfo)
  1645. // fmt.Println("end send template msg")
  1646. //}
  1647. func PublicsendTemplateMsg(sendUrl string, sendMap map[string]interface{}, items []*models.OpenIdList, resource string, sendType int) (err error) {
  1648. for _, v := range items {
  1649. sendMap["touser"] = v.OpenId
  1650. data, err := json.Marshal(sendMap)
  1651. if err != nil {
  1652. fmt.Println("SendTemplateMsgOne Marshal Err:", err.Error())
  1653. utils.FileLog.Info(fmt.Sprintf("SendTemplateMsgOne Marshal Err:%s", err.Error()))
  1654. return err
  1655. }
  1656. err = toSendTemplateMsg(sendUrl, data, resource, sendType, v)
  1657. if err != nil {
  1658. fmt.Println("send err:", err.Error())
  1659. utils.FileLog.Info(fmt.Sprintf("ToSendTemplateMsg Err:%s", err.Error()))
  1660. }
  1661. }
  1662. return
  1663. }
  1664. // SendYbCommunityVideoWxMsg 推送研报小程序视频社区模板消息
  1665. func SendYbCommunityVideoWxMsgV2(videoId, varietyTagId int, varietyTagName, title, publishTime string) (err error) {
  1666. var msg string
  1667. defer func() {
  1668. if err != nil {
  1669. errMsg := "SendYbCommunityVideoWxMsg 发送视频社区模版消息失败; Err: " + err.Error() + "; Msg: " + msg
  1670. utils.FileLog.Info("%s", errMsg)
  1671. go alarm_msg.SendAlarmMsg(errMsg, 3)
  1672. }
  1673. }()
  1674. //accessToken, err := models.GetWxAccessToken()
  1675. //if err != nil {
  1676. // msg = "GetWxAccessToken Err:" + err.Error()
  1677. // return
  1678. //}
  1679. //if accessToken == "" {
  1680. // msg = "accessToken is empty"
  1681. // return
  1682. //}
  1683. openIdList, err := models.GetOpenIdArrByVarietyTag(varietyTagId)
  1684. if err != nil {
  1685. msg = "get openIdList err:" + err.Error()
  1686. return
  1687. }
  1688. utils.FileLog.Info("send start")
  1689. //sendUrl := "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken
  1690. //sendMap := make(map[string]interface{})
  1691. //sendData := make(map[string]interface{})
  1692. first := "Hi,最新一期视频已发布,欢迎查看"
  1693. keyword1 := fmt.Sprintf("%s小视频", varietyTagName)
  1694. keyword2 := title
  1695. keyword3 := publishTime
  1696. keyword4 := ""
  1697. //sendData["first"] = map[string]interface{}{"value": first, "color": "#173177"}
  1698. //sendData["keyword1"] = map[string]interface{}{"value": keyword1, "color": "#173177"}
  1699. //sendData["keyword2"] = map[string]interface{}{"value": keyword2, "color": "#173177"}
  1700. //sendData["keyword3"] = map[string]interface{}{"value": keyword3, "color": "#173177"}
  1701. //sendData["keyword4"] = map[string]interface{}{"value": keyword4, "color": "#173177"}
  1702. //sendMap["template_id"] = utils.TemplateIdByProduct
  1703. //sendMap["data"] = sendData
  1704. if utils.RunMode == "debug" {
  1705. videoId = 1
  1706. }
  1707. wxAppPath := fmt.Sprint(`/pages/video/videoList?videoId=`, videoId)
  1708. //if wxAppPath != "" {
  1709. // sendMap["miniprogram"] = map[string]interface{}{"appid": utils.WxYbAppId, "pagepath": wxAppPath}
  1710. //}
  1711. //err = sendTemplateMsg(sendUrl, sendMap, openIdList, wxAppPath, utils.TEMPLATE_MSG_YB_COMMUNITY_VIDEO)
  1712. //openIdArr := make([]string, len(openIdList))
  1713. //for i, v := range openIdList {
  1714. // openIdArr[i] = v.OpenId
  1715. //}
  1716. sendInfo := new(SendWxTemplate)
  1717. sendInfo.First = first
  1718. sendInfo.Keyword1 = keyword1
  1719. sendInfo.Keyword2 = keyword2
  1720. sendInfo.Keyword3 = keyword3
  1721. sendInfo.Keyword4 = keyword4
  1722. sendInfo.RedirectUrl = wxAppPath
  1723. sendInfo.TemplateId = utils.UserTemplateIdByProduct
  1724. sendInfo.RedirectTarget = 1
  1725. sendInfo.Resource = wxAppPath
  1726. sendInfo.SendType = utils.TEMPLATE_MSG_YB_COMMUNITY_VIDEO
  1727. sendInfo.OpenIdArr = openIdList
  1728. err = SendTemplateMsg(sendInfo)
  1729. return
  1730. }
  1731. // SendWxMsgWithRaiSell 权益销售客户申请转正后,消息群发给所有销售
  1732. func SendWxMsgWithRaiSell(first, keyword1, keyword2, keyword3, keyword4 string, openIdList []*cygx.OpenIdList) (err error) {
  1733. var msg string
  1734. defer func() {
  1735. if err != nil {
  1736. fmt.Println("err:", err)
  1737. go alarm_msg.SendAlarmMsg("权益销售客户申请转正后,消息群发给所有销售,Err:"+err.Error()+";msg:"+msg, 3)
  1738. }
  1739. if msg != "" {
  1740. utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
  1741. }
  1742. }()
  1743. openIdArr := make([]string, len(openIdList))
  1744. for i, v := range openIdList {
  1745. openIdArr[i] = v.OpenId
  1746. }
  1747. sendInfo := new(SendWxTemplate)
  1748. sendInfo.First = first
  1749. sendInfo.Keyword1 = keyword1
  1750. sendInfo.Keyword2 = keyword2
  1751. sendInfo.Keyword3 = keyword3
  1752. sendInfo.Keyword4 = keyword4
  1753. sendInfo.Remark = ""
  1754. sendInfo.TemplateId = utils.WxMsgTemplateIdCompanyApprovalMessageRai
  1755. sendInfo.RedirectUrl = ""
  1756. sendInfo.RedirectTarget = 3
  1757. sendInfo.SendType = utils.TEMPLATE_MSG_APPLY
  1758. sendInfo.OpenIdArr = openIdArr
  1759. fmt.Println(sendInfo)
  1760. err = SendTemplateMsg(sendInfo)
  1761. return
  1762. }
  1763. // SendWxMsgWithRaiWangYang 客户研选行业转正时(王芳审批通过),模板消息提醒汪洋
  1764. func SendWxMsgWithRaiWangYang(keyword1, keyword2, keyword3, keyword4 string, openIdList []*cygx.OpenIdList) (err error) {
  1765. var msg string
  1766. defer func() {
  1767. if err != nil {
  1768. fmt.Println("err:", err)
  1769. go alarm_msg.SendAlarmMsg("客户研选行业转正时(王芳审批通过),模板消息提醒汪洋,Err:"+err.Error()+";msg:"+msg, 3)
  1770. }
  1771. if msg != "" {
  1772. utils.FileLog.Info("发送模版消息失败,msg:%s", msg)
  1773. }
  1774. }()
  1775. openIdArr := make([]string, len(openIdList))
  1776. for i, v := range openIdList {
  1777. openIdArr[i] = v.OpenId
  1778. }
  1779. sendInfo := new(SendWxTemplate)
  1780. sendInfo.Keyword1 = keyword1
  1781. sendInfo.Keyword2 = keyword2
  1782. sendInfo.Keyword3 = keyword3
  1783. sendInfo.Keyword4 = keyword4
  1784. sendInfo.TemplateId = utils.WxMsgTemplateIdCompanyApprovalMessageRai
  1785. sendInfo.RedirectUrl = ""
  1786. sendInfo.RedirectTarget = 3
  1787. sendInfo.SendType = utils.TEMPLATE_MSG_APPLY
  1788. sendInfo.OpenIdArr = openIdArr
  1789. err = SendTemplateMsg(sendInfo)
  1790. return
  1791. }