短信发送方法
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
2.3 KiB

package sms
import (
"log"
"git.tetele.net/tgo/helper"
)
/**
* 创蓝253发送短信
*
* @param string $mobile 手机号码
* @param string $msg 短信内容
* @param string $sms_sign 短信签名
* @param string $needstatus 是否需要状态报告
* @return success bool, reply map[string]string, err error
*/
var CL_ACCOUNT string = "N3402351"
var CL_PASSWORD string = "zmkj64U5A"
// const CL_VARIABLE_SMS_URL string = "http://XXX/msg/variable/json"
func SendByCL(account, password, mobile, sms_sign, msg string) (bool, map[string]interface{}, error) {
const CL_SIMPLE_SMS_URL string = "https://smssh1.253.com/msg/v1/send/json" // "http://smssh1.253.com/msg/send/json"
if account == "" {
account = CL_ACCOUNT
}
if password == "" {
password = CL_PASSWORD
}
//创蓝接口参数
data := map[string]string{
"account": account,
"password": password,
"msg": StringJoin("【", sms_sign, "】", msg),
"phone": mobile,
"report": "true",
}
response, err := PostJsonData(CL_SIMPLE_SMS_URL, data)
if err != nil {
return false, nil, err
}
var reply map[string]interface{}
err = json.Unmarshal(response, &reply)
if err != nil {
log.Println(string(response), err)
return false, nil, err
}
if helper.ToStr(reply["code"]) != "0" {
return false, reply, nil
}
return true, reply, err
}
/**
* 查询额度
*
*/
func QueryRemaining(account, password string) (bool, string, map[string]interface{}, error) {
const URL string = "https://smssh1.253.com/msg/balance/json"
if account == "" {
account = CL_ACCOUNT
}
if password == "" {
password = CL_PASSWORD
}
data := map[string]string{
"account": account,
"password": password,
}
response, err := PostJsonData(URL, data)
/** 返回示例
{"code":0,"balance":"9156","time":"20230217150940","errorMsg":""}
{"code":"130","msgId":"","time":"20230217145243","errorMsg":"请求参数错误"}
{"code":"101","msgId":"","time":"20230217151029","errorMsg":"无此用户"}
*/
if err != nil {
return false, "", nil, err
}
var reply map[string]interface{}
err = json.Unmarshal(response, &reply)
if err != nil {
log.Println(string(response), err)
return false, "", nil, err
}
if helper.ToStr(reply["code"]) != "0" {
return false, "", reply, nil
}
return true, helper.ToStr(reply["balance"]), reply, err
}