35 lines
1.3 KiB
JavaScript
35 lines
1.3 KiB
JavaScript
import { calculateSignature } from './md5Util';
|
|
export default {
|
|
methods: {
|
|
async callApi(apiEndpoint, requestBody) {
|
|
try {
|
|
// 请求头
|
|
const headers = {
|
|
'Content-Type': 'application/json',//输出的数据格式是json
|
|
'app-key': 'c7d9decc0ccb4b6da81a9f65aea29ed3',//appkey编码
|
|
'sign-type': 'MD5',//MD5进行格式
|
|
'sign': '', // 先留空,稍后计算并填充 数据加密
|
|
};
|
|
//加密认证
|
|
const appSecret = '8299e69f17d943f59109a79d73e80da5';
|
|
// 计算 MD5 签名
|
|
const signature = calculateSignature(requestBody, appSecret);
|
|
headers['sign'] = signature;
|
|
// 发送 POST 请求 请求接口 请求体 请求头
|
|
const response = await this.axios.post(apiEndpoint, requestBody, { headers });
|
|
// 处理返回的数据
|
|
return response.data;
|
|
} catch (error) {
|
|
// 处理错误
|
|
console.error('调用接口发生错误:', error);
|
|
//抛出数据异常结果
|
|
throw error;
|
|
}
|
|
},
|
|
//定义新的数据方方法对其方法调用
|
|
generateApiEndpoint() {
|
|
return 'https://openapi-apaas.seeyonv8.com/wushuiyuntai3071243142359302596/FileAppService/generateShareUrl';
|
|
},
|
|
},
|
|
};
|