rexma-design 2.0.0 → 2.0.2
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.
- package/lib/XinhuaClient/ClientSign.d.ts +32 -0
- package/lib/XinhuaClient/ClientSign.js +117 -0
- package/lib/XinhuaClient/declaration.d.ts +29 -0
- package/lib/XinhuaClient/declaration.js +2 -0
- package/lib/XinhuaClient/index.d.ts +21 -0
- package/lib/XinhuaClient/index.js +203 -0
- package/lib/getValueFromUA/index.d.ts +5 -0
- package/lib/getValueFromUA/index.js +21 -0
- package/lib/index.js +10 -0
- package/package.json +5 -2
- package/.browserslistrc +0 -4
- package/src/packages/XinhuaClient/ClientSign.ts +0 -72
- package/src/packages/XinhuaClient/declaration.ts +0 -30
- package/src/packages/XinhuaClient/index.ts +0 -96
- package/src/packages/getValueFromUA/index.ts +0 -20
- /package/{src/packages/index.ts → lib/index.d.ts} +0 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { IXinhuaClientState } from './declaration';
|
|
2
|
+
declare type IGetClientSignParams = {
|
|
3
|
+
key: string;
|
|
4
|
+
offset: string;
|
|
5
|
+
moduleCode?: string;
|
|
6
|
+
developmentClientSign?: IXinhuaClientState['clientSign'];
|
|
7
|
+
};
|
|
8
|
+
declare type IAesDecryptParams = {
|
|
9
|
+
key: string;
|
|
10
|
+
offset: string;
|
|
11
|
+
};
|
|
12
|
+
declare class ClientSign {
|
|
13
|
+
/**
|
|
14
|
+
* ASE 解密
|
|
15
|
+
* 使用加密秘钥,对 需要解密的参数 进行解密
|
|
16
|
+
* @param content - 需要解密的参数
|
|
17
|
+
* @param params - 加密信息
|
|
18
|
+
*/
|
|
19
|
+
static aesDecryptParams(content: string, params: IAesDecryptParams): any;
|
|
20
|
+
/**
|
|
21
|
+
* 获取客户端签名
|
|
22
|
+
*/
|
|
23
|
+
static getClientSign(options: IGetClientSignParams): Promise<{
|
|
24
|
+
sign: string;
|
|
25
|
+
subDomain: string;
|
|
26
|
+
} | {
|
|
27
|
+
sign: any;
|
|
28
|
+
subDomain: any;
|
|
29
|
+
siteId: any;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
|
32
|
+
export default ClientSign;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
var crypto_js_1 = require("crypto-js");
|
|
43
|
+
var xinhua_sdk_1 = __importDefault(require("xinhua-sdk"));
|
|
44
|
+
var ClientSign = /** @class */ (function () {
|
|
45
|
+
function ClientSign() {
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* ASE 解密
|
|
49
|
+
* 使用加密秘钥,对 需要解密的参数 进行解密
|
|
50
|
+
* @param content - 需要解密的参数
|
|
51
|
+
* @param params - 加密信息
|
|
52
|
+
*/
|
|
53
|
+
Object.defineProperty(ClientSign, "aesDecryptParams", {
|
|
54
|
+
enumerable: false,
|
|
55
|
+
configurable: true,
|
|
56
|
+
writable: true,
|
|
57
|
+
value: function (content, params) {
|
|
58
|
+
var key = params.key, offset = params.offset;
|
|
59
|
+
if (!key || !offset) {
|
|
60
|
+
throw new Error('缺少加密相关配置');
|
|
61
|
+
}
|
|
62
|
+
// 密钥 - 从 UTF-8 编码 解析出原始字符串
|
|
63
|
+
var keyUTF8 = crypto_js_1.enc.Utf8.parse(key);
|
|
64
|
+
// 偏移量(在此公司内是固定的) - 从 UTF-8编码 解析出原始字符串
|
|
65
|
+
var offsetUTF8 = crypto_js_1.enc.Utf8.parse(offset);
|
|
66
|
+
var bytes = crypto_js_1.AES.decrypt(content, keyUTF8, {
|
|
67
|
+
iv: offsetUTF8,
|
|
68
|
+
mode: crypto_js_1.mode.CBC,
|
|
69
|
+
padding: crypto_js_1.pad.Pkcs7,
|
|
70
|
+
});
|
|
71
|
+
return bytes.toString(crypto_js_1.enc.Utf8);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
/**
|
|
75
|
+
* 获取客户端签名
|
|
76
|
+
*/
|
|
77
|
+
Object.defineProperty(ClientSign, "getClientSign", {
|
|
78
|
+
enumerable: false,
|
|
79
|
+
configurable: true,
|
|
80
|
+
writable: true,
|
|
81
|
+
value: function (options) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
83
|
+
var developmentClientSign, key, offset, moduleCode, clientSignInfo;
|
|
84
|
+
return __generator(this, function (_a) {
|
|
85
|
+
switch (_a.label) {
|
|
86
|
+
case 0:
|
|
87
|
+
developmentClientSign = options.developmentClientSign, key = options.key, offset = options.offset, moduleCode = options.moduleCode;
|
|
88
|
+
if (process.env.NODE_ENV === 'development' && developmentClientSign) {
|
|
89
|
+
return [2 /*return*/, developmentClientSign];
|
|
90
|
+
}
|
|
91
|
+
if (!xinhua_sdk_1.default.isMediaConvergenceXinhuaApp()) {
|
|
92
|
+
return [2 /*return*/, {
|
|
93
|
+
sign: '',
|
|
94
|
+
subDomain: '',
|
|
95
|
+
}];
|
|
96
|
+
}
|
|
97
|
+
return [4 /*yield*/, new Promise(function (resolve) {
|
|
98
|
+
xinhua_sdk_1.default.getClientSign({
|
|
99
|
+
moduleCode: moduleCode,
|
|
100
|
+
success: function (res) { return resolve(res); },
|
|
101
|
+
});
|
|
102
|
+
})];
|
|
103
|
+
case 1:
|
|
104
|
+
clientSignInfo = _a.sent();
|
|
105
|
+
return [2 /*return*/, {
|
|
106
|
+
sign: this.aesDecryptParams(clientSignInfo.cs, { key: key, offset: offset }),
|
|
107
|
+
subDomain: clientSignInfo.subDomain,
|
|
108
|
+
siteId: clientSignInfo.siteId,
|
|
109
|
+
}];
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
return ClientSign;
|
|
116
|
+
}());
|
|
117
|
+
exports.default = ClientSign;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare type IXinhuaClientState = {
|
|
2
|
+
/** 站点 id */
|
|
3
|
+
siteId: string;
|
|
4
|
+
/** 用户 id */
|
|
5
|
+
userId: string;
|
|
6
|
+
/** 状态栏高度 */
|
|
7
|
+
statusBarHeight: number;
|
|
8
|
+
/** 签名信息 */
|
|
9
|
+
clientSign: {
|
|
10
|
+
sign: string;
|
|
11
|
+
subDomain: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* 初始化方法参数
|
|
16
|
+
*/
|
|
17
|
+
export declare type IXinhuaClientInitOptions = {
|
|
18
|
+
clientSign: {
|
|
19
|
+
key: string;
|
|
20
|
+
offset: string;
|
|
21
|
+
moduleCode?: string;
|
|
22
|
+
};
|
|
23
|
+
/** 本地运行时的全局状态(仅浏览器环境生效) */
|
|
24
|
+
developmentState?: IXinhuaClientState;
|
|
25
|
+
/** 未登录时是否需要用户登录(useState 调用时生效) */
|
|
26
|
+
goLogin?: boolean;
|
|
27
|
+
/** 配置该项后,本地环境 developmentState 在客户端也生效 */
|
|
28
|
+
clientDebug?: boolean;
|
|
29
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { IXinhuaClientInitOptions, IXinhuaClientState } from './declaration';
|
|
2
|
+
declare class XinhuaClient {
|
|
3
|
+
/** 数据初始化是否完成 */
|
|
4
|
+
private static initStatus;
|
|
5
|
+
/** 站点 id */
|
|
6
|
+
private static state;
|
|
7
|
+
/** 初始化信息 */
|
|
8
|
+
private static initOptions;
|
|
9
|
+
static init(options: IXinhuaClientInitOptions): void;
|
|
10
|
+
private static stateInit;
|
|
11
|
+
/**
|
|
12
|
+
* 使用数据状态
|
|
13
|
+
*/
|
|
14
|
+
static useState(): Promise<IXinhuaClientState>;
|
|
15
|
+
/**
|
|
16
|
+
* 生成签名参数
|
|
17
|
+
*/
|
|
18
|
+
static getSignRequestParams(params: any): Promise<any>;
|
|
19
|
+
private constructor();
|
|
20
|
+
}
|
|
21
|
+
export default XinhuaClient;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
var js_md5_1 = require("js-md5");
|
|
54
|
+
var xinhua_sdk_1 = __importDefault(require("xinhua-sdk"));
|
|
55
|
+
var getValueFromUA_1 = __importDefault(require("../getValueFromUA"));
|
|
56
|
+
var ClientSign_1 = __importDefault(require("./ClientSign"));
|
|
57
|
+
var XinhuaClient = /** @class */ (function () {
|
|
58
|
+
function XinhuaClient() {
|
|
59
|
+
}
|
|
60
|
+
Object.defineProperty(XinhuaClient, "init", {
|
|
61
|
+
enumerable: false,
|
|
62
|
+
configurable: true,
|
|
63
|
+
writable: true,
|
|
64
|
+
value: function (options) {
|
|
65
|
+
this.initOptions = options;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
Object.defineProperty(XinhuaClient, "stateInit", {
|
|
69
|
+
enumerable: false,
|
|
70
|
+
configurable: true,
|
|
71
|
+
writable: true,
|
|
72
|
+
value: function () {
|
|
73
|
+
var _a;
|
|
74
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
75
|
+
var initOptions, isClientDebug, userInfo, numberStatusBarHeight, _b;
|
|
76
|
+
return __generator(this, function (_c) {
|
|
77
|
+
switch (_c.label) {
|
|
78
|
+
case 0:
|
|
79
|
+
initOptions = this.initOptions;
|
|
80
|
+
if (process.env.NODE_ENV === 'development' && initOptions.developmentState) {
|
|
81
|
+
// 本地开发、配置的本地开发环境的数据
|
|
82
|
+
this.state = __assign(__assign({}, this.state), initOptions.developmentState);
|
|
83
|
+
}
|
|
84
|
+
isClientDebug = process.env.NODE_ENV === 'development' && initOptions.clientDebug;
|
|
85
|
+
if (!(xinhua_sdk_1.default.isMediaConvergenceXinhuaApp() && !isClientDebug)) return [3 /*break*/, 3];
|
|
86
|
+
// 客户端环境
|
|
87
|
+
this.state.siteId = (0, getValueFromUA_1.default)('currentSiteId');
|
|
88
|
+
return [4 /*yield*/, new Promise(function (resolve) {
|
|
89
|
+
var _a;
|
|
90
|
+
xinhua_sdk_1.default.getUserInfo({
|
|
91
|
+
goLogin: (_a = initOptions.goLogin) !== null && _a !== void 0 ? _a : false,
|
|
92
|
+
success: function (res) { return resolve(res); },
|
|
93
|
+
});
|
|
94
|
+
})];
|
|
95
|
+
case 1:
|
|
96
|
+
userInfo = _c.sent();
|
|
97
|
+
this.state.userId = (_a = userInfo === null || userInfo === void 0 ? void 0 : userInfo.info) === null || _a === void 0 ? void 0 : _a.id;
|
|
98
|
+
numberStatusBarHeight = Number((0, getValueFromUA_1.default)('statusBarHeight'));
|
|
99
|
+
this.state.statusBarHeight = isNaN(numberStatusBarHeight) ? 0 : numberStatusBarHeight;
|
|
100
|
+
_b = this.state;
|
|
101
|
+
return [4 /*yield*/, ClientSign_1.default.getClientSign({
|
|
102
|
+
key: initOptions.clientSign.key,
|
|
103
|
+
offset: initOptions.clientSign.offset,
|
|
104
|
+
moduleCode: initOptions.clientSign.moduleCode,
|
|
105
|
+
})];
|
|
106
|
+
case 2:
|
|
107
|
+
_b.clientSign = _c.sent();
|
|
108
|
+
_c.label = 3;
|
|
109
|
+
case 3:
|
|
110
|
+
this.initStatus = true;
|
|
111
|
+
return [2 /*return*/];
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
/**
|
|
118
|
+
* 使用数据状态
|
|
119
|
+
*/
|
|
120
|
+
Object.defineProperty(XinhuaClient, "useState", {
|
|
121
|
+
enumerable: false,
|
|
122
|
+
configurable: true,
|
|
123
|
+
writable: true,
|
|
124
|
+
value: function () {
|
|
125
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
126
|
+
return __generator(this, function (_a) {
|
|
127
|
+
switch (_a.label) {
|
|
128
|
+
case 0:
|
|
129
|
+
if (!!this.initStatus) return [3 /*break*/, 2];
|
|
130
|
+
return [4 /*yield*/, this.stateInit()];
|
|
131
|
+
case 1:
|
|
132
|
+
_a.sent();
|
|
133
|
+
_a.label = 2;
|
|
134
|
+
case 2: return [2 /*return*/, this.state];
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
/**
|
|
141
|
+
* 生成签名参数
|
|
142
|
+
*/
|
|
143
|
+
Object.defineProperty(XinhuaClient, "getSignRequestParams", {
|
|
144
|
+
enumerable: false,
|
|
145
|
+
configurable: true,
|
|
146
|
+
writable: true,
|
|
147
|
+
value: function (params) {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
149
|
+
var requestParams, initialState, paramsArr;
|
|
150
|
+
return __generator(this, function (_a) {
|
|
151
|
+
switch (_a.label) {
|
|
152
|
+
case 0:
|
|
153
|
+
if (!!this.initStatus) return [3 /*break*/, 2];
|
|
154
|
+
return [4 /*yield*/, this.stateInit()];
|
|
155
|
+
case 1:
|
|
156
|
+
_a.sent();
|
|
157
|
+
_a.label = 2;
|
|
158
|
+
case 2:
|
|
159
|
+
requestParams = __assign({}, params), initialState = this.state;
|
|
160
|
+
if (initialState.userId) {
|
|
161
|
+
requestParams.userId = initialState.userId;
|
|
162
|
+
}
|
|
163
|
+
if (initialState.siteId) {
|
|
164
|
+
requestParams.siteId = initialState.siteId;
|
|
165
|
+
}
|
|
166
|
+
requestParams.currentTimeMillis = new Date().getTime();
|
|
167
|
+
if (initialState.clientSign && initialState.clientSign.sign) {
|
|
168
|
+
paramsArr = Object.values(requestParams);
|
|
169
|
+
paramsArr.push(initialState.clientSign.sign);
|
|
170
|
+
paramsArr.sort();
|
|
171
|
+
requestParams.signature = (0, js_md5_1.md5)(paramsArr.join(''));
|
|
172
|
+
}
|
|
173
|
+
return [2 /*return*/, requestParams];
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
/** 数据初始化是否完成 */
|
|
180
|
+
Object.defineProperty(XinhuaClient, "initStatus", {
|
|
181
|
+
enumerable: true,
|
|
182
|
+
configurable: true,
|
|
183
|
+
writable: true,
|
|
184
|
+
value: false
|
|
185
|
+
});
|
|
186
|
+
/** 站点 id */
|
|
187
|
+
Object.defineProperty(XinhuaClient, "state", {
|
|
188
|
+
enumerable: true,
|
|
189
|
+
configurable: true,
|
|
190
|
+
writable: true,
|
|
191
|
+
value: {
|
|
192
|
+
siteId: '',
|
|
193
|
+
userId: '',
|
|
194
|
+
statusBarHeight: 0,
|
|
195
|
+
clientSign: {
|
|
196
|
+
sign: '',
|
|
197
|
+
subDomain: '',
|
|
198
|
+
},
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
return XinhuaClient;
|
|
202
|
+
}());
|
|
203
|
+
exports.default = XinhuaClient;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* 从 ua 中根据 key 获取信息
|
|
5
|
+
*/
|
|
6
|
+
function getValueFromUA(name) {
|
|
7
|
+
var userAgent = window.navigator.userAgent;
|
|
8
|
+
var userAgentArr = userAgent.split(' ');
|
|
9
|
+
var uaValue = '';
|
|
10
|
+
if (userAgentArr) {
|
|
11
|
+
for (var index in userAgentArr) {
|
|
12
|
+
var item = userAgentArr[index];
|
|
13
|
+
if (item.startsWith(name + '/')) {
|
|
14
|
+
uaValue = item.split('/')[1];
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return uaValue;
|
|
20
|
+
}
|
|
21
|
+
exports.default = getValueFromUA;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.XinhuaClient = exports.getValueFromUA = void 0;
|
|
7
|
+
var getValueFromUA_1 = require("./getValueFromUA");
|
|
8
|
+
Object.defineProperty(exports, "getValueFromUA", { enumerable: true, get: function () { return __importDefault(getValueFromUA_1).default; } });
|
|
9
|
+
var XinhuaClient_1 = require("./XinhuaClient");
|
|
10
|
+
Object.defineProperty(exports, "XinhuaClient", { enumerable: true, get: function () { return __importDefault(XinhuaClient_1).default; } });
|
package/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rexma-design",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"start": "vue-cli-service serve",
|
|
6
6
|
"build": "vue-cli-service build",
|
|
7
|
+
"build:lib": "rm -rf lib && tsc --project tsconfig.lib.json",
|
|
7
8
|
"lint": "vue-cli-service lint",
|
|
8
9
|
"prepare": "husky install"
|
|
9
10
|
},
|
|
10
|
-
"
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"main": "lib/index.js",
|
|
13
|
+
"typings": "lib/index.d.ts",
|
|
11
14
|
"commitlint": {
|
|
12
15
|
"extends": [
|
|
13
16
|
"@commitlint/config-conventional"
|
package/.browserslistrc
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { AES, enc, mode, pad } from 'crypto-js';
|
|
2
|
-
import xh from 'xinhua-sdk';
|
|
3
|
-
import type { IXinhuaClientState } from './declaration';
|
|
4
|
-
|
|
5
|
-
type IGetClientSignParams = {
|
|
6
|
-
key: string;
|
|
7
|
-
offset: string;
|
|
8
|
-
moduleCode?: string;
|
|
9
|
-
developmentClientSign?: IXinhuaClientState['clientSign'];
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
type IAesDecryptParams = {
|
|
13
|
-
key: string;
|
|
14
|
-
offset: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
class ClientSign {
|
|
18
|
-
/**
|
|
19
|
-
* ASE 解密
|
|
20
|
-
* @description 使用加密秘钥,对 需要解密的参数 进行解密
|
|
21
|
-
* @param content - 需要解密的参数
|
|
22
|
-
* @param params - 加密信息
|
|
23
|
-
*/
|
|
24
|
-
static aesDecryptParams(content: string, params: IAesDecryptParams) {
|
|
25
|
-
const { key, offset } = params;
|
|
26
|
-
if (!key || !offset) {
|
|
27
|
-
throw new Error('缺少加密相关配置');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// 密钥 - 从 UTF-8 编码 解析出原始字符串
|
|
31
|
-
const keyUTF8 = enc.Utf8.parse(key);
|
|
32
|
-
// 偏移量(在此公司内是固定的) - 从 UTF-8编码 解析出原始字符串
|
|
33
|
-
const offsetUTF8 = enc.Utf8.parse(offset);
|
|
34
|
-
|
|
35
|
-
const bytes = AES.decrypt(content, keyUTF8, {
|
|
36
|
-
iv: offsetUTF8,
|
|
37
|
-
mode: mode.CBC,
|
|
38
|
-
padding: pad.Pkcs7,
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
return bytes.toString(enc.Utf8);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* D@description 获取客户端签名
|
|
46
|
-
*/
|
|
47
|
-
static async getClientSign(options: IGetClientSignParams) {
|
|
48
|
-
const { developmentClientSign, key, offset, moduleCode } = options;
|
|
49
|
-
if (process.env.NODE_ENV === 'development' && developmentClientSign) {
|
|
50
|
-
return developmentClientSign;
|
|
51
|
-
}
|
|
52
|
-
if (!xh.isMediaConvergenceXinhuaApp()) {
|
|
53
|
-
return {
|
|
54
|
-
sign: '',
|
|
55
|
-
subDomain: '',
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
const clientSignInfo: any = await new Promise((resolve) => {
|
|
59
|
-
xh.getClientSign({
|
|
60
|
-
moduleCode,
|
|
61
|
-
success: (res) => resolve(res),
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
return {
|
|
65
|
-
sign: this.aesDecryptParams(clientSignInfo.cs, { key, offset }),
|
|
66
|
-
subDomain: clientSignInfo.subDomain,
|
|
67
|
-
siteId: clientSignInfo.siteId,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export default ClientSign;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export type IXinhuaClientState = {
|
|
2
|
-
/** 站点 id */
|
|
3
|
-
siteId: string;
|
|
4
|
-
/** 用户 id */
|
|
5
|
-
userId: string;
|
|
6
|
-
/** 状态栏高度 */
|
|
7
|
-
statusBarHeight: number;
|
|
8
|
-
/** 签名信息 */
|
|
9
|
-
clientSign: {
|
|
10
|
-
sign: string;
|
|
11
|
-
subDomain: string;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @description 初始化方法参数
|
|
17
|
-
*/
|
|
18
|
-
export type IXinhuaClientInitOptions = {
|
|
19
|
-
clientSign: {
|
|
20
|
-
key: string;
|
|
21
|
-
offset: string;
|
|
22
|
-
moduleCode?: string;
|
|
23
|
-
};
|
|
24
|
-
/** 本地运行时的全局状态(仅浏览器环境生效) */
|
|
25
|
-
developmentState?: IXinhuaClientState;
|
|
26
|
-
/** 未登录时是否需要用户登录(useState 调用时生效) */
|
|
27
|
-
goLogin?: boolean;
|
|
28
|
-
/** 配置该项后,本地环境 developmentState 在客户端也生效 */
|
|
29
|
-
clientDebug?: boolean;
|
|
30
|
-
};
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { md5 } from 'js-md5';
|
|
2
|
-
import xh from 'xinhua-sdk';
|
|
3
|
-
import getValueFromUA from '../getValueFromUA';
|
|
4
|
-
import ClientSign from './ClientSign';
|
|
5
|
-
import type { IXinhuaClientInitOptions, IXinhuaClientState } from './declaration';
|
|
6
|
-
|
|
7
|
-
class XinhuaClient {
|
|
8
|
-
/** 数据初始化是否完成 */
|
|
9
|
-
private static initStatus: boolean = false;
|
|
10
|
-
/** 站点 id */
|
|
11
|
-
private static state: IXinhuaClientState = {
|
|
12
|
-
siteId: '',
|
|
13
|
-
userId: '',
|
|
14
|
-
statusBarHeight: 0,
|
|
15
|
-
clientSign: {
|
|
16
|
-
sign: '',
|
|
17
|
-
subDomain: '',
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
/** 初始化信息 */
|
|
21
|
-
private static initOptions: IXinhuaClientInitOptions;
|
|
22
|
-
|
|
23
|
-
static init(options: IXinhuaClientInitOptions) {
|
|
24
|
-
this.initOptions = options;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
private static async stateInit() {
|
|
28
|
-
const initOptions = this.initOptions;
|
|
29
|
-
if (process.env.NODE_ENV === 'development' && initOptions.developmentState) {
|
|
30
|
-
// 本地开发、配置的本地开发环境的数据
|
|
31
|
-
this.state = {
|
|
32
|
-
...this.state,
|
|
33
|
-
...initOptions.developmentState,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
const isClientDebug = process.env.NODE_ENV === 'development' && initOptions.clientDebug;
|
|
37
|
-
if (xh.isMediaConvergenceXinhuaApp() && !isClientDebug) {
|
|
38
|
-
// 客户端环境
|
|
39
|
-
this.state.siteId = getValueFromUA('currentSiteId');
|
|
40
|
-
const userInfo = await new Promise<any>((resolve) => {
|
|
41
|
-
xh.getUserInfo({
|
|
42
|
-
goLogin: initOptions.goLogin ?? false,
|
|
43
|
-
success: (res) => resolve(res),
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
this.state.userId = userInfo?.info?.id;
|
|
47
|
-
const numberStatusBarHeight = Number(getValueFromUA('statusBarHeight'));
|
|
48
|
-
this.state.statusBarHeight = isNaN(numberStatusBarHeight) ? 0 : numberStatusBarHeight;
|
|
49
|
-
this.state.clientSign = await ClientSign.getClientSign({
|
|
50
|
-
key: initOptions.clientSign.key,
|
|
51
|
-
offset: initOptions.clientSign.offset,
|
|
52
|
-
moduleCode: initOptions.clientSign.moduleCode,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
this.initStatus = true;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @description 使用数据状态
|
|
60
|
-
*/
|
|
61
|
-
static async useState() {
|
|
62
|
-
if (!this.initStatus) {
|
|
63
|
-
await this.stateInit();
|
|
64
|
-
}
|
|
65
|
-
return this.state;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* @@description 生成签名参数
|
|
70
|
-
*/
|
|
71
|
-
static async getSignRequestParams(params: any) {
|
|
72
|
-
if (!this.initStatus) {
|
|
73
|
-
await this.stateInit();
|
|
74
|
-
}
|
|
75
|
-
const requestParams = { ...params },
|
|
76
|
-
initialState = this.state;
|
|
77
|
-
if (initialState.userId) {
|
|
78
|
-
requestParams.userId = initialState.userId;
|
|
79
|
-
}
|
|
80
|
-
if (initialState.siteId) {
|
|
81
|
-
requestParams.siteId = initialState.siteId;
|
|
82
|
-
}
|
|
83
|
-
requestParams.currentTimeMillis = new Date().getTime();
|
|
84
|
-
if (initialState.clientSign && initialState.clientSign.sign) {
|
|
85
|
-
const paramsArr = Object.values(requestParams);
|
|
86
|
-
paramsArr.push(initialState.clientSign.sign);
|
|
87
|
-
paramsArr.sort();
|
|
88
|
-
requestParams.signature = md5(paramsArr.join(''));
|
|
89
|
-
}
|
|
90
|
-
return requestParams;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
private constructor() {}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export default XinhuaClient;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description 从 ua 中根据 key 获取信息
|
|
3
|
-
*/
|
|
4
|
-
function getValueFromUA(name: string) {
|
|
5
|
-
const userAgent = window.navigator.userAgent;
|
|
6
|
-
const userAgentArr = userAgent.split(' ');
|
|
7
|
-
let uaValue = '';
|
|
8
|
-
if (userAgentArr) {
|
|
9
|
-
for (let index in userAgentArr) {
|
|
10
|
-
const item = userAgentArr[index];
|
|
11
|
-
if (item.startsWith(name + '/')) {
|
|
12
|
-
uaValue = item.split('/')[1];
|
|
13
|
-
break;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return uaValue;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export default getValueFromUA;
|
|
File without changes
|