This commit is contained in:
eoao
2025-04-26 17:24:39 +08:00
commit 24ba4772e6
107 changed files with 13612 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
import BizError from '../error/biz-error';
const turnstileService = {
async verify(c, token) {
if (!token) {
throw new BizError('验证token不能为空');
}
const res = await fetch('https://challenges.cloudflare.com/turnstile/v0/siteverify', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: new URLSearchParams({
secret: c.env.secret_key,
response: token,
remoteip: c.req.header('cf-connecting-ip')
})
});
const result = await res.json();
console.log(result)
if (!result.success) {
throw new BizError('人机验证失败,请重试',400)
}
}
};
export default turnstileService;