Forráskód Böngészése

模板消息自定义

wangchuanjin 4 éve
szülő
commit
abac8fe537

+ 14 - 1
src/jfw/modules/subscribepay/src/config/config.go

@@ -94,6 +94,7 @@ type messageConfig struct {
 	WxTpl_Expired            *WxTplMsg //已到期
 	WxTpl_Unpaid             *WxTplMsg //未支付订单
 	WxTpl_PaySuccess         *WxTplMsg //支付成功
+	WxTpl_DataReport         *WxTplMsg //数据报告
 }
 
 type WxTplMsg struct {
@@ -237,6 +238,13 @@ var WxPayConf map[string]interface{}
 
 var Wxoauth, Wxoauthinfo string
 var AutoMergeTimeStamp int64
+var (
+	WxTpl_OnTrial_SoonExpire_SceneCode string
+	WxTpl_OnTrial_Expired_SceneCode    string
+	WxTpl_SoonExpire_SceneCode         string
+	WxTpl_Expired_SceneCode            string
+	WxTpl_DataReport_SceneCode         string
+)
 
 func init() {
 	//程序配置文件
@@ -274,5 +282,10 @@ func init() {
 		panic(err)
 	}
 	AutoMergeTimeStamp = time.Unix()
-
+	//
+	WxTpl_OnTrial_SoonExpire_SceneCode = MessageConfig.WxTpl_OnTrial_SoonExpire.First.Value
+	WxTpl_OnTrial_Expired_SceneCode = MessageConfig.WxTpl_OnTrial_Expired.First.Value
+	WxTpl_SoonExpire_SceneCode = MessageConfig.WxTpl_SoonExpire.First.Value
+	WxTpl_Expired_SceneCode = MessageConfig.WxTpl_Expired.First.Value
+	WxTpl_DataReport_SceneCode = MessageConfig.WxTpl_DataReport.First.Value
 }

+ 5 - 1
src/jfw/modules/subscribepay/src/entity/dataReportStruct.go

@@ -170,9 +170,13 @@ func sendtemp(openid, order_coded, product_type, pay_time string) {
 	if openid == "" || order_coded == "" || product_type == "" || pay_time == "" {
 		fmt.Println("数据报告模板参数异常")
 	} else {
+		wxTplMsgErr := (&util.WxTplMsgCustom{}).DataReport()
+		if wxTplMsgErr != nil {
+			log.Println(wxTplMsgErr)
+		}
 		ok, status := frpc.WxPush(config.Config.Weixinrpc, "WeiXinRpc.SendDataReportMsg", &frpc.NotifyMsg{
 			Openid:  openid,
-			Title:   "尊敬的客户,您的订单已支付成功",
+			Title:   config.MessageConfig.WxTpl_DataReport.First.Value,
 			Detail:  product_type, //产品类型
 			Service: order_coded,  //订单编号
 			Date:    pay_time,     //支付时间

+ 9 - 3
src/jfw/modules/subscribepay/src/main.go

@@ -11,13 +11,20 @@ import (
 	"rpcfollow"
 	_ "service"
 	"timetask"
-	_ "util"
+	"util"
 
 	"github.com/go-xweb/xweb"
 )
 
 func main() {
-
+	wxTplMsgExpiredErr := (&util.WxTplMsgCustom{}).Expired()
+	if wxTplMsgExpiredErr != nil {
+		log.Fatalln(wxTplMsgExpiredErr)
+	}
+	wxTplMsgDataReportErr := (&util.WxTplMsgCustom{}).DataReport()
+	if wxTplMsgDataReportErr != nil {
+		log.Fatalln(wxTplMsgDataReportErr)
+	}
 	go func() {
 		frpc := new(rpcfollow.JyPayRpc)
 		rpc.Register(frpc)
@@ -31,7 +38,6 @@ func main() {
 			log.Println("ListenAndServe: ", err)
 		}
 	}()
-
 	go timetask.Run()
 	mux1 := http.NewServeMux()
 	xweb.RunBase(":"+Config.Webport, mux1)

+ 10 - 4
src/jfw/modules/subscribepay/src/message.json

@@ -2,7 +2,7 @@
 	"WxTpl_OnTrial_SoonExpire": {
 		"id": "_2qGuk_KkOQtiO8oV_7ZOCWfjX2FQjs6pUDYBHkpygI",
 		"first":{
-			"value":"您试用的超级订阅服务即将到期,如需获取更多精准招标信息,请及时购买。",
+			"value":"001",
 			"color":"#FE737A"
 		},
 		"remark": {
@@ -12,7 +12,7 @@
 	"WxTpl_OnTrial_Expired": {
 		"id": "_2qGuk_KkOQtiO8oV_7ZOCWfjX2FQjs6pUDYBHkpygI",
 		"first":{
-			"value":"您试用的超级订阅服务已到期,如需获取更多精准招标信息,请及时购买。",
+			"value":"002",
 			"color":"#FE737A"
 		},
 		"remark": {
@@ -22,7 +22,7 @@
 	"WxTpl_SoonExpire": {
 		"id": "3_VPNbD7fmfd8BsdjLW-a7FOP4wIhEGV7Jx-11-9c7g",
 		"first":{
-			"value":"超级订阅服务即将到期,请及时续费",
+			"value":"001",
 			"color":"#FE737A"
 		},
 		"keyword2": {
@@ -38,7 +38,7 @@
 	"WxTpl_Expired": {
 		"id": "3_VPNbD7fmfd8BsdjLW-a7FOP4wIhEGV7Jx-11-9c7g",
 		"first":{
-			"value":"超级订阅服务已到期,点击续费",
+			"value":"002",
 			"color":"#FE737A"
 		},
 		"keyword2": {
@@ -95,5 +95,11 @@
 		"keyword1": {
 			"value":"超级订阅%s"
 		}
+	},
+	"WxTpl_DataReport": {
+		"id": "1p3eqXz28HNlIJxhLoWl8zP7y0l8ZGd8YTsLvTq2J28",
+		"first":{
+			"value":"001"
+		}
 	}
 }

+ 5 - 1
src/jfw/modules/subscribepay/src/timetask/timetask.go

@@ -269,6 +269,10 @@ func expireRemind() {
 	crontab(false, TimeTaskConfig.ExpireRemind, func() {
 		defer qutil.Catch()
 		log.Println("定时任务,到期提醒,开始推送消息")
+		wxTplMsgErr := (&util.WxTplMsgCustom{}).Expired()
+		if wxTplMsgErr != nil {
+			log.Println(wxTplMsgErr)
+		}
 		sess := util.MQFW.GetMgoConn()
 		for {
 			if sess != nil {
@@ -354,7 +358,7 @@ func expireRemind() {
 				keyword4_value = qutil.FormatDateByInt64(&l_vip_endtime, qutil.Date_Short_Layout)
 				break
 			}
-			if isPushWx == 1 && s_m_openid != "" { //微信推送
+			if isPushWx == 1 && s_m_openid != "" && first_value != "" { //微信推送
 				tmplData := map[string]*qrpc.TmplItem{
 					"first": &qrpc.TmplItem{
 						Value: first_value,

+ 97 - 0
src/jfw/modules/subscribepay/src/util/wxtplmsgcustom.go

@@ -0,0 +1,97 @@
+package util
+
+import (
+	. "config"
+	"errors"
+	"log"
+	. "qfw/util/rpc"
+	"strings"
+)
+
+type WxTplMsgCustom struct {
+}
+
+/* 获取自定义模板消息
+ * @Param mysql 数据库实例
+ * @Param tplId 模板消息id
+ * @Param sceneCode 场景代码
+ */
+func (w *WxTplMsgCustom) Get(tplId string, sceneCode ...string) map[string]*TmplItem {
+	param := []interface{}{tplId}
+	wh := []string{}
+	for _, v := range sceneCode {
+		param = append(param, v)
+		wh = append(wh, "?")
+	}
+	list := Mysql.SelectBySql(`select firstdata,sceneCode from scene a 
+	inner join template_message b on (a.templateId=b.id and b.id=? and a.sceneCode in (`+strings.Join(wh, ",")+`) and a.state=1 and b.isTest=1)`, param...)
+	m := map[string]*TmplItem{}
+	if list != nil {
+		for _, v := range *list {
+			sceneCode, _ := v["sceneCode"].(string)
+			sceneCode = strings.TrimSpace(sceneCode)
+			//
+			firstdata, _ := v["firstdata"].(string)
+			firstdata = strings.TrimSpace(firstdata)
+			//
+			m[sceneCode] = &TmplItem{
+				Value: firstdata,
+			}
+		}
+	}
+	return m
+}
+
+//超级订阅试用即将到期、超级订阅试用已到期、超级订阅即将到期、超级订阅已到期
+func (w *WxTplMsgCustom) Expired() error {
+	//试用-微信模板消息自定义
+	onTrial_WxTplMsg := w.Get(MessageConfig.WxTpl_OnTrial_SoonExpire.Id, WxTpl_OnTrial_SoonExpire_SceneCode, WxTpl_OnTrial_Expired_SceneCode)
+	//试用-即将到期
+	if onTrial_WxTplMsg[WxTpl_OnTrial_SoonExpire_SceneCode] == nil {
+		return errors.New("试用-即将到期,没有找到微信模板消息")
+	} else if onTrial_WxTplMsg[WxTpl_OnTrial_SoonExpire_SceneCode].Value == "" {
+		return errors.New("试用-即将到期,微信模板消息first_data为空")
+	}
+	MessageConfig.WxTpl_OnTrial_SoonExpire.First.Value = onTrial_WxTplMsg[WxTpl_OnTrial_SoonExpire_SceneCode].Value
+	log.Println("试用-即将到期,微信模板消息first_data", onTrial_WxTplMsg[WxTpl_OnTrial_SoonExpire_SceneCode].Value)
+	//试用-已到期
+	if onTrial_WxTplMsg[WxTpl_OnTrial_Expired_SceneCode] == nil {
+		return errors.New("试用-已到期,没有找到微信模板消息")
+	} else if onTrial_WxTplMsg[WxTpl_OnTrial_Expired_SceneCode].Value == "" {
+		return errors.New("试用-已到期,微信模板消息first_data为空")
+	}
+	MessageConfig.WxTpl_OnTrial_Expired.First.Value = onTrial_WxTplMsg[WxTpl_OnTrial_Expired_SceneCode].Value
+	log.Println("试用-已到期,微信模板消息first_data", onTrial_WxTplMsg[WxTpl_OnTrial_Expired_SceneCode].Value)
+	//购买-微信模板消息自定义
+	wxTplMsg := w.Get(MessageConfig.WxTpl_Expired.Id, WxTpl_SoonExpire_SceneCode, WxTpl_Expired_SceneCode)
+	//即将到期
+	if wxTplMsg[WxTpl_SoonExpire_SceneCode] == nil {
+		return errors.New("即将到期,没有找到微信模板消息")
+	} else if wxTplMsg[WxTpl_SoonExpire_SceneCode].Value == "" {
+		return errors.New("即将到期,微信模板消息first_data为空")
+	}
+	MessageConfig.WxTpl_SoonExpire.First.Value = wxTplMsg[WxTpl_SoonExpire_SceneCode].Value
+	log.Println("即将到期,微信模板消息first_data", wxTplMsg[WxTpl_SoonExpire_SceneCode].Value)
+	//已到期
+	if wxTplMsg[WxTpl_Expired_SceneCode] == nil {
+		return errors.New("已到期,没有找到微信模板消息")
+	} else if wxTplMsg[WxTpl_Expired_SceneCode].Value == "" {
+		return errors.New("已到期,微信模板消息first_data为空")
+	}
+	MessageConfig.WxTpl_Expired.First.Value = wxTplMsg[WxTpl_Expired_SceneCode].Value
+	log.Println("已到期,微信模板消息first_data", wxTplMsg[WxTpl_Expired_SceneCode].Value)
+	return nil
+}
+
+//数据报告
+func (w *WxTplMsgCustom) DataReport() error {
+	wxTplMsg := w.Get(MessageConfig.WxTpl_DataReport.Id, WxTpl_DataReport_SceneCode)
+	if wxTplMsg[WxTpl_DataReport_SceneCode] == nil {
+		return errors.New("数据报告,没有找到微信模板消息")
+	} else if wxTplMsg[WxTpl_DataReport_SceneCode].Value == "" {
+		return errors.New("数据报告,微信模板消息first_data为空")
+	}
+	MessageConfig.WxTpl_DataReport.First.Value = wxTplMsg[WxTpl_DataReport_SceneCode].Value
+	log.Println("微信模板消息first_data", wxTplMsg[WxTpl_DataReport_SceneCode].Value)
+	return nil
+}