20261008
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
[{"code":"110000","name":"北京市"},{"code":"120000","name":"天津市"},{"code":"130000","name":"河北省"},{"code":"140000","name":"山西省"},{"code":"150000","name":"内蒙古自治区"},{"code":"210000","name":"辽宁省"},{"code":"220000","name":"吉林省"},{"code":"230000","name":"黑龙江省"},{"code":"310000","name":"上海市"},{"code":"320000","name":"江苏省"},{"code":"330000","name":"浙江省"},{"code":"340000","name":"安徽省"},{"code":"350000","name":"福建省"},{"code":"360000","name":"江西省"},{"code":"370000","name":"山东省"},{"code":"410000","name":"河南省"},{"code":"420000","name":"湖北省"},{"code":"430000","name":"湖南省"},{"code":"440000","name":"广东省"},{"code":"450000","name":"广西壮族自治区"},{"code":"460000","name":"海南省"},{"code":"500000","name":"重庆市"},{"code":"510000","name":"四川省"},{"code":"520000","name":"贵州省"},{"code":"530000","name":"云南省"},{"code":"540000","name":"西藏自治区"},{"code":"610000","name":"陕西省"},{"code":"620000","name":"甘肃省"},{"code":"630000","name":"青海省"},{"code":"640000","name":"宁夏回族自治区"},{"code":"650000","name":"新疆维吾尔自治区"},{"code":"710000","name":"台湾省"},{"code":"810000","name":"香港特别行政区"},{"code":"820000","name":"澳门特别行政区"}]
|
||||
+198
@@ -0,0 +1,198 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) {
|
||||
return value instanceof P ? value : new P(function (resolve) {
|
||||
resolve(value);
|
||||
});
|
||||
}
|
||||
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) {
|
||||
try {
|
||||
step(generator.next(value));
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
}
|
||||
|
||||
function rejected(value) {
|
||||
try {
|
||||
step(generator["throw"](value));
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
}
|
||||
|
||||
function step(result) {
|
||||
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
||||
}
|
||||
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", {value: true});
|
||||
const CryptoJS = require("crypto-js");
|
||||
const request = require("request");
|
||||
var AuthorizationType;
|
||||
(function (AuthorizationType) {
|
||||
AuthorizationType[AuthorizationType["OPEN-FORM-PARAM"] = 0] = "OPEN-FORM-PARAM";
|
||||
AuthorizationType[AuthorizationType["OPEN-BODY-SIG"] = 1] = "OPEN-BODY-SIG";
|
||||
AuthorizationType[AuthorizationType["OPEN-ACCESS-TOKEN"] = 2] = "OPEN-ACCESS-TOKEN";
|
||||
})(AuthorizationType || (AuthorizationType = {}));
|
||||
|
||||
/**
|
||||
* Open SDK for Node.JS
|
||||
*/
|
||||
class OpenSdk {
|
||||
/**
|
||||
* @class
|
||||
* @param {OpenSdkConfig} config 初始化 SDK 配置
|
||||
*/
|
||||
constructor(config) {
|
||||
if (!config.appId) {
|
||||
throw Error('config.appId is required');
|
||||
}
|
||||
if (!config.appKey) {
|
||||
throw Error('config.appKey is required');
|
||||
}
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成请求字符串
|
||||
* @param {QueryParams} params 请求参数
|
||||
* @return {string} 请求字符串
|
||||
*/
|
||||
generateSignature(params) {
|
||||
if (!AuthorizationType[params.authorization]) {
|
||||
params.authorization = AuthorizationType['OPEN-BODY-SIG'];
|
||||
}
|
||||
let content = JSON.stringify(params.content);
|
||||
if (params.authorization === AuthorizationType['OPEN-FORM-PARAM']) {
|
||||
console.log('here')
|
||||
let contentHash = CryptoJS.SHA256(content).toString();
|
||||
let signStr = this.config.appId + params.timestamp + params.nonce + contentHash;
|
||||
let signature = CryptoJS.HmacSHA256(signStr, this.config.appKey);
|
||||
let signatureStr = CryptoJS.enc.Base64.stringify(signature);
|
||||
return encodeURIComponent(signatureStr);
|
||||
// let str = `authorization=OPEN-FORM-PARAM&appId=${this.config.appId}×tamp=${params.timestamp}&nonce=${params.nonce}&content=${encodeURIComponent(content)}&signature=${signatureEncode}`;
|
||||
// console.log(str)
|
||||
// return str;
|
||||
}
|
||||
if (params.authorization === AuthorizationType['OPEN-BODY-SIG']) {
|
||||
let contentHash = CryptoJS.SHA256(content).toString();
|
||||
let signStr = this.config.appId + params.timestamp + params.nonce + contentHash;
|
||||
let signature = CryptoJS.HmacSHA256(signStr, this.config.appKey);
|
||||
let signatureStr = CryptoJS.enc.Base64.stringify(signature);
|
||||
return signatureStr;
|
||||
}
|
||||
if (params.authorization === AuthorizationType['OPEN-ACCESS-TOKEN']) {
|
||||
let signStr = this.config.appId + params.timestamp + params.nonce + this.config.appKey;
|
||||
let signatureStr = CryptoJS.SHA256(signStr).toString();
|
||||
return signatureStr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送请求
|
||||
* @param {QueryParams} params 请求参数
|
||||
* @return {Promise<OpenSdkCommonResult | string>} 请求执行结果
|
||||
*/
|
||||
exec(params) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (!params.queryUrl) {
|
||||
throw Error('params.queryUrl is required');
|
||||
}
|
||||
if (!params.nonce) {
|
||||
throw Error('params.nonce is required');
|
||||
}
|
||||
if (!params.timestamp) {
|
||||
throw Error('params.timestamp is required');
|
||||
}
|
||||
const str = this.generateSignature(params);
|
||||
const config = this.config;
|
||||
console.log(params, AuthorizationType['OPEN-FORM-PARAM'])
|
||||
if (params.authorization === AuthorizationType['OPEN-FORM-PARAM']) {
|
||||
const content = JSON.stringify(params.content);
|
||||
const Url = `${params.queryUrl}?authorization=OPEN-FORM-PARAM&appId=${this.config.appId}×tamp=${params.timestamp}&nonce=${params.nonce}&content=${encodeURIComponent(content)}&signature=${str}`
|
||||
return new Promise((resolve, reject) => {
|
||||
request.get(Url, {}, (error, _response, body) => {
|
||||
if (!error) {
|
||||
if (typeof (body) === 'object') {
|
||||
resolve(JSON.parse(body));
|
||||
} else {
|
||||
resolve(body);
|
||||
}
|
||||
}
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
if (params.authorization === AuthorizationType['OPEN-BODY-SIG']) {
|
||||
const Url = params.queryUrl;
|
||||
return new Promise((resolve, reject) => {
|
||||
request({
|
||||
url: Url,
|
||||
method: params.method ? params.method : "POST",
|
||||
headers: {
|
||||
"Authorization": `OPEN-BODY-SIG AppId="${config.appId}", Timestamp="${params.timestamp}", Nonce="${params.nonce}", Signature="${str}"`,
|
||||
},
|
||||
body: JSON.stringify(params.content),
|
||||
}, (error, _response, body) => {
|
||||
if (!error) {
|
||||
if (typeof (body) === 'object') {
|
||||
resolve(JSON.parse(body));
|
||||
} else {
|
||||
resolve(body);
|
||||
}
|
||||
}
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
if (params.authorization === AuthorizationType['OPEN-ACCESS-TOKEN']) {
|
||||
const Url = params.queryUrl;
|
||||
const token = yield new Promise((resolve, reject) => {
|
||||
request({
|
||||
url: 'https://test-api-open.chinaums.com/v1/token/access',
|
||||
method: params.method ? params.method : "POST",
|
||||
body: JSON.stringify({
|
||||
appId: config.appId,
|
||||
timestamp: params.timestamp,
|
||||
nonce: params.nonce,
|
||||
signMethod: 'SHA256',
|
||||
Signature: str
|
||||
})
|
||||
}, (error, _response, body) => {
|
||||
if (!error) {
|
||||
resolve(JSON.parse(body).accessToken);
|
||||
}
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
request({
|
||||
url: Url,
|
||||
method: params.method ? params.method : "POST",
|
||||
headers: {
|
||||
"Authorization": `OPEN-ACCESS-TOKEN AccessToken="${token}"`,
|
||||
},
|
||||
body: JSON.stringify(params.content),
|
||||
}, (error, _response, body) => {
|
||||
if (!error) {
|
||||
if (typeof (body) === 'object') {
|
||||
resolve(JSON.parse(body));
|
||||
} else {
|
||||
resolve(body);
|
||||
}
|
||||
}
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
exports.default = OpenSdk;
|
||||
//# sourceMappingURL=base.js.map
|
||||
@@ -0,0 +1,54 @@
|
||||
export const WRITE_INVOICE_TIME = ['付款当月(限20号之前付款,20号之后付款次月开票)', '付款后次月', '付款前']
|
||||
|
||||
export const INVOICE_TYPE = ['增值税专用发票13%', '增值税普通发票', '普通发票']
|
||||
|
||||
export const PROCESS_PAY_METHOD = ['预付', '货到验收后付款', '提货付全款', '信誉采购,货到签单后账期:', '其他付款方式']
|
||||
|
||||
export const USER_LEVEL = [
|
||||
{
|
||||
value: -1,
|
||||
label: '普通用户',
|
||||
},
|
||||
{
|
||||
value: 0,
|
||||
label: '认证用户',
|
||||
},
|
||||
{
|
||||
value: 1,
|
||||
label: '黄金VIP',
|
||||
},
|
||||
{
|
||||
value: 2,
|
||||
label: '铂金VIP',
|
||||
},
|
||||
{
|
||||
value: 3,
|
||||
label: '钻石VIP',
|
||||
},
|
||||
{
|
||||
value: 4,
|
||||
label: '实力厂家',
|
||||
},
|
||||
{
|
||||
value: 5,
|
||||
label: '实力加工厂',
|
||||
},
|
||||
{
|
||||
value: 6,
|
||||
label: '实力供货商',
|
||||
},
|
||||
{
|
||||
value: 7,
|
||||
label: '实力采购商',
|
||||
},
|
||||
];
|
||||
|
||||
export const getUserLevelLabel = (level) => {
|
||||
let label = '';
|
||||
USER_LEVEL.forEach(item => {
|
||||
if (item.value === level) {
|
||||
label = item.label;
|
||||
}
|
||||
});
|
||||
return label;
|
||||
}
|
||||
Reference in New Issue
Block a user