package sms
|
|
|
|
import (
|
|
"errors"
|
|
"git.tetele.net/tgo/helper"
|
|
"log"
|
|
"time"
|
|
)
|
|
|
|
/**
|
|
* 企业信息服务平台--一信通短信,健帆用
|
|
* @spCode 企业编号
|
|
* @appKey 登录的用户名
|
|
* @secretKey 接口业务--接口申请里的秘钥
|
|
* @templateId 短信模板id
|
|
* @mobiles 手机号,多个用逗号隔开
|
|
* @content 短信内容
|
|
*/
|
|
func SendByUms(spCode, appKey, secretKey, mobiles, templateId, content string) (bool, error) {
|
|
if spCode == "" || appKey == "" || secretKey == "" || mobiles == "" || templateId == "" || content == "" {
|
|
return false, errors.New("参数不全")
|
|
}
|
|
|
|
api := "https://api.ums86.com/api/sms/send"
|
|
|
|
timestamp := helper.ToStr(time.Now().UnixNano() / 1e6)
|
|
num_rand := helper.GetRandomNumber(7)
|
|
|
|
serialNumber := timestamp + num_rand
|
|
// 短信请求字段
|
|
body_data := map[string]string{
|
|
"userNumber": mobiles,
|
|
"templateId": templateId,
|
|
"messageContent": content,
|
|
"serialNumber": serialNumber,
|
|
}
|
|
// 请求头封装
|
|
six_rand := helper.GetRandomString(6)
|
|
request_id := timestamp + six_rand
|
|
|
|
headers := map[string]string{
|
|
"x-sp-code": spCode,
|
|
"x-app-key": appKey,
|
|
"x-request-id": request_id,
|
|
"X-Forwarded-For": "120.78.230.86",
|
|
}
|
|
// 签名
|
|
sign := UmsSetSign(body_data, headers, secretKey)
|
|
headers["x-sign"] = sign
|
|
|
|
reply, err := PostJsonData(api, body_data, headers)
|
|
|
|
if err != nil {
|
|
log.Println("post err", err)
|
|
return false, err
|
|
}
|
|
|
|
var reply_data map[string]interface{}
|
|
|
|
err = json.Unmarshal(reply, &reply_data)
|
|
|
|
if err != nil {
|
|
log.Println(string(reply), err)
|
|
return false, err
|
|
}
|
|
|
|
if helper.ToStr(reply_data["code"]) != "0" {
|
|
return false, errors.New("短信发送失败," + helper.ToStr(reply_data["msg"]))
|
|
}
|
|
|
|
return true, nil
|
|
}
|