12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- const BASE_URL = '' //http://192.168.3.152:8088/glwork
- const s4 = new SM4Util()
- //加密
- function encrypt(content) {
- return s4.encryptData_CBC(content)
- }
- //解密
- function decrypt(content) {
- content = content.replace(/"+/g, "").replace(/\s+/g, "");
- return s4.decryptData_CBC(content).replace(
- /\u0000|\u0001|\u0002|\u0003|\u0004|\u0005|\u0006|\u0007|\u0008|\u0009|\u000a|\u000b|\u000c|\u000d|\u000e|\u000f|\u0010|\u0011|\u0012|\u0013|\u0014|\u0015|\u0016|\u0017|\u0018|\u0019|\u001a|\u001b|\u001c|\u001d|\u001e|\u001f|\u007F/g,
- "")
- }
- export function ApiRequest(config = {}){
- let {
- url,
- data,
- method="GET",
- header={}
- } = config
- url = BASE_URL + url
- header['Authorization'] = 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIwYzY3NTYxZi01ZDBkLTQ4ZmQtYTkwYi05MGQ2OWE5OGZiYWMiLCJjbGllbnRpZCI6ImFuZHJvaWRjbGllbnQiLCJncmFudF90eXBlIjoicGFzc3dvcmQiLCJzY29wZSI6Im9wZW5pZCBwcm9maWxlIGVtYWlsIFJlZmluZUFQSSIsImV4cCI6MTczNDcxNzExNywiY29uZmlnIjoiMjAyMC0yMDk5In0.zkgfGsl0euGKek87wVIxXSfMOp4ZgY_uz4rz-zmOzFA'
-
- if(uni.getStorageSync('GlWorkPlatform-AccessToken')){
- header['Authorization'] = 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIwYzY3NTYxZi01ZDBkLTQ4ZmQtYTkwYi05MGQ2OWE5OGZiYWMiLCJjbGllbnRpZCI6ImFuZHJvaWRjbGllbnQiLCJncmFudF90eXBlIjoicGFzc3dvcmQiLCJzY29wZSI6Im9wZW5pZCBwcm9maWxlIGVtYWlsIFJlZmluZUFQSSIsImV4cCI6MTczNDcxNzExNywiY29uZmlnIjoiMjAyMC0yMDk5In0.zkgfGsl0euGKek87wVIxXSfMOp4ZgY_uz4rz-zmOzFA'
-
- //'Bearer ' + uni.getStorageSync('GlWorkPlatform-AccessToken')
- }
- return new Promise((resolve, reject)=>{
- uni.request({
- url: url,
- data: {data:encrypt(JSON.stringify(data))} ,
- method: method,
- header: header,
- timeout: 60000,
- success: (res)=>{
- resolve(JSON.parse(decrypt(res.data.data)))
- },
- fail: (err) => {
- reject(err)
- },
- complete: (event)=>{
-
- }
- })
- })
- }
|