|
@ -0,0 +1,76 @@ |
|
|
|
|
|
package smsrpc |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
|
"encoding/json" |
|
|
|
|
|
"errors" |
|
|
|
|
|
"log" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 发送腾讯云短信 |
|
|
|
|
|
* @secretId 腾讯云密钥id |
|
|
|
|
|
* @secretKey 腾讯云密钥key |
|
|
|
|
|
* @signname 签名 |
|
|
|
|
|
* @templateId 模板id |
|
|
|
|
|
* @mobiles 手机号,多个用逗号隔开 |
|
|
|
|
|
* @params 参数值 |
|
|
|
|
|
*/ |
|
|
|
|
|
func SendTencentSms(secretId, secretKey, smsAppId string, signname, templateId string, mobiles, params []string, url ...string) ([]map[string]interface{}, error) { |
|
|
|
|
|
|
|
|
|
|
|
if secretId == "" || secretKey == "" || signname == "" || templateId == "" { |
|
|
|
|
|
return nil, errors.New("参数错误") |
|
|
|
|
|
} |
|
|
|
|
|
if len(mobiles) < 1 || len(params) < 1 { |
|
|
|
|
|
return nil, errors.New("参数错误") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
conn, err := rpc_server_conn(url...) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
defer conn.Close() |
|
|
|
|
|
|
|
|
|
|
|
mobile, err := json.Marshal(mobiles) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
param, err := json.Marshal(params) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
arg := TencentParam{secretId, secretKey, smsAppId, signname, string(mobile), templateId, string(param)} |
|
|
|
|
|
|
|
|
|
|
|
req, err := SetReqData(arg) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
res := &Response{} |
|
|
|
|
|
|
|
|
|
|
|
err = conn.SendTencentMsg(req, res) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
res_data_de, err := GetResData(res) |
|
|
|
|
|
|
|
|
|
|
|
log.Println(res_data_de, err) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
if res_data_de == "" { |
|
|
|
|
|
return nil, nil |
|
|
|
|
|
} |
|
|
|
|
|
var res_arr []map[string]interface{} |
|
|
|
|
|
|
|
|
|
|
|
err = json.Unmarshal([]byte(res_data_de), &res_arr) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
return res_arr, nil |
|
|
|
|
|
|
|
|
|
|
|
} |