1
0

requesttest2.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const BASE_URL = '' //http://192.168.3.152:8088/glwork
  2. const s4 = new SM4Util()
  3. //加密
  4. function encrypt(content) {
  5. return s4.encryptData_CBC(content)
  6. }
  7. //解密
  8. function decrypt(content) {
  9. content = content.replace(/"+/g, "").replace(/\s+/g, "");
  10. return s4.decryptData_CBC(content).replace(
  11. /\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,
  12. "")
  13. }
  14. export function ApiRequest(config = {}){
  15. let {
  16. url,
  17. data,
  18. method="GET",
  19. header={}
  20. } = config
  21. url = BASE_URL + url
  22. header['Authorization'] = 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIwYzY3NTYxZi01ZDBkLTQ4ZmQtYTkwYi05MGQ2OWE5OGZiYWMiLCJjbGllbnRpZCI6ImFuZHJvaWRjbGllbnQiLCJncmFudF90eXBlIjoicGFzc3dvcmQiLCJzY29wZSI6Im9wZW5pZCBwcm9maWxlIGVtYWlsIFJlZmluZUFQSSIsImV4cCI6MTczNDcxNzExNywiY29uZmlnIjoiMjAyMC0yMDk5In0.zkgfGsl0euGKek87wVIxXSfMOp4ZgY_uz4rz-zmOzFA'
  23. if(uni.getStorageSync('GlWorkPlatform-AccessToken')){
  24. header['Authorization'] = 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIwYzY3NTYxZi01ZDBkLTQ4ZmQtYTkwYi05MGQ2OWE5OGZiYWMiLCJjbGllbnRpZCI6ImFuZHJvaWRjbGllbnQiLCJncmFudF90eXBlIjoicGFzc3dvcmQiLCJzY29wZSI6Im9wZW5pZCBwcm9maWxlIGVtYWlsIFJlZmluZUFQSSIsImV4cCI6MTczNDcxNzExNywiY29uZmlnIjoiMjAyMC0yMDk5In0.zkgfGsl0euGKek87wVIxXSfMOp4ZgY_uz4rz-zmOzFA'
  25. //'Bearer ' + uni.getStorageSync('GlWorkPlatform-AccessToken')
  26. }
  27. return new Promise((resolve, reject)=>{
  28. uni.request({
  29. url: url,
  30. data: {data:encrypt(JSON.stringify(data))} ,
  31. method: method,
  32. header: header,
  33. timeout: 60000,
  34. success: (res)=>{
  35. resolve(JSON.parse(decrypt(res.data.data)))
  36. },
  37. fail: (err) => {
  38. reject(err)
  39. },
  40. complete: (event)=>{
  41. }
  42. })
  43. })
  44. }