2025-03-19 15:49:18 +08:00
|
|
|
'use server'
|
2025-04-26 14:18:08 +08:00
|
|
|
import {ApiResponse} from '@/lib/api'
|
|
|
|
|
import {callByDevice} from '@/actions/base'
|
2025-12-11 14:10:52 +08:00
|
|
|
import {getCap} from '@/lib/cap'
|
2025-03-19 15:49:18 +08:00
|
|
|
|
2025-04-26 14:18:08 +08:00
|
|
|
export async function sendSMS(props: {
|
2025-03-28 15:00:46 +08:00
|
|
|
phone: string
|
2025-04-26 14:18:08 +08:00
|
|
|
captcha: string
|
|
|
|
|
}): Promise<ApiResponse> {
|
2025-03-19 15:49:18 +08:00
|
|
|
try {
|
|
|
|
|
// 人机验证
|
|
|
|
|
if (!props.captcha?.length) {
|
|
|
|
|
return {
|
|
|
|
|
success: false,
|
|
|
|
|
status: 400,
|
|
|
|
|
message: '请输入验证码',
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-12-11 14:10:52 +08:00
|
|
|
|
|
|
|
|
const cap = await getCap()
|
|
|
|
|
const valid = await cap.validateToken(props.captcha)
|
2025-03-19 15:49:18 +08:00
|
|
|
if (!valid) {
|
|
|
|
|
return {
|
|
|
|
|
success: false,
|
|
|
|
|
status: 400,
|
|
|
|
|
message: '验证码错误或已过期',
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 请求发送短信
|
2026-03-31 15:34:50 +08:00
|
|
|
return await callByDevice('/api/verify/sms', {
|
2025-03-19 15:49:18 +08:00
|
|
|
phone: props.phone,
|
|
|
|
|
purpose: 0,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
catch (error) {
|
2025-04-22 10:44:05 +08:00
|
|
|
console.error('验证码验证失败:', error)
|
2025-03-19 15:49:18 +08:00
|
|
|
throw new Error('验证码验证失败', {cause: error})
|
|
|
|
|
}
|
|
|
|
|
}
|