Verified Commit 87bfadfd authored by Cui's avatar Cui

refactor struct

parent 12e7a5fb
......@@ -3,13 +3,12 @@
* @Date: 2019-01-15 15:06
*/
package utils
package sender
import (
"encoding/json"
"github.com/sirupsen/logrus"
"strconv"
"time"
. "gitlab.qingclass.cn/cuiweiqiang/utils"
)
const (
......@@ -18,8 +17,6 @@ const (
MASSPREVIEWURI = "https://api.weixin.qq.com/cgi-bin/message/mass/preview"
TEMPLATEURI = "https://api.weixin.qq.com/cgi-bin/message/template/send"
SUBSCRIBEURI = "https://api.weixin.qq.com/cgi-bin/message/template/subscribe"
NationCode = "86"
SMSSendUri = "https://yun.tim.qq.com/v5/tlssmssvr/sendsms"
)
type WxResponse struct {
......@@ -152,38 +149,3 @@ func SubscribeMessageSender(accessToken string, sm SubscribeMessage) (int, strin
return result.Errcode, result.Errmsg
}
func SmsMessageSender(sm SmsMessage, appId int, appKey string) (int, string) {
log := Logger.WithFields(logrus.Fields{
"position": "messageSender.go",
"func": "SmsMessageSender",
"accessToken": appId,
})
randInt := RandInt()
uri := SMSSendUri + "?sdkappid=" + strconv.Itoa(appId) + "&random=" + strconv.Itoa(randInt)
sm.Sign = ""
sm.Ext = ""
sm.Extend = ""
sm.Time = time.Now().Unix()
sm.Sig = SmsDoSign(appKey, []string{sm.Tel.Mobile}, sm.Time, randInt)
sm.Tel.Nationcode = NationCode
reqBody, _ := json.Marshal(sm)
body, statusCode, err := FasthttpPost(uri, reqBody)
if err != nil {
log.
WithField("error", err).
Error("SmsMessageSender Error!")
} else {
log.
WithFields(sm.ToFields()).
WithField("response", string(body)).
Info("SmsMessageSender send success !")
}
return statusCode, ""
}
/*
* @Author: cuiweiqiang
* @Date: 2019-01-16 22:04
*/
package sender
import (
"encoding/json"
"github.com/sirupsen/logrus"
. "gitlab.qingclass.cn/cuiweiqiang/utils"
"strconv"
"time"
)
const (
NationCode = "86"
SMSSendUri = "https://yun.tim.qq.com/v5/tlssmssvr/sendsms"
)
func SmsMessageSender(sm SmsMessage, appId int, appKey string) (int, string) {
log := Logger.WithFields(logrus.Fields{
"position": "messageSender.go",
"func": "SmsMessageSender",
"accessToken": appId,
})
randInt := RandInt()
uri := SMSSendUri + "?sdkappid=" + strconv.Itoa(appId) + "&random=" + strconv.Itoa(randInt)
sm.Sign = ""
sm.Ext = ""
sm.Extend = ""
sm.Time = time.Now().Unix()
sm.Sig = SmsDoSign(appKey, []string{sm.Tel.Mobile}, sm.Time, randInt)
sm.Tel.Nationcode = NationCode
reqBody, _ := json.Marshal(sm)
body, statusCode, err := FasthttpPost(uri, reqBody)
if err != nil {
log.
WithField("error", err).
Error("SmsMessageSender Error!")
} else {
log.
WithFields(sm.ToFields()).
WithField("response", string(body)).
Info("SmsMessageSender send success !")
}
return statusCode, ""
}
......@@ -3,7 +3,7 @@
* @Date: 2019-01-15 15:06
*/
package utils
package sender
import (
"encoding/json"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment