update
This commit is contained in:
parent
345c90cecf
commit
4c9e3c16d3
@ -607,7 +607,11 @@ const DigitalElectronics: React.FC<{ currentUser: any }> = (props) => {
|
|||||||
language: ""
|
language: ""
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
let token = await handleGetForwardJDPJInterface(req)
|
let newreq: any = {
|
||||||
|
name: "",
|
||||||
|
value: encryptAES(JSON.stringify(req))
|
||||||
|
}
|
||||||
|
let token = await handleGetForwardJDPJInterface(newreq)
|
||||||
let tokenData = token ? JSON.parse(token as any) : ""
|
let tokenData = token ? JSON.parse(token as any) : ""
|
||||||
console.log('tokenDatatokenDatatokenDatatokenDatadasdsa', tokenData);
|
console.log('tokenDatatokenDatatokenDatatokenDatadasdsa', tokenData);
|
||||||
|
|
||||||
@ -641,8 +645,15 @@ const DigitalElectronics: React.FC<{ currentUser: any }> = (props) => {
|
|||||||
usertype: ""
|
usertype: ""
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
let accessTokenData = await handleGetForwardJDPJInterface(tokenReq)
|
|
||||||
|
let newTokenReq: any = {
|
||||||
|
name: "",
|
||||||
|
value: encryptAES(JSON.stringify(tokenReq))
|
||||||
|
}
|
||||||
|
let accessTokenData = await handleGetForwardJDPJInterface(newTokenReq)
|
||||||
|
|
||||||
let accessToken = JSON.parse(accessTokenData as any)
|
let accessToken = JSON.parse(accessTokenData as any)
|
||||||
|
console.log('dajksdjaksd', accessToken);
|
||||||
|
|
||||||
setAppToken(appToken)
|
setAppToken(appToken)
|
||||||
setAccessToken(accessToken.data.access_token)
|
setAccessToken(accessToken.data.access_token)
|
||||||
@ -674,7 +685,12 @@ const DigitalElectronics: React.FC<{ currentUser: any }> = (props) => {
|
|||||||
Access_token: accessToken.data.access_token,
|
Access_token: accessToken.data.access_token,
|
||||||
data: JSON.stringify(requestParams)
|
data: JSON.stringify(requestParams)
|
||||||
}
|
}
|
||||||
let responseOld = await handleGetForwardJDPJInterface(reqResult)
|
|
||||||
|
let newreqResult: any = {
|
||||||
|
name: "",
|
||||||
|
value: encryptAES(JSON.stringify(reqResult))
|
||||||
|
}
|
||||||
|
let responseOld = await handleGetForwardJDPJInterface(newreqResult)
|
||||||
console.log('responseOldresponseOldresponseOld', responseOld);
|
console.log('responseOldresponseOldresponseOld', responseOld);
|
||||||
responseOld = JSON.parse(responseOld as any)
|
responseOld = JSON.parse(responseOld as any)
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import requestKaiPiao from "@/utils/requestKaiPiao"
|
import requestKaiPiao from "@/utils/requestKaiPiao"
|
||||||
|
import requestMemberApi from "@/utils/requestMemberApi"
|
||||||
import requestOld from "@/utils/requestOld"
|
import requestOld from "@/utils/requestOld"
|
||||||
|
|
||||||
|
|
||||||
@ -112,7 +113,7 @@ export async function handleGetBILLDETAILList(params: any) {
|
|||||||
|
|
||||||
// 包一层的中转接口 用来解决金飘云的跨域问题
|
// 包一层的中转接口 用来解决金飘云的跨域问题
|
||||||
export async function handleGetForwardJDPJInterface(params: any) {
|
export async function handleGetForwardJDPJInterface(params: any) {
|
||||||
const data = await requestKaiPiao(`/Invoice/ForwardJDPJInterface`, {
|
const data = await requestMemberApi(`/ThirdInterface/ForwardJDPJInterface`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: params
|
data: params
|
||||||
})
|
})
|
||||||
|
|||||||
@ -543,7 +543,11 @@ const InvoiceInquiry: React.FC<{ currentUser: any }> = (props) => {
|
|||||||
language: ""
|
language: ""
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
let token = await handleGetForwardJDPJInterface(req)
|
let newreq: any = {
|
||||||
|
name: "",
|
||||||
|
value: encryptAES(JSON.stringify(req))
|
||||||
|
}
|
||||||
|
let token = await handleGetForwardJDPJInterface(newreq)
|
||||||
let tokenData = token ? JSON.parse(token as any) : ""
|
let tokenData = token ? JSON.parse(token as any) : ""
|
||||||
console.log('tokenDatatokenDatatokenDatatokenDatadasdsa', tokenData);
|
console.log('tokenDatatokenDatatokenDatatokenDatadasdsa', tokenData);
|
||||||
|
|
||||||
@ -577,7 +581,11 @@ const InvoiceInquiry: React.FC<{ currentUser: any }> = (props) => {
|
|||||||
usertype: ""
|
usertype: ""
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
let accessTokenData = await handleGetForwardJDPJInterface(tokenReq)
|
let newTokenReq: any = {
|
||||||
|
name: "",
|
||||||
|
value: encryptAES(JSON.stringify(tokenReq))
|
||||||
|
}
|
||||||
|
let accessTokenData = await handleGetForwardJDPJInterface(newTokenReq)
|
||||||
let accessToken = JSON.parse(accessTokenData as any)
|
let accessToken = JSON.parse(accessTokenData as any)
|
||||||
|
|
||||||
setAppToken(appToken)
|
setAppToken(appToken)
|
||||||
|
|||||||
@ -606,7 +606,11 @@ const RedReversal: React.FC<{ currentUser: any }> = (props) => {
|
|||||||
language: ""
|
language: ""
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
let token = await handleGetForwardJDPJInterface(req)
|
let newreq: any = {
|
||||||
|
name: "",
|
||||||
|
value: encryptAES(JSON.stringify(req))
|
||||||
|
}
|
||||||
|
let token = await handleGetForwardJDPJInterface(newreq)
|
||||||
let tokenData = token ? JSON.parse(token as any) : ""
|
let tokenData = token ? JSON.parse(token as any) : ""
|
||||||
console.log('tokenDatatokenDatatokenDatatokenDatadasdsa', tokenData);
|
console.log('tokenDatatokenDatatokenDatatokenDatadasdsa', tokenData);
|
||||||
|
|
||||||
@ -640,7 +644,11 @@ const RedReversal: React.FC<{ currentUser: any }> = (props) => {
|
|||||||
usertype: ""
|
usertype: ""
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
let accessTokenData = await handleGetForwardJDPJInterface(tokenReq)
|
let newTokenReq: any = {
|
||||||
|
name: "",
|
||||||
|
value: encryptAES(JSON.stringify(tokenReq))
|
||||||
|
}
|
||||||
|
let accessTokenData = await handleGetForwardJDPJInterface(newTokenReq)
|
||||||
let accessToken = JSON.parse(accessTokenData as any)
|
let accessToken = JSON.parse(accessTokenData as any)
|
||||||
|
|
||||||
setAppToken(appToken)
|
setAppToken(appToken)
|
||||||
|
|||||||
@ -16,6 +16,7 @@ const { UMI_APP_BASEURL } = process.env;
|
|||||||
// const instance = axios.create({ baseURL: 'https://cosmic-sandbox.piaozone.com/jdpjykjyxgs' });
|
// const instance = axios.create({ baseURL: 'https://cosmic-sandbox.piaozone.com/jdpjykjyxgs' });
|
||||||
|
|
||||||
// 改为使用代理路径
|
// 改为使用代理路径
|
||||||
|
// const instance = axios.create({ baseURL: 'http://api.eshangtech.com/EShangApiMain' });
|
||||||
const instance = axios.create({ baseURL: 'http://api.eshangtech.com/EShangApiMain' });
|
const instance = axios.create({ baseURL: 'http://api.eshangtech.com/EShangApiMain' });
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
149
src/utils/requestMemberApi.ts
Normal file
149
src/utils/requestMemberApi.ts
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
import axios from 'axios';
|
||||||
|
import { getDvaApp } from 'umi';
|
||||||
|
import { notification } from 'antd';
|
||||||
|
import type { AxiosRequestHeaders } from 'axios/index';
|
||||||
|
import CryptoJS from "crypto-js";
|
||||||
|
|
||||||
|
const { UMI_APP_BASEURL } = process.env;
|
||||||
|
|
||||||
|
// const instance = axios.create({ baseURL: UMI_APP_BASEURL });
|
||||||
|
const instance = axios.create({ baseURL: 'https://api.eshangtech.com/MemberApi' });
|
||||||
|
// const instance = axios.create({ baseURL: '/auth' });
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
instance.interceptors.request.use(
|
||||||
|
(config) => {
|
||||||
|
// 对data数据进行加密
|
||||||
|
// if (config.data) {
|
||||||
|
// config.data = preprocessData(JSON.stringify(config.data)); // 调用预处理函数
|
||||||
|
// }
|
||||||
|
|
||||||
|
config.headers = {
|
||||||
|
...config.headers,
|
||||||
|
Authorization: `Bearer ${localStorage.getItem('Authorization') || ''}`,
|
||||||
|
"Content-Type": "application/json;charset=utf-8"
|
||||||
|
} as AxiosRequestHeaders;
|
||||||
|
|
||||||
|
return config;
|
||||||
|
},
|
||||||
|
(error) => Promise.reject(error),
|
||||||
|
);
|
||||||
|
|
||||||
|
instance.interceptors.response.use(
|
||||||
|
//状态码为2xx的时候执行
|
||||||
|
(response) => {
|
||||||
|
const { data } = response;
|
||||||
|
|
||||||
|
if (data.code !== 200 && data.Result_Code !== 100) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const timestamp = getFormattedDate()
|
||||||
|
|
||||||
|
return data
|
||||||
|
},
|
||||||
|
//状态码不是2xx的时候执行
|
||||||
|
(error) => {
|
||||||
|
const { response } = error;
|
||||||
|
|
||||||
|
if (response && response.status === 401) {
|
||||||
|
// // 清除本地存储的token
|
||||||
|
// localStorage.removeItem('Authorization');
|
||||||
|
// // 重定向到登录页
|
||||||
|
// window.location.href = '/user/login';
|
||||||
|
// notification.error({
|
||||||
|
// message: response?.data?.message || '请求失败',
|
||||||
|
// description: error.message
|
||||||
|
// });
|
||||||
|
} else {
|
||||||
|
notification.error({
|
||||||
|
message: response?.data?.message || '请求失败',
|
||||||
|
description: error.message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.reject({
|
||||||
|
code: response?.status || 500,
|
||||||
|
message: response?.data?.message || '请求失败'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// 加密
|
||||||
|
const encryptAESECB = (data: string, key: string) => {
|
||||||
|
// const cipher = CryptoJS.createCipheriv('aes-128-ecb', key, null); // ECB 模式不需要 IV
|
||||||
|
const newKey = CryptoJS.enc.Utf8.parse(key); // 密钥必须是 16 字节
|
||||||
|
const cipher = CryptoJS.AES.encrypt(data, newKey, {
|
||||||
|
mode: CryptoJS.mode.ECB,
|
||||||
|
padding: CryptoJS.pad.Pkcs7
|
||||||
|
});
|
||||||
|
let encrypted = cipher.ciphertext.toString(CryptoJS.enc.Hex);
|
||||||
|
// let encrypted = cipher.update(data, 'utf8', 'hex');
|
||||||
|
// encrypted += cipher.final('hex');
|
||||||
|
return encrypted;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解密
|
||||||
|
const decryptAESECB = (data: string, key: string) => {
|
||||||
|
// const decipher = CryptoJS.createDecipheriv('aes-128-ecb', key, null);
|
||||||
|
// let decrypted = decipher.update(data, 'hex', 'utf8');
|
||||||
|
// decrypted += decipher.final('utf8');
|
||||||
|
const newKey = CryptoJS.enc.Utf8.parse(key);
|
||||||
|
|
||||||
|
const encryptedData = CryptoJS.enc.Hex.parse(data);
|
||||||
|
|
||||||
|
// 解密操作
|
||||||
|
const decrypted = CryptoJS.AES.decrypt({ ciphertext: encryptedData }, newKey, {
|
||||||
|
mode: CryptoJS.mode.ECB, // ECB 模式
|
||||||
|
padding: CryptoJS.pad.Pkcs7 // PKCS7 填充方式
|
||||||
|
});
|
||||||
|
// 将解密后的结果转为 UTF-8 字符串
|
||||||
|
const decryptedText = decrypted.toString(CryptoJS.enc.Utf8);
|
||||||
|
return decryptedText;
|
||||||
|
}
|
||||||
|
|
||||||
|
// md5 签名
|
||||||
|
const md5 = (key: string, data: string, timestamp: string) => {
|
||||||
|
const text = "s" + key + data + timestamp;
|
||||||
|
return CryptoJS.MD5(text).toString(CryptoJS.enc.Hex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成签名戳
|
||||||
|
const getFormattedDate = () => {
|
||||||
|
const date = new Date();
|
||||||
|
const year = date.getFullYear(); // 获取年份 (yyyy)
|
||||||
|
const month = String(date.getMonth() + 1).padStart(2, '0'); // 获取月份 (MM)
|
||||||
|
const day = String(date.getDate()).padStart(2, '0'); // 获取日期 (dd)
|
||||||
|
const hours = String(date.getHours()).padStart(2, '0'); // 获取小时 (HH)
|
||||||
|
return `es0${year}${month}${day}${hours}0es`; // 拼接成 yyyyMMddHH 格式
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加密方法
|
||||||
|
const preprocessData = (data: string) => {
|
||||||
|
console.log('data', data);
|
||||||
|
// YYYYMMDD
|
||||||
|
let timestamp = getFormattedDate()
|
||||||
|
console.log('timestamp', timestamp);
|
||||||
|
// 秒为单位的时间戳
|
||||||
|
let timeSecond = parseInt((new Date().getTime() / 1000).toString())
|
||||||
|
console.log('timeSecond', timeSecond);
|
||||||
|
// 数据的加密
|
||||||
|
let encryptionData = encryptAESECB(data, timestamp)
|
||||||
|
console.log('encryptionData', encryptionData);
|
||||||
|
// md5签名方法
|
||||||
|
let md5Data = md5(timestamp, encryptionData, timestamp)
|
||||||
|
console.log('md5Data', md5Data);
|
||||||
|
|
||||||
|
let res = {
|
||||||
|
data: encryptionData,
|
||||||
|
timestamp: timeSecond,
|
||||||
|
sign: md5Data
|
||||||
|
}
|
||||||
|
console.log('res', res);
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
export default instance;
|
||||||
@ -7,7 +7,8 @@ import CryptoJS from "crypto-js";
|
|||||||
const { UMI_APP_BASEURL } = process.env;
|
const { UMI_APP_BASEURL } = process.env;
|
||||||
|
|
||||||
// const instance = axios.create({ baseURL: UMI_APP_BASEURL });
|
// const instance = axios.create({ baseURL: UMI_APP_BASEURL });
|
||||||
const instance = axios.create({ baseURL: 'https://api.eshangtech.com/EShangApiMain' });
|
// const instance = axios.create({ baseURL: 'https://api.eshangtech.com/EShangApiMain' });
|
||||||
|
const instance = axios.create({ baseURL: 'https://samember.yciccloud.com:8999/EShangApiMain' });
|
||||||
// const instance = axios.create({ baseURL: '/auth' });
|
// const instance = axios.create({ baseURL: '/auth' });
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user