保存
This commit is contained in:
30
mail-worker/src/service/turnstile-service.js
Normal file
30
mail-worker/src/service/turnstile-service.js
Normal 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;
|
||||
Reference in New Issue
Block a user