schangxiang@126.com
2025-09-09 3d8966ba2c81e7e0365c8b123e861d18ee4f94f5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
}