/** * 阿里云短信联调脚本 * * 用法: * npm run test:sms -- 13800138000 LOGIN * npm run test:sms -- 13800138000 RESET_PASSWORD */ import { sendVerificationCodeSms } from '../src/common/sms/aliyunSms.service.js' import { config } from '../src/config/env.js' function usage(): never { console.log('用法: npm run test:sms -- <手机号> [LOGIN|RESET_PASSWORD]') process.exit(1) } async function main(): Promise { const phone = process.argv[2] const type = (process.argv[3] || 'LOGIN') as 'LOGIN' | 'RESET_PASSWORD' if (!phone || !/^1[3-9]\d{9}$/.test(phone)) usage() if (type !== 'LOGIN' && type !== 'RESET_PASSWORD') usage() if (config.smsProvider !== 'aliyun') { console.error('当前 SMS_PROVIDER 不是 aliyun,请先在 .env 中设置 SMS_PROVIDER=aliyun') process.exit(1) } const code = Math.floor(100000 + Math.random() * 900000).toString() await sendVerificationCodeSms(phone, code, type) console.log(`短信发送完成,手机号: ${phone}, 类型: ${type}, 验证码: ${code}`) } void main()