1 Star 0 Fork 0

kzangv/gsf-fof

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
sms.go 1.53 KB
一键复制 编辑 原始数据 按行查看 历史
kzangv 提交于 2023-02-23 13:34 . 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.2.0

搜索帮助

0d507c66 1850385 C8b1a773 1850385