Răsfoiți Sursa

wip:营销模板

wangshan 1 an în urmă
părinte
comite
ee286fe274
12 a modificat fișierele cu 138 adăugiri și 49 ștergeri
  1. 19 0
      .gitignore
  2. 8 0
      .idea/.gitignore
  3. 9 0
      .idea/Sms_Service.iml
  4. 8 0
      .idea/modules.xml
  5. 6 0
      .idea/vcs.xml
  6. BIN
      src/Sms_Service
  7. 17 3
      src/config.json
  8. 7 0
      src/config/config.go
  9. 0 31
      src/logs/sms.log
  10. 19 4
      src/main.go
  11. 45 11
      src/service/weiwangtonglian.go
  12. BIN
      src/sms.exe

+ 19 - 0
.gitignore

@@ -0,0 +1,19 @@
+.buildpath
+.hgignore.swp
+.project
+.orig
+.swp
+.idea/
+.settings/
+.vscode/
+bin/
+**/.DS_Store
+gf
+main
+main.exe
+output/
+manifest/output/
+temp/
+temp.yaml
+bin
+*.exe

+ 8 - 0
.idea/.gitignore

@@ -0,0 +1,8 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml

+ 9 - 0
.idea/Sms_Service.iml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="WEB_MODULE" version="4">
+  <component name="Go" enabled="true" />
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$" />
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/Sms_Service.iml" filepath="$PROJECT_DIR$/.idea/Sms_Service.iml" />
+    </modules>
+  </component>
+</project>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

BIN
src/Sms_Service


+ 17 - 3
src/config.json

@@ -1,4 +1,5 @@
 {
+	"webPort":"9321",
 	"port":"932",
 	"model":1,
 	"reTry":3,
@@ -10,8 +11,21 @@
 		"productId":1012888,
 		"fixEncryptKey":"SMmsEncryptKey",
 		"idToTpl":{
-			"01":134220
-		}
+			"01":134220,
+			"02":139702,
+			"03":149347,
+			"04":150559
+		},
+		"productMark": "jy@wz",
+		"productInfo": [
+			{
+				"productId": 1012812,
+				"templateCodes": [
+					154902,
+					154903
+				]
+			}
+		]
 	},
 	"yunpian":{
 		"url":"https://sms.yunpian.com/v2/sms/tpl_batch_send.json",
@@ -24,4 +38,4 @@
 		}
 	},
 	"warn":"http://172.17.4.195:19281/_send/_mail?program=Sms_Service&to=wangchuanjin@topnet.net.cn,renzheng@topnet.net.cn,zhaoyujian@topnet.net.cn&title=短信服务程序报警&body=%s"
-}
+}

+ 7 - 0
src/config/config.go

