72 lines
4.1 KiB
JavaScript
72 lines
4.1 KiB
JavaScript
import service from '../utils/request.js'
|
||
|
||
// 检查用户token
|
||
export async function checkUsertoken(token) {
|
||
// console.log('开始验证token:', token); // 添加开始验证的日志
|
||
|
||
try {
|
||
const res = await service.get(`/auth/check/token`,{
|
||
headers: {
|
||
Authorization: `Bearer ${token}`
|
||
}
|
||
});
|
||
|
||
console.log('checkTokenValid:', res);
|
||
|
||
if (res.code === '401' || res.success === false) {
|
||
console.error('Token is invalid:', res.message);
|
||
return false;
|
||
}
|
||
|
||
// console.log('令牌有效');
|
||
return res;
|
||
} catch (error) {
|
||
console.error('验证token时发生错误:', error);
|
||
console.error('错误详情:', error.message, error.stack);
|
||
return false;
|
||
}
|
||
}
|
||
|
||
// 判断余额或免费次数是否充足
|
||
/**
|
||
* @param {object} data 预扣费接口参数
|
||
* @param {string} data.platformCode 平台编码
|
||
* @param {number} data.platformId 生成平台 必需
|
||
* @param {string} data.chargeCode 必需
|
||
* @param {number} data.quantity 必需
|
||
* @param {string} data.chargeType 生成类型(0:token,1:图片,3:音频,4:视频,5:3D,6:教学智能体,7:deep_research,8:多模态,9:AI编程,10:智能体开发) 必需
|
||
* @param {number} data.taskType ( 文生:1,图生:2,音效生成:3,参考生视频:4,白膜贴图:5 ) 必需
|
||
* @param {number} data.type 记录类型(0充点 1 次数 2 点数) 必需
|
||
* @param {string} data.preDeductAmount 预扣减金额 必需
|
||
* @returns
|
||
*/
|
||
export async function checkBalance(data,token) {
|
||
// console.log('开始验证余额:', token);
|
||
return await service.post(`/billing/judgeBalanceWithAmount`, data, {headers: { 'Authorization': `Bearer ${token}` }});
|
||
}
|
||
|
||
// 添加用户充值消费历史记录并扣费
|
||
/**
|
||
* @param {object} data judgeBalance接口参数
|
||
* @param {string} data.platformCode 平台编码 必需
|
||
* @param {number} data.platformId 生成平台 ( 音频:1,视频:2,3D:3 ) 必需
|
||
* @param {string} data.taskId 任务ID 必需
|
||
* @param {string} data.title 文件名 必需
|
||
* @param {string} data.chargeCode 可选
|
||
* @param {number} data.quantity 可选
|
||
* @param {string} data.status 任务状态 (0:进行中, 1:成功, 2:失败) 必需
|
||
* @param {string} data.result 生成的文字内容(文字类型时填写) 可选
|
||
* @param {string} data.tokens 消费的token数(文字类型时填写) 可选
|
||
* @param {string} data.fileUrl 文件路径(音视频图片类型时填写) 可选
|
||
* @param {string} data.errorMessage 错误消息(失败时填写) 可选
|
||
* @param {number} data.chargeType 生成类型( 0:token,1:图片,3:音频,4:视频,5:AI3D ) 必需
|
||
* @param {number} data.taskType ( 文生:1,图生:2,音效生成:3,参考生视频:4 ) 必需
|
||
* @param {number} data.type 记录类型(0充点 1 次数 2 点数) 必需
|
||
* @param {string} data.fileType 文件类型 可选
|
||
* @param {number} data.actualAmount 实际消费金额 必需
|
||
* @returns
|
||
*/
|
||
export function addConsumptionHistory(data,token) {
|
||
return service.post(`/billing/callbackWithAmount`, data, {headers: { 'Authorization': `Bearer ${token}` }});
|
||
}
|