@lingxiteam/assets 0.7.30-alpha.30 → 0.7.30-alpha.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
2
 
3
3
  import { sha256 } from 'js-sha256';
4
+ import { obj2QueryString } from '../utils/url';
4
5
  var SIGN_KEY = process.env.LING_XI_HTTP_SIGN_KEY || 'zrT5bi2escXilaH1fs653uZiH9RWfzCS'; // 1、签名算法:
5
6
  // 通过对url、参数、秘钥拼接成字符串,然后对字符串使用算法SHA-256得到64个字符串,放到header, X-SIGN=XXXXXXX。
6
7
  // 2、签名字符串拼接规则:
@@ -31,9 +32,16 @@ export var createHttpSignStr = function createHttpSignStr(url, options) {
31
32
 
32
33
  var method = options.method,
33
34
  headers = options.headers,
34
- body = options.body; // 获取参数1: 接口名称
35
+ body = options.body,
36
+ search = options.search; // 获取参数1: 接口名称
35
37
 
36
- var apiName = url.split('?')[0].split('/').pop(); // 获取参数2: 请求头部参数
38
+ var mixUrl = url;
39
+
40
+ if (search && search instanceof Object) {
41
+ mixUrl += (url.indexOf('?') !== -1 ? '&' : '?') + obj2QueryString(search);
42
+ }
43
+
44
+ var apiName = mixUrl.split('?')[0].split('/').pop(); // 获取参数2: 请求头部参数
37
45
 
38
46
  var headerParams = '';
39
47
  var headersKeyArr = [];
@@ -47,7 +55,7 @@ export var createHttpSignStr = function createHttpSignStr(url, options) {
47
55
  var params = '';
48
56
 
49
57
  if (method.toLowerCase() === 'get') {
50
- params = url.split('?')[1] || '';
58
+ params = mixUrl.split('?')[1] || '';
51
59
  } else {
52
60
  params = _typeof(body) === 'object' ? JSON.stringify(body) : body;
53
61
  }
@@ -0,0 +1 @@
1
+ export declare const obj2QueryString: (params: any) => string;
@@ -0,0 +1,6 @@
1
+ export var obj2QueryString = function obj2QueryString(params) {
2
+ var queryString = Object.keys(params).map(function (key) {
3
+ return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(params[key]));
4
+ }).join('&');
5
+ return queryString;
6
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingxiteam/assets",
3
- "version": "0.7.30-alpha.30",
3
+ "version": "0.7.30-alpha.31",
4
4
  "description": "灵犀低代码平台移动端 - 工具类",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",