mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-22 20:37:48 +00:00
35 lines
925 B
TypeScript
35 lines
925 B
TypeScript
import axios from 'axios';
|
|
import { Obj2Query } from '../tools';
|
|
|
|
export const getClientToken = (googleVerKey: string) => {
|
|
if (typeof grecaptcha === 'undefined' || !grecaptcha?.ready) return '';
|
|
return new Promise<string>((resolve, reject) => {
|
|
grecaptcha.ready(async () => {
|
|
try {
|
|
const token = await grecaptcha.execute(googleVerKey, {
|
|
action: 'submit'
|
|
});
|
|
resolve(token);
|
|
} catch (error) {
|
|
reject(error);
|
|
}
|
|
});
|
|
});
|
|
};
|
|
|
|
// service run
|
|
export const authGoogleToken = async (data: {
|
|
secret: string;
|
|
response: string;
|
|
remoteip?: string;
|
|
}) => {
|
|
const res = await axios.post<{ score?: number; success: boolean }>(
|
|
`https://www.recaptcha.net/recaptcha/api/siteverify?${Obj2Query(data)}`
|
|
);
|
|
|
|
if (res.data.success && res.data.score && res.data.score >= 0.7) {
|
|
return Promise.resolve('');
|
|
}
|
|
return Promise.reject('非法环境');
|
|
};
|