Files
AIclinicalresearch/backend/scripts/test-aliyun-sms.ts
HaHafeng d30bf95815 feat(auth): integrate Aliyun SMS verification flow with docs update
Wire auth verification-code delivery to Aliyun SMS with mock fallback, config validation, and a standalone SMS smoke-test script. Update deployment checklist and system status docs with required env vars and rollout notes.

Made-with: Cursor
2026-03-09 20:30:52 +08:00

35 lines
1.0 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 阿里云短信联调脚本
*
* 用法:
* 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<void> {
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()