import BaseService from "../baseService";
|
import * as querystring from "querystring";
|
import { ResultInfo } from "../../public/commonInterface";
|
|
export default class SmsHelperService extends BaseService {
|
//#region SendYPSMS
|
/**
|
* 发送短信(云片网)
|
* @param phoneNumbers 发送手机号
|
* @param name 用户名
|
* @param param 参数
|
* @param templateCode 短信模板编码
|
*/
|
public async sendYPSMS(phoneNumbers: string, param: object, templateCode: number): Promise<ResultInfo> {
|
// 设置为您的apikey(https://www.yunpian.com)可查
|
let apikey = "cc7081e8ede397bd630d018255983288";
|
// 发送的手机号
|
let mobile = phoneNumbers;
|
// 发送模板编号
|
let tpl_id = templateCode;
|
|
// let val: any = {
|
// "#order_number#": verCode
|
// };
|
// if (name) {
|
// val["#name#"] = name;
|
// }
|
let tpl_value = querystring.stringify(param);
|
|
// 指定模板发送短信url
|
let url_tpl_sms = "https://sms.yunpian.com/v2/sms/tpl_single_send.json";
|
let data = {
|
apikey: apikey,
|
mobile: mobile,
|
tpl_id: tpl_id,
|
tpl_value: tpl_value
|
};
|
|
let result = await this.ctx.curl(url_tpl_sms, {
|
method: "POST",
|
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
|
content: querystring.stringify(data)
|
});
|
let resultMsg = JSON.parse(Buffer.from(result.data).toString());
|
if (resultMsg.http_status_code == 400) {
|
this.info.result = false;
|
this.info.msg = resultMsg.detail;
|
} else {
|
this.info.result = true;
|
this.info.msg = resultMsg.msg;
|
}
|
|
return this.info;
|
}
|
//#endregion
|
}
|