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