Files
苏尹岚 bccb99e580 duanxin
2020-12-16 11:08:56 +08:00

51 lines
1.6 KiB
Go

package smsmsg
import (
"fmt"
aliyunsmsclient "github.com/KenmyZhang/aliyun-communicate"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/baseapi/utils/errlist"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
)
var (
warningMap = map[string]int{
"isv.AMOUNT_NOT_ENOUGH": 1,
"isv.ACCOUNT_ABNORMAL": 1,
"isv.OUT_OF_SERVICE": 1,
"isv.DAY_LIMIT_CONTROL": 1,
}
)
func SendSMSMsg(mobileList []string, signName, templateCode string, templateParam map[string]interface{}) (err error) {
if len(mobileList) > 0 {
errList := errlist.New()
mobileList = jxutils.StringMap2List(jxutils.StringList2Map(mobileList))
for _, mobileNum := range mobileList {
if mobileNum != "" {
globals.SugarLogger.Debugf("SendSMSMsg mobileNum:%s, templateCode:%s", mobileNum, templateCode)
if true { //globals.EnableStoreWrite {
if response, err := api.SMSClient.Execute(globals.AliKey, globals.AliSecret, mobileNum, signName, templateCode, string(utils.MustMarshal(templateParam))); err != nil {
globals.SugarLogger.Warnf("SendSMSMsg mobileNum:%s failed with error:%v", mobileNum, err)
errList.AddErr(err)
} else if response.Code != aliyunsmsclient.ResponseCodeOk {
errMsg := fmt.Sprintf("SendSMSMsg mobileNum:%s failed with response:%s", mobileNum, utils.Format4Output(response, true))
errList.AddErr(fmt.Errorf(errMsg))
if warningMap[response.Code] == 1 {
globals.SugarLogger.Warnf(errMsg)
} else {
globals.SugarLogger.Infof(errMsg)
}
}
}
}
}
err = errList.GetErrListAsOne()
}
return err
}