Skip to content

阿里短信服务


下面是一个下发短信验证码的示例

import { Context, Controller, ShowSuccess, ApiException, GetParams, Utils } from 'think-ts-lib'

export default class HelloController extends Controller {

  // 下发短信验证码
  async sendSms(ctx: Context) {
    const params = GetParams(ctx)
    const result = await Utils.SMS().sendSMS({
        PhoneNumbers: params.phone, // 要发送的手机号
        SignName: '馋么', // 认证签名
        TemplateCode: 'SMS_193870822', // 模板ID
        TemplateParam: JSON.stringify({
            code: this.Utils.getValidateCode()
        })
    })
    if (result.Code === 'OK') {
        return ShowSuccess()
    } else {
        ApiException('发送失败')
    }
  }

}
import { Context, Controller, ShowSuccess, ApiException, GetParams, Utils } from 'think-ts-lib'

export default class HelloController extends Controller {

  // 下发短信验证码
  async sendSms(ctx: Context) {
    const params = GetParams(ctx)
    const result = await Utils.SMS().sendSMS({
        PhoneNumbers: params.phone, // 要发送的手机号
        SignName: '馋么', // 认证签名
        TemplateCode: 'SMS_193870822', // 模板ID
        TemplateParam: JSON.stringify({
            code: this.Utils.getValidateCode()
        })
    })
    if (result.Code === 'OK') {
        return ShowSuccess()
    } else {
        ApiException('发送失败')
    }
  }

}

文档

https://www.npmjs.com/package/@alicloud/sms-sdk

阿里文档

https://help.aliyun.com/document_detail/215763.html

备案号:冀ICP备20015584号-2