@@ -7,6 +7,7 @@ import (
 var Config *config
 
 type config struct {
+	WebPort         string
 	Port            string
 	Model           int
 	ReTry           int
@@ -18,6 +19,8 @@ type config struct {
 		ProductId     int
 		FixEncryptKey string
 		IdToTpl       map[string]int
+		ProductMark   string
+		ProductInfo   []productInfo
 	}
 	Yunpian struct {
 		Url     string
@@ -29,6 +32,10 @@ type config struct {
 	}
 	Warn string
 }
+type productInfo struct {
+	ProductId     int   `json:"productId"`
+	TemplateCodes []int `json:"templateCodes"`
+}
 
 func init() {
 	common.ReadConfig(&Config)

+ 0 - 31
src/logs/sms.log

@@ -1,31 +0,0 @@
-2022/03/16 10:46:38 main.go:112: info  返回值: {"Result":"1052","Reason":"无效计费条数,号码不规则过滤[1:150378707650,]","MsgId":0,"SplitCount":0}
-2022/03/16 10:46:38 main.go:120: info  1052 无效计费条数,号码不规则过滤[1:150378707650,]  0
-2022/03/16 10:49:12 main.go:84: info  req data: &{Id:01 Phones:150378707650 Params:[123456]}
-2022/03/16 10:56:34 main.go:84: info  req data: &{Id:01 Phones:150378707650 Params:[123456]}
-2022/03/16 10:57:09 main.go:84: info  req data: &{Id:01 Phones:150378707650 Params:[123456]}
-2022/03/16 10:57:10 main.go:114: info  返回值: {"Result":"1052","Reason":"无效计费条数,号码不规则过滤[1:150378707650,]","MsgId":0,"SplitCount":0}
-2022/03/16 10:57:10 main.go:122: info  1052 无效计费条数,号码不规则过滤[1:150378707650,]  0
-2022/03/16 11:08:06 main.go:125: info  req data: &{Id:01 Phones:150378707650 Params:[123456]}
-2022/03/16 11:08:07 main.go:155: info  返回值: {"Result":"1052","Reason":"无效计费条数,号码不规则过滤[1:150378707650,]","MsgId":0,"SplitCount":0}
-2022/03/16 11:08:07 main.go:163: info  1052 无效计费条数,号码不规则过滤[1:150378707650,]  0
-2022/03/16 11:09:15 main.go:125: info  req data: &{Id:01 Phones:150378707650 Params:[123456]}
-2022/03/16 11:09:15 main.go:155: info  返回值: {"Result":"1052","Reason":"无效计费条数,号码不规则过滤[1:150378707650,]","MsgId":0,"SplitCount":0}
-2022/03/16 11:09:15 main.go:163: info  1052 无效计费条数,号码不规则过滤[1:150378707650,]  0
-2022/03/16 11:23:22 main.go:123: info  req data: &{Id:01 Phones:150378707650 Params:[123456]}
-2022/03/16 11:23:22 main.go:153: info  返回值: {"Result":"1052","Reason":"无效计费条数,号码不规则过滤[1:150378707650,]","MsgId":0,"SplitCount":0}
-2022/03/16 11:23:22 main.go:161: info  1052 无效计费条数,号码不规则过滤[1:150378707650,]  0
-2022/03/16 13:17:24 main.go:84: info  req data: &{Id:01 Phones:150378707650 Params:[123456]}
-2022/03/16 13:18:57 main.go:84: info  req data: &{Id:01 Phones:150378707650 Params:[2]}
-2022/03/16 13:18:58 main.go:114: info  返回值: {"Result":"1052","Reason":"无效计费条数,号码不规则过滤[1:150378707650,]","MsgId":0,"SplitCount":0}
-2022/03/16 13:18:58 main.go:122: info  1052 无效计费条数,号码不规则过滤[1:150378707650,]  0
-2022/03/16 13:20:21 main.go:84: info  req data: &{Id:01 Phones:15037870765 Params:[5]}
-2022/03/16 13:20:21 main.go:114: info  返回值: {"Result":"succ","Reason":"提交成功","MsgId":2203161320217202597,"SplitCount":1}
-2022/03/16 13:20:21 main.go:122: info  succ 提交成功  1
-2022/03/17 13:29:21 main.go:64: info  req data: &{Id:01 Phones:15037870765 Params:[4]}
-2022/03/17 13:29:21 service.go:37: info  微网通联 返回值: {"Result":"succ","Reason":"提交成功","MsgId":2203171329210092797,"SplitCount":1}
-2022/03/17 13:33:14 main.go:64: info  req data: &{Id:01 Phones:15037870765 Params:[133314]}
-2022/03/17 13:33:14 yunpian.go:24: error  无效的参数id,没有找到对应的tpl
-2022/03/17 13:37:26 main.go:64: info  req data: &{Id:01 Phones:15037870765 Params:[133726]}
-2022/03/17 13:37:27 service.go:37: info  云片 返回值: {"total_count":1,"total_fee":"0.0480","unit":"RMB","data":[{"code":0,"count":1,"fee":0.048,"mobile":"15037870765","msg":"发送成功","sid":71170988266,"unit":"RMB"}]}
-2022/03/17 13:39:47 main.go:64: info  req data: &{Id:01 Phones:1503787076 Params:[133947]}
-2022/03/17 13:39:48 service.go:37: info  云片 返回值: {"total_count":0,"total_fee":"0.0000","unit":"RMB","data":[{"http_status_code":400,"code":2,"msg":"请求参数格式错误","count":"0","fee":"0","unit":"RMB","mobile":"1503787076","sid":"0"}]}

+ 19 - 4
src/main.go

@@ -4,6 +4,9 @@ import (
 	. "Sms_Service/src/config"
 	. "Sms_Service/src/service"
 	"app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/endless"
+	"app.yhyue.com/moapp/jybase/go-xweb/xweb"
+	"app.yhyue.com/moapp/jylog"
 	"encoding/json"
 	"fmt"
 	"log"
@@ -14,7 +17,6 @@ import (
 	"github.com/donnie4w/go-logger/logger"
 )
 
-//
 type Sms struct {
 }
 
@@ -30,9 +32,22 @@ func init() {
 		log.Fatalln("无效的model配置项", Config.Model)
 	}
 }
-
-//
 func main() {
+	go func() {
+		frpc := new(Sms)
+		rpc.Register(frpc)
+		rpc.HandleHTTP()
+		err := endless.ListenAndServe(":"+Config.Port, nil, func() {})
+		if err != nil {
+			log.Println("ListenAndServe: ", err)
+		}
+	}()
+	mux1 := http.NewServeMux()
+	xweb.RootApp().Logger.SetOutput(jylog.GetWriter())
+	xweb.RunBase(":"+Config.WebPort, mux1)
+}
+
+func main1() {
 	logger.SetConsole(false)
 	logger.SetRollingDaily("./logs", "sms.log")
 	frpc := new(Sms)
@@ -48,7 +63,7 @@ func main() {
 	http.Serve(listen, nil)
 }
 
-//提交模板短信
+// 提交模板短信
 func (s *Sms) Execute(param *[]byte, ret *string) error {
 	go func() {
 		pool <- true

+ 45 - 11
src/service/weiwangtonglian.go

@@ -2,6 +2,7 @@ package service
 
 import (
 	. "Sms_Service/src/config"
+	"app.yhyue.com/moapp/jybase/common"
 	"bytes"
 	"crypto/md5"
 	"crypto/sha256"
@@ -16,7 +17,7 @@ import (
 	"github.com/donnie4w/go-logger/logger"
 )
 
-//微网通联短信平台
+// 微网通联短信平台
 var Weiwangtonglian = &weiwangtonglian{
 	t: "微网通联",
 }
@@ -25,36 +26,69 @@ type weiwangtonglian struct {
 	t string
 }
 
-//提交模板短信
+// 提交模板短信
 func (w *weiwangtonglian) Execute(reqData *ReqData) {
-	TempCode := Config.Weiwangtonglian.IdToTpl[reqData.Id]
-	if TempCode == 0 {
+	var (
+		productId = Config.Weiwangtonglian.ProductId
+		tempCode  = Config.Weiwangtonglian.IdToTpl[reqData.Id]
+	)
+	if mark := Config.Weiwangtonglian.ProductMark; len(reqData.Params) > 0 && mark != "" {
+		var p, t = -1, -1
+		for k, v := range reqData.Params {
+			if strings.Contains(v, mark) {
+				reqData.Params = append(reqData.Params[:k], reqData.Params[k+1:]...)
+				p = common.IntAll(strings.Split(v, mark)[0])
+				t = common.IntAll(strings.Split(v, mark)[1])
+				break
+			}
+		}
+		if p > -1 && t > -1 {
+			var (
+				productInfo = Config.Weiwangtonglian.ProductInfo
+				pId, tCode  = -1, -1
+			)
+			if len(productInfo) > p {
+				pId = productInfo[p].ProductId
+				if len(productInfo[p].TemplateCodes) > t {
+					tCode = productInfo[p].TemplateCodes[t]
+				}
+			}
+			if pId < 0 || tCode < 0 {
+				logger.Error("----无效的参数id,没有找到对应的tpl----")
+				return
+			}
+			productId = pId
+			tempCode = tCode
+		}
+	}
+	if tempCode == 0 {
 		logger.Error("无效的参数id,没有找到对应的tpl")
 		return
 	}
 	r := rand.New(rand.NewSource(time.Now().UnixNano()))
 	randInt := r.Intn(999999) + 5
-	Timestamp := time.Now().Unix()
+	timestamp := time.Now().Unix()
 	m5 := strings.ToUpper(w.Mmd5(Config.Weiwangtonglian.Password + Config.Weiwangtonglian.FixEncryptKey))
-	m256 := w.Msha256(fmt.Sprintf(`AccountId=%s&PhoneNos=%s&Password=%s&Random=%d&TempCode=%d&Timestamp=%d`, Config.Weiwangtonglian.AccountId, strings.Split(reqData.Phones, ",")[0], m5, randInt, TempCode, Timestamp))
+	m256 := w.Msha256(fmt.Sprintf(`AccountId=%s&PhoneNos=%s&Password=%s&Random=%d&TempCode=%d&Timestamp=%d`, Config.Weiwangtonglian.AccountId, strings.Split(reqData.Phones, ",")[0], m5, randInt, tempCode, timestamp))
 	pb, _ := json.Marshal(map[string]interface{}{
 		"AccountId":  Config.Weiwangtonglian.AccountId,
 		"AccessKey":  m256,
-		"Timestamp":  Timestamp,
+		"Timestamp":  timestamp,
 		"Random":     randInt,
-		"ProductId":  Config.Weiwangtonglian.ProductId,
+		"ProductId":  productId,
 		"PhoneNos":   reqData.Phones,
-		"TempCode":   TempCode,
+		"tempCode":   tempCode,
 		"TempParams": reqData.Params,
 	})
 	b, err := Post(Config.Weiwangtonglian.Url, "application/json", bytes.NewReader(pb), w.t)
 	if err != nil {
 		return
 	}
+	fmt.Println(string(b))
 	var result struct {
 		Result     string
 		Reason     string
-		MsgId      string
+		MsgId      int64
 		SplitCount int
 	}
 	json.Unmarshal(b, &result)
@@ -75,7 +109,7 @@ func (w *weiwangtonglian) Mmd5(val string) string {
 	return fmt.Sprintf("%x", m5.Sum(nil))
 }
 
-//删除模板(短信/视频短信)
+// 删除模板(短信/视频短信)
 func (w *weiwangtonglian) delTemplate() {
 	r := rand.New(rand.NewSource(time.Now().UnixNano()))
 	randInt := r.Intn(999999) + 5

BIN
src/sms.exe