检查了appId、APISecret都没有问题
一直报解析签名出错,但是签名没有地方校验,我是哪里错了呢
// APPID: 'b7823b6a', // 控制台获取填写
// APISecret: 'NTU4ZTgwYTRhYzJjYTJmNzBmNmNlNDc1',
getHeader() {
let that = this
let timestamp = Math.floor(Date.now() / 1000).toString()
const headers = {
appId: that.APPID,
timestamp: timestamp,
signature: that.getSignature(that.APPID, that.APISecret, timestamp),
'content-type': 'multipart/form-data',
};
return headers;
},
getSignature(appId, secret, ts) {
const auth = md5(appId + ts);
const signature = CryptoJS.HmacSHA1(auth, secret).toString(CryptoJS.enc.Hex);
return signature
},
// 上传文档
uploadTxt() {
uni.chooseFile({
success: (chooseImageRes) => {
const tempFilePaths = chooseImageRes.tempFilePaths;
this.uploadDocument(tempFilePaths[0])
}
});
},
async uploadDocument(file) {
const formData = new FormData();
formData.append('file', file);
formData.append('fileName', '背影.txt');
formData.append('fileType', 'wiki');
const headers = this.getHeader();
try {
const response = await axios.post(
'https://chatdoc.xfyun.cn/openapi/v1/file/upload',
formData, {
headers
}
);
console.log('Response:', response.data);
} catch (error) {
console.error('Error:', error);
}
},
低质量回答:
getHeader() {
let that = this;
let timestamp = Math.floor(Date.now() / 1000).toString();
const headers = {
appId: that.APPID,
timestamp: timestamp,
signature: that.getSignature(that.APPID, that.APISecret, timestamp),
'content-type': 'multipart/form-data',
};
return headers;
},
getSignature(appId, secret, ts) {
const auth = md5(appId + ts);
console.log('Auth:', auth); // 调试信息
const signature = CryptoJS.HmacSHA1(auth, secret).toString(CryptoJS.enc.Hex);
console.log('Signature:', signature); // 调试信息
return signature;
},
// 上传文档
uploadTxt() {
uni.chooseFile({
success: (chooseImageRes) => {
const tempFilePaths = chooseImageRes.tempFilePaths;
this.uploadDocument(tempFilePaths[0]);
}
});
},
async uploadDocument(file) {
const formData = new FormData();
formData.append('file', file);
formData.append('fileName', '背影.txt');
formData.append('fileType', 'wiki');
const headers = this.getHeader();
try {
const response = await axios.post(
'https://chatdoc.xfyun.cn/openapi/v1/file/upload',
formData, {
headers
}
);
console.log('Response:', response.data);
} catch (error) {
console.error('Error:', error);
}
}
CopyInsert
我没看出来哪里修改了呢,放进代码里还是报一样的错误
那就主要检查这个方法,参考文档,看参数顺序和算法是否正确
getSignature(appId, secret, ts) {
const auth = md5(appId + ts);
const signature = CryptoJS.HmacSHA1(auth, secret).toString(CryptoJS.enc.Hex);
return signature
}