阿里短信服务
下面是一个下发短信验证码的示例
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('发送失败')
}
}
}