1 Star 0 Fork 0

kzangv/gsf-fof

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
sms.go 1.53 KB
Copy Edit Raw Blame History
kzangv authored 2023-03-15 16:15 . fixed
package sms
import (
"encoding/json"
"errors"
)
type SmsResponse struct {
Status string `json:"status"`
Msg string `json:"msg"`
SendId string `json:"send_id"`
Fee int `json:"fee"`
SmsCredits string `json:"sms_credits"`
TransactionalSmsCredits string `json:"transactional_sms_credits"`
}
func XSend(to, tempId string, data map[string]string, appId, appKey string) error {
config := map[string]string{
"appid": appId,
"appkey": appKey,
"signType": "md5",
}
s := CreateXsend(config)
ret := s.SetTo(to).SetProject(tempId).AddVars(data).Xsend()
retData := SmsResponse{}
err := json.Unmarshal([]byte(ret), &retData)
if err != nil {
return err
}
if retData.Status == "error" {
return errors.New(retData.Msg)
}
return nil
}
func MultiXSend(to []string, tempId string, data map[string]string, appId, appKey string) ([]SmsResponse, []string, error) {
config := map[string]string{
"appid": appId,
"appkey": appKey,
"signType": "md5",
}
s := CreateMultiXsend(config)
for _, phone := range to {
msg := CreateMulti()
msg.SetTo(phone).AddVars(data)
s.AddMulti(msg.Get())
}
ret := s.SetProject(tempId).MultiXsend()
var retData []SmsResponse
failData := make([]string, len(retData))
err := json.Unmarshal([]byte(ret), &retData)
if err != nil {
return nil, failData, err
}
for _, value := range retData {
if value.Status == "error" {
failData = append(failData, value.SendId)
}
}
return retData, failData, nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kzangv/gsf-fof.git
git@gitee.com:kzangv/gsf-fof.git
kzangv
gsf-fof
gsf-fof
v0.4.2

Search