From 472942e93e2b98434c00cacc95260feef4dbd05f Mon Sep 17 00:00:00 2001 From: Changeden Date: Mon, 12 Apr 2021 15:23:19 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E4=BC=98=E5=8C=96sdk-nodejs=E4=BB=A5?= =?UTF-8?q?=E4=B8=8B=E5=8A=9F=E8=83=BD=EF=BC=9A=201=E3=80=81=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=90=8C=E6=AD=A5=E8=AF=B7=E6=B1=82=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=EF=BC=88executeSync=E3=80=81executeTokenSync=EF=BC=89=EF=BC=9B?= =?UTF-8?q?=202=E3=80=81=E4=BC=98=E5=8C=96=E8=AF=B7=E6=B1=82=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E4=B8=AD=E6=96=AD=E9=97=AE=E9=A2=98=EF=BC=8C=E8=BF=94?= =?UTF-8?q?=E5=9B=9E502=E9=94=99=E8=AF=AF=E7=A0=81=EF=BC=9B=203=E3=80=81?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=AD=BE=E5=90=8D=E6=96=B9=E6=B3=95=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sop-sdk/sdk-nodejs/common/OpenClient.js | 83 ++++++++++++++++++------- sop-sdk/sdk-nodejs/common/SignUtil.js | 23 +++---- sop-sdk/sdk-nodejs/main.js | 26 ++++++++ 3 files changed, 98 insertions(+), 34 deletions(-) diff --git a/sop-sdk/sdk-nodejs/common/OpenClient.js b/sop-sdk/sdk-nodejs/common/OpenClient.js index 3da27c36..38aae1bd 100644 --- a/sop-sdk/sdk-nodejs/common/OpenClient.js +++ b/sop-sdk/sdk-nodejs/common/OpenClient.js @@ -33,44 +33,75 @@ const OpenClient = Class.create({ /** * 发送请求 * @param request 请求类 - * @param callback 回调函数,参数json + * @param callback 回调函数,参数json(undefined则使用executeSync) */ execute: function (request, callback) { - this.executeToken(request, null, callback) + if (typeof callback == 'function') { + this.executeToken(request, null, callback) + } else { + return this.executeSync(request) + } + }, + /** + * 发送同步请求 + * @param request 请求类 + * */ + executeSync: function (request) { + return new Promise((resolve) => { + this.execute(request, res => { + resolve(res) + }) + }) }, /** * 发送请求 * @param request 请求类 * @param token token - * @param callback 回调函数,参数json + * @param callback 回调函数,参数json(undefined则使用executeTokenSync) */ executeToken: function (request, token, callback) { if (!(request instanceof BaseRequest)) { throw 'request类未继承BaseRequest' } - const requestType = request.getRequestType(); - if (request.files) { - this._postFile(request, callback); - } else { - switch (requestType) { - case RequestType.GET: - this._get(request, callback); - break - case RequestType.POST_FORM: - this._postForm(request, callback); - break - case RequestType.POST_JSON: - this._postJson(request, callback); - break - case RequestType.POST_FILE: - this._postFile(request, callback); - break - default :{ - throw 'request.getRequestType()类型不正确' + if (typeof callback == 'function') { + const requestType = request.getRequestType(); + if (request.files) { + this._postFile(request, callback); + } else { + switch (requestType) { + case RequestType.GET: + this._get(request, callback); + break + case RequestType.POST_FORM: + this._postForm(request, callback); + break + case RequestType.POST_JSON: + this._postJson(request, callback); + break + case RequestType.POST_FILE: + this._postFile(request, callback); + break + default : { + throw 'request.getRequestType()类型不正确' + } } } + } else { + return this.executeTokenSync(request, token) } }, + /** + * 发送同步请求 + * @param request 请求类 + * @param token token + */ + executeTokenSync: function (request, token) { + return new Promise((resolve) => { + this.executeToken(request, token, res => { + resolve(res) + }) + }) + }, _get: function(request, callback) { const allParams = this._buildParams(request) const that = this @@ -120,7 +151,13 @@ const OpenClient = Class.create({ if (!error && response.statusCode === 200) { return request.parseResponse(response.body) } else { - throw '请求异常:' + error + // throw '请求异常:' + error + return { // 重新封装请求异常回调,以防中断 + msg: '请求异常', + code: '502', + sub_msg: `${error}`, + sub_code: 'isv.invalid-server' + } } }, _buildParams: function (request, token) { diff --git a/sop-sdk/sdk-nodejs/common/SignUtil.js b/sop-sdk/sdk-nodejs/common/SignUtil.js index 03d757a6..d4300aba 100644 --- a/sop-sdk/sdk-nodejs/common/SignUtil.js +++ b/sop-sdk/sdk-nodejs/common/SignUtil.js @@ -68,21 +68,22 @@ exports.SignUtil = { */ getSignContent: function (params) { const paramNames = [] - for(const key in params) { - paramNames.push(key) - } + // 获取对象中的Key + paramNames.push(...Object.keys(params || {}) + // 过滤无效的KeyValue + .filter(paramName => { + // 参数名不为undefined且参数值不为undefined + return !(typeof paramName === undefined || typeof params[paramName] === undefined) + })) paramNames.sort() - const paramNameValue = [] - - for (let i = 0, len = paramNames.length; i < len; i++) { - const paramName = paramNames[i]; + // 合成签名字符串 + const paramNameValue = paramNames.map(paramName => { const val = params[paramName]; - if (paramName && val) { - paramNameValue.push(`${paramName}=${val}`) - } - } + return `${paramName}=${val}` + }) + return paramNameValue.join('&') } } diff --git a/sop-sdk/sdk-nodejs/main.js b/sop-sdk/sdk-nodejs/main.js index f8d8987e..6d9a2370 100644 --- a/sop-sdk/sdk-nodejs/main.js +++ b/sop-sdk/sdk-nodejs/main.js @@ -30,6 +30,7 @@ function test() { // ] openClient.execute(request, data => { + console.log('异步请求') // 成功 if (!data.sub_code) { console.log('成功', data); @@ -37,6 +38,31 @@ function test() { console.error('失败', data) } }) + + // 使用Promise进行封装 + openClient.executeSync(request).then(data => { + console.log('同步请求-Promise') + // 成功 + if (!data.sub_code) { + console.log('成功', data); + } else { + console.error('失败', data) + } + }) + + // 使用Async/Await进行封装 + async function syncRequest () { + const data = await openClient.execute(request) + console.log('同步请求-Async/Await') + // 成功 + if (!data.sub_code) { + console.log('成功', data); + } else { + console.error('失败', data) + } + } + + syncRequest() } From e1b860c75a435722fece80f7449a32957d9a5f8b Mon Sep 17 00:00:00 2001 From: Changeden Date: Mon, 12 Apr 2021 15:42:52 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E4=BC=98=E5=8C=96sdk-nodejs=E4=BB=A5?= =?UTF-8?q?=E4=B8=8B=E5=8A=9F=E8=83=BD=EF=BC=9A=201=E3=80=81=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=90=8C=E6=AD=A5=E8=AF=B7=E6=B1=82=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=EF=BC=88executeSync=E3=80=81executeTokenSync=EF=BC=89=EF=BC=9B?= =?UTF-8?q?=202=E3=80=81=E4=BC=98=E5=8C=96=E8=AF=B7=E6=B1=82=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E4=B8=AD=E6=96=AD=E9=97=AE=E9=A2=98=EF=BC=8C=E8=BF=94?= =?UTF-8?q?=E5=9B=9E502=E9=94=99=E8=AF=AF=E7=A0=81=EF=BC=9B=203=E3=80=81?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=AD=BE=E5=90=8D=E6=96=B9=E6=B3=95=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sop-sdk/sdk-nodejs/common/Class.js | 3 +- sop-sdk/sdk-nodejs/common/OpenClient.js | 132 +++++++++--------- sop-sdk/sdk-nodejs/common/RequestType.js | 2 +- sop-sdk/sdk-nodejs/common/SignUtil.js | 56 ++++---- sop-sdk/sdk-nodejs/main.js | 40 +++--- sop-sdk/sdk-nodejs/request/BaseRequest.js | 20 +-- sop-sdk/sdk-nodejs/request/StoryGetRequest.js | 16 +-- sop-sdk/sdk-nodejs/testClass.js | 24 ++-- 8 files changed, 146 insertions(+), 147 deletions(-) diff --git a/sop-sdk/sdk-nodejs/common/Class.js b/sop-sdk/sdk-nodejs/common/Class.js index e066def1..6068fc48 100644 --- a/sop-sdk/sdk-nodejs/common/Class.js +++ b/sop-sdk/sdk-nodejs/common/Class.js @@ -70,7 +70,7 @@ exports.Class = (function () { // Copy the properties over onto the new prototype for (var name in prop) { // Check if we're overwriting an existing function - prototype[name] = typeof prop[name] == "function" && typeof _super[name] == "function" && fnTest.test(prop[name]) ? (function (name, fn) { + prototype[name] = typeof prop[name] == 'function' && typeof _super[name] == 'function' && fnTest.test(prop[name]) ? (function (name, fn) { return function () { var tmp = this._super; @@ -107,7 +107,6 @@ exports.Class = (function () { };// ------Class Creation end------ - return { /** * 创建一个类 diff --git a/sop-sdk/sdk-nodejs/common/OpenClient.js b/sop-sdk/sdk-nodejs/common/OpenClient.js index 38aae1bd..df758669 100644 --- a/sop-sdk/sdk-nodejs/common/OpenClient.js +++ b/sop-sdk/sdk-nodejs/common/OpenClient.js @@ -1,22 +1,22 @@ -const needle = require('needle') -const moment = require('moment') +const needle = require('needle'); +const moment = require('moment'); -const {Class} = require("./Class"); -const {RequestType} = require('./RequestType') -const {SignUtil} = require('./SignUtil') -const {BaseRequest} = require('../request/BaseRequest') +const {Class} = require('./Class'); +const {RequestType} = require('./RequestType'); +const {SignUtil} = require('./SignUtil'); +const {BaseRequest} = require('../request/BaseRequest'); -const HEADERS = {'Accept-Encoding': 'identity'} +const HEADERS = {'Accept-Encoding': 'identity'}; const getHeaders = function (headers) { if (!headers) { - return HEADERS + return HEADERS; } for (const key in HEADERS) { headers[key] = HEADERS[key]; } - return headers -} + return headers; +}; const OpenClient = Class.create({ /** @@ -36,11 +36,11 @@ const OpenClient = Class.create({ * @param callback 回调函数,参数json(undefined则使用executeSync) */ execute: function (request, callback) { - if (typeof callback == 'function') { - this.executeToken(request, null, callback) - } else { - return this.executeSync(request) - } + if (typeof callback == 'function') { + this.executeToken(request, null, callback); + } else { + return this.executeSync(request); + } }, /** * 发送同步请求 @@ -49,9 +49,9 @@ const OpenClient = Class.create({ executeSync: function (request) { return new Promise((resolve) => { this.execute(request, res => { - resolve(res) - }) - }) + resolve(res); + }); + }); }, /** * 发送请求 @@ -61,7 +61,7 @@ const OpenClient = Class.create({ */ executeToken: function (request, token, callback) { if (!(request instanceof BaseRequest)) { - throw 'request类未继承BaseRequest' + throw 'request类未继承BaseRequest'; } if (typeof callback == 'function') { const requestType = request.getRequestType(); @@ -71,85 +71,85 @@ const OpenClient = Class.create({ switch (requestType) { case RequestType.GET: this._get(request, callback); - break + break; case RequestType.POST_FORM: this._postForm(request, callback); - break + break; case RequestType.POST_JSON: this._postJson(request, callback); - break + break; case RequestType.POST_FILE: this._postFile(request, callback); - break + break; default : { - throw 'request.getRequestType()类型不正确' + throw 'request.getRequestType()类型不正确'; } } } } else { - return this.executeTokenSync(request, token) + return this.executeTokenSync(request, token); } }, - /** - * 发送同步请求 - * @param request 请求类 - * @param token token - */ + /** + * 发送同步请求 + * @param request 请求类 + * @param token token + */ executeTokenSync: function (request, token) { - return new Promise((resolve) => { - this.executeToken(request, token, res => { - resolve(res) - }) - }) + return new Promise((resolve) => { + this.executeToken(request, token, res => { + resolve(res); + }); + }); }, - _get: function(request, callback) { - const allParams = this._buildParams(request) - const that = this + _get: function (request, callback) { + const allParams = this._buildParams(request); + const that = this; // needle.request(method, url, data[, options][, callback]) - needle.request('GET',this.url, allParams, { + needle.request('GET', this.url, allParams, { headers: getHeaders() - }, function(error, response) { - callback(that._parseResponse(error, response, request)) + }, function (error, response) { + callback(that._parseResponse(error, response, request)); }); }, _postForm: function (request, callback) { - const allParams = this._buildParams(request) - const that = this - needle.request('POST',this.url, allParams, { + const allParams = this._buildParams(request); + const that = this; + needle.request('POST', this.url, allParams, { headers: getHeaders({ 'Content-Type': 'application/x-www-form-urlencoded' }) - }, function(error, response) { - callback(that._parseResponse(error, response, request)) + }, function (error, response) { + callback(that._parseResponse(error, response, request)); }); }, _postJson: function (request, callback) { - const allParams = this._buildParams(request) - const that = this - needle.request('POST',this.url, allParams, { + const allParams = this._buildParams(request); + const that = this; + needle.request('POST', this.url, allParams, { headers: getHeaders(), json: true - }, function(error, response) { - callback(that._parseResponse(error, response, request)) + }, function (error, response) { + callback(that._parseResponse(error, response, request)); }); }, _postFile: function (request, callback) { - const allParams = this._buildParams(request) + const allParams = this._buildParams(request); const files = request.files; files.forEach(row => { // 设置成{ file: row.path, content_type: 'application/octet-stream' }格式 // needle会认为是上传文件 - allParams[row.name] = { file: row.path, content_type: 'application/octet-stream' } - }) - const that = this - needle.request('POST',this.url, allParams, { + allParams[row.name] = {file: row.path, content_type: 'application/octet-stream'}; + }); + const that = this; + needle.request('POST', this.url, allParams, { headers: getHeaders(), multipart: true - }, function(error, response) { - callback(that._parseResponse(error, response, request)) + }, function (error, response) { + callback(that._parseResponse(error, response, request)); }); }, _parseResponse: function (error, response, request) { if (!error && response.statusCode === 200) { - return request.parseResponse(response.body) + return request.parseResponse(response.body); } else { // throw '请求异常:' + error return { // 重新封装请求异常回调,以防中断 @@ -157,7 +157,7 @@ const OpenClient = Class.create({ code: '502', sub_msg: `${error}`, sub_code: 'isv.invalid-server' - } + }; } }, _buildParams: function (request, token) { @@ -169,16 +169,16 @@ const OpenClient = Class.create({ 'timestamp': moment().format('YYYY-MM-DD HH:mm:ss'), 'version': request.getVersion(), 'biz_content': JSON.stringify(request.bizModel) - } + }; if (token) { - allParams['app_auth_token'] = token + allParams['app_auth_token'] = token; } // 创建签名 - const sign = SignUtil.createSign(allParams, this.privateKey, 'RSA2') - allParams.sign = sign + const sign = SignUtil.createSign(allParams, this.privateKey, 'RSA2'); + allParams.sign = sign; return allParams; } -}) +}); -module.exports = OpenClient +module.exports = OpenClient; diff --git a/sop-sdk/sdk-nodejs/common/RequestType.js b/sop-sdk/sdk-nodejs/common/RequestType.js index e64db59d..717d99f5 100644 --- a/sop-sdk/sdk-nodejs/common/RequestType.js +++ b/sop-sdk/sdk-nodejs/common/RequestType.js @@ -3,4 +3,4 @@ exports.RequestType = { POST_FORM: 'POST_FORM', POST_JSON: 'POST_JSON', POST_FILE: 'POST_FILE' -} +}; diff --git a/sop-sdk/sdk-nodejs/common/SignUtil.js b/sop-sdk/sdk-nodejs/common/SignUtil.js index d4300aba..4c141676 100644 --- a/sop-sdk/sdk-nodejs/common/SignUtil.js +++ b/sop-sdk/sdk-nodejs/common/SignUtil.js @@ -1,12 +1,12 @@ -const {KJUR, hextob64} = require('jsrsasign') +const {KJUR, hextob64} = require('jsrsasign'); const HashMap = { SHA256withRSA: 'SHA256withRSA', SHA1withRSA: 'SHA1withRSA' -} +}; -const PEM_BEGIN = '-----BEGIN PRIVATE KEY-----\n' -const PEM_END = '\n-----END PRIVATE KEY-----' +const PEM_BEGIN = '-----BEGIN PRIVATE KEY-----\n'; +const PEM_END = '\n-----END PRIVATE KEY-----'; /** * rsa签名参考:https://www.jianshu.com/p/145eab95322c @@ -20,16 +20,16 @@ exports.SignUtil = { * @returns 返回签名内容 */ createSign(params, privateKey, signType) { - const content = this.getSignContent(params) - return this.sign(content, privateKey, signType) + const content = this.getSignContent(params); + return this.sign(content, privateKey, signType); }, sign: function (content, privateKey, signType) { if (signType.toUpperCase() === 'RSA') { - return this.rsaSign(content, privateKey, HashMap.SHA1withRSA) + return this.rsaSign(content, privateKey, HashMap.SHA1withRSA); } else if (signType.toUpperCase() === 'RSA2') { - return this.rsaSign(content, privateKey, HashMap.SHA256withRSA) + return this.rsaSign(content, privateKey, HashMap.SHA256withRSA); } else { - throw 'signType错误' + throw 'signType错误'; } }, /** @@ -40,26 +40,26 @@ exports.SignUtil = { * @returns 返回签名字符串,base64 */ rsaSign: function (content, privateKey, hash) { - privateKey = this._formatKey(privateKey) + privateKey = this._formatKey(privateKey); // 创建 Signature 对象 const signature = new KJUR.crypto.Signature({ alg: hash, //!这里指定 私钥 pem! prvkeypem: privateKey - }) - signature.updateString(content) - const signData = signature.sign() + }); + signature.updateString(content); + const signData = signature.sign(); // 将内容转成base64 - return hextob64(signData) + return hextob64(signData); }, _formatKey: function (key) { if (!key.startsWith(PEM_BEGIN)) { - key = PEM_BEGIN + key + key = PEM_BEGIN + key; } if (!key.endsWith(PEM_END)) { - key = key + PEM_END + key = key + PEM_END; } - return key + return key; }, /** * 获取签名内容 @@ -67,23 +67,23 @@ exports.SignUtil = { * @returns {string} */ getSignContent: function (params) { - const paramNames = [] + const paramNames = []; // 获取对象中的Key paramNames.push(...Object.keys(params || {}) - // 过滤无效的KeyValue - .filter(paramName => { - // 参数名不为undefined且参数值不为undefined - return !(typeof paramName === undefined || typeof params[paramName] === undefined) - })) + // 过滤无效的KeyValue + .filter(paramName => { + // 参数名不为undefined且参数值不为undefined + return !(typeof paramName === undefined || typeof params[paramName] === undefined); + })); - paramNames.sort() + paramNames.sort(); // 合成签名字符串 const paramNameValue = paramNames.map(paramName => { const val = params[paramName]; - return `${paramName}=${val}` - }) + return `${paramName}=${val}`; + }); - return paramNameValue.join('&') + return paramNameValue.join('&'); } -} +}; diff --git a/sop-sdk/sdk-nodejs/main.js b/sop-sdk/sdk-nodejs/main.js index 6d9a2370..d4dcd3e5 100644 --- a/sop-sdk/sdk-nodejs/main.js +++ b/sop-sdk/sdk-nodejs/main.js @@ -1,26 +1,26 @@ -const OpenClient = require('./common/OpenClient') +const OpenClient = require('./common/OpenClient'); -const {StoryGetRequest} = require('./request/StoryGetRequest') +const {StoryGetRequest} = require('./request/StoryGetRequest'); // 应用ID -const appId = '2019032617262200001' +const appId = '2019032617262200001'; // 应用私钥,2048位,PKCS8 -const privateKey = 'MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXJv1pQFqWNA/++OYEV7WYXwexZK/J8LY1OWlP9X0T6wHFOvxNKRvMkJ5544SbgsJpVcvRDPrcxmhPbi/sAhdO4x2PiPKIz9Yni2OtYCCeaiE056B+e1O2jXoLeXbfi9fPivJZkxH/tb4xfLkH3bA8ZAQnQsoXA0SguykMRZntF0TndUfvDrLqwhlR8r5iRdZLB6F8o8qXH6UPDfNEnf/K8wX5T4EB1b8x8QJ7Ua4GcIUqeUxGHdQpzNbJdaQvoi06lgccmL+PHzminkFYON7alj1CjDN833j7QMHdPtS9l7B67fOU/p2LAAkPMtoVBfxQt9aFj7B8rEhGCz02iJIBAgMBAAECggEARqOuIpY0v6WtJBfmR3lGIOOokLrhfJrGTLF8CiZMQha+SRJ7/wOLPlsH9SbjPlopyViTXCuYwbzn2tdABigkBHYXxpDV6CJZjzmRZ+FY3S/0POlTFElGojYUJ3CooWiVfyUMhdg5vSuOq0oCny53woFrf32zPHYGiKdvU5Djku1onbDU0Lw8w+5tguu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gQCqYbeec56LAhWP903Zwcj9VvG7sESqXUhIkUqoOkuIBTWFFIm54QLTA1tJxDQGb98heoCIWf5x/A3xNI98RsqNBX5JON6qNWjb7/dobitti3t99v/ptDp9u8JTMC7penoryLKK0Ty3bkan95Kn9SC42YxaSghzqkt+uvfVQgiNGQKBgGxU6P2aDAt6VNwWosHSe+d2WWXt8IZBhO9d6dn0f7ORvcjmCqNKTNGgrkewMZEuVcliueJquR47IROdY8qmwqcBAN7Vg2K7r7CPlTKAWTRYMJxCT1Hi5gwJb+CZF3+IeYqsJk2NF2s0w5WJTE70k1BSvQsfIzAIDz2yE1oPHvwVAoGAA6e+xQkVH4fMEph55RJIZ5goI4Y76BSvt2N5OKZKd4HtaV+eIhM3SDsVYRLIm9ZquJHMiZQGyUGnsvrKL6AAVNK7eQZCRDk9KQz+0GKOGqku0nOZjUbAu6A2/vtXAaAuFSFx1rUQVVjFulLexkXR3KcztL1Qu2k5pB6Si0K/uwQ='; // 接口url -const url = 'http://localhost:8081' +const url = 'http://localhost:8081'; // 创建客户端 -const openClient = new OpenClient(appId, privateKey, url) +const openClient = new OpenClient(appId, privateKey, url); function test() { // 创建请求 - const request = new StoryGetRequest() + const request = new StoryGetRequest(); // 设置业务参数 request.bizModel = { id: 111, name: 'jim' - } + }; // 添加上传文件 // request.files = [ @@ -30,41 +30,41 @@ function test() { // ] openClient.execute(request, data => { - console.log('异步请求') + console.log('异步请求'); // 成功 if (!data.sub_code) { console.log('成功', data); } else { - console.error('失败', data) + console.error('失败', data); } - }) + }); // 使用Promise进行封装 openClient.executeSync(request).then(data => { - console.log('同步请求-Promise') + console.log('同步请求-Promise'); // 成功 if (!data.sub_code) { console.log('成功', data); } else { - console.error('失败', data) + console.error('失败', data); } - }) + }); // 使用Async/Await进行封装 - async function syncRequest () { - const data = await openClient.execute(request) - console.log('同步请求-Async/Await') + async function syncRequest() { + const data = await openClient.execute(request); + console.log('同步请求-Async/Await'); // 成功 if (!data.sub_code) { console.log('成功', data); } else { - console.error('失败', data) + console.error('失败', data); } } - syncRequest() + syncRequest(); } -test() +test(); diff --git a/sop-sdk/sdk-nodejs/request/BaseRequest.js b/sop-sdk/sdk-nodejs/request/BaseRequest.js index 7720828b..53c36f2f 100644 --- a/sop-sdk/sdk-nodejs/request/BaseRequest.js +++ b/sop-sdk/sdk-nodejs/request/BaseRequest.js @@ -1,35 +1,35 @@ -const {Class} = require("../common/Class"); +const {Class} = require('../common/Class'); /** * 请求类父类 */ exports.BaseRequest = Class.create({ - init: function(){ - this.bizModel = {} + init: function () { + this.bizModel = {}; /* [ {name: 'file1', path: 'd:/dd/1.txt'}, {name: 'file2', path: 'd:/dd/2.txt'} ] */ - this.files = [] + this.files = []; }, /** * 返回接口名称 */ - getMethod: function() { + getMethod: function () { throw `未实现BaseRequest类getMethod()方法`; }, /** * 返回版本号 */ - getVersion: function() { + getVersion: function () { throw '未实现BaseRequest类getVersion()方法'; }, /** * 返回请求类型,使用RequestType.js */ - getRequestType: function() { + getRequestType: function () { throw '未实现BaseRequest类getRequestType()方法'; }, /** @@ -40,9 +40,9 @@ exports.BaseRequest = Class.create({ parseResponse: function (responseData) { let data = responseData['error_response']; if (!data) { - const dataNodeName = this.getMethod().replace(/\./g, '_') + '_response' - data = responseData[dataNodeName] + const dataNodeName = this.getMethod().replace(/\./g, '_') + '_response'; + data = responseData[dataNodeName]; } return data; } -}) +}); diff --git a/sop-sdk/sdk-nodejs/request/StoryGetRequest.js b/sop-sdk/sdk-nodejs/request/StoryGetRequest.js index fb66c2f6..ea5f51bb 100644 --- a/sop-sdk/sdk-nodejs/request/StoryGetRequest.js +++ b/sop-sdk/sdk-nodejs/request/StoryGetRequest.js @@ -1,6 +1,6 @@ -const {Class} = require("../common/Class"); -const {RequestType} = require("../common/RequestType"); -const {BaseRequest} = require('./BaseRequest') +const {Class} = require('../common/Class'); +const {RequestType} = require('../common/RequestType'); +const {BaseRequest} = require('./BaseRequest'); /** * 创建一个请求类,继承BaseRequest,重写三个函数 @@ -8,15 +8,15 @@ const {BaseRequest} = require('./BaseRequest') const StoryGetRequest = Class.create({ getMethod: function () { - return "story.get" + return 'story.get'; }, getVersion: function () { - return "1.0" + return '1.0'; }, getRequestType: function () { - return RequestType.GET + return RequestType.GET; } -}, BaseRequest) // 继承BaseRequest +}, BaseRequest); // 继承BaseRequest -module.exports.StoryGetRequest = StoryGetRequest +module.exports.StoryGetRequest = StoryGetRequest; diff --git a/sop-sdk/sdk-nodejs/testClass.js b/sop-sdk/sdk-nodejs/testClass.js index 0e2fe2a8..866fe62a 100644 --- a/sop-sdk/sdk-nodejs/testClass.js +++ b/sop-sdk/sdk-nodejs/testClass.js @@ -3,7 +3,7 @@ * 运行:node testClass.js */ -const {Class} = require('./common/Class') +const {Class} = require('./common/Class'); function testClass() { //------------------------- @@ -14,39 +14,39 @@ function testClass() { // 创建一个父类 var Person = Class.create({ // 构造函数 - init:function(option){ + init: function (option) { this.name = option.name; } - ,getName:function() { + , getName: function () { return this.name; } }); // 声明类实例 - var Jim = new Person({name:'Jim'}); - console.log('Jim name:' + Jim.getName()) + var Jim = new Person({name: 'Jim'}); + console.log('Jim name:' + Jim.getName()); //例子2:------------------------- // 创建一个类,继承Person类,并重写getName var Man = Class.create({ - init:function(option) { + init: function (option) { this._super(option);// 调用父类构造函数 this.age = option.age; } // 重写父类方法 - ,getName:function() { + , getName: function () { // 调用父类的getName() var name = this._super(); - return '我重写了getName方法:{'+name+'}'; + return '我重写了getName方法:{' + name + '}'; } - },Person); + }, Person); - var man = new Man({name:'Tom',age:22}); - console.log('man name:' + man.getName()) + var man = new Man({name: 'Tom', age: 22}); + console.log('man name:' + man.getName()); console.log('Jim instanceof Person: ' + (Jim instanceof Person)); console.log('man instanceof Person: ' + (man instanceof Person)); } -testClass() +testClass(); From aaef05525ef97f9401da00983917f7494bfe29c6 Mon Sep 17 00:00:00 2001 From: Changeden Date: Mon, 12 Apr 2021 15:45:49 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E4=BC=98=E5=8C=96sdk-nodejs=E4=BB=A5?= =?UTF-8?q?=E4=B8=8B=E5=8A=9F=E8=83=BD=EF=BC=9A=201=E3=80=81=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=90=8C=E6=AD=A5=E8=AF=B7=E6=B1=82=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=EF=BC=88executeSync=E3=80=81executeTokenSync=EF=BC=89=EF=BC=9B?= =?UTF-8?q?=202=E3=80=81=E4=BC=98=E5=8C=96=E8=AF=B7=E6=B1=82=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E4=B8=AD=E6=96=AD=E9=97=AE=E9=A2=98=EF=BC=8C=E8=BF=94?= =?UTF-8?q?=E5=9B=9E502=E9=94=99=E8=AF=AF=E7=A0=81=EF=BC=9B=203=E3=80=81?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=AD=BE=E5=90=8D=E6=96=B9=E6=B3=95=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sop-sdk/sdk-nodejs/common/OpenClient.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sop-sdk/sdk-nodejs/common/OpenClient.js b/sop-sdk/sdk-nodejs/common/OpenClient.js index df758669..2397021c 100644 --- a/sop-sdk/sdk-nodejs/common/OpenClient.js +++ b/sop-sdk/sdk-nodejs/common/OpenClient.js @@ -81,7 +81,7 @@ const OpenClient = Class.create({ case RequestType.POST_FILE: this._postFile(request, callback); break; - default : { + default: { throw 'request.getRequestType()类型不正确'; } } From 4055210942c334c80c8fa52bf5ab23f8c2211153 Mon Sep 17 00:00:00 2001 From: tanghc Date: Tue, 13 Apr 2021 17:46:23 +0800 Subject: [PATCH 4/7] UPDATE --- docker-build.sh | 2 +- docker-entrypoint.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-build.sh b/docker-build.sh index e9aa01f0..fc020067 100644 --- a/docker-build.sh +++ b/docker-build.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # 打包 mvn clean package diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 73b6894c..e0b60768 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh JAVA_OPTS="-Xms128m -Xmx128m" From 2d8948fd5a1eae5ce2fd854a8d67a8589ab58f7f Mon Sep 17 00:00:00 2001 From: tanghc Date: Tue, 13 Apr 2021 17:56:14 +0800 Subject: [PATCH 5/7] UPDATE --- doc/docs/files/10080_使用签名校验工具.md | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/doc/docs/files/10080_使用签名校验工具.md b/doc/docs/files/10080_使用签名校验工具.md index 459b0eb0..26c13dea 100644 --- a/doc/docs/files/10080_使用签名校验工具.md +++ b/doc/docs/files/10080_使用签名校验工具.md @@ -13,14 +13,7 @@ SOP默认签名算法仿照的是支付宝开放平台,因此我们可以使 ![示例图](https://gw.alipayobjects.com/zos/skylark/6dbc42cc-6b9b-4691-83f1-e7b875e1a602/2018/png/e6b725d0-8257-4a71-b7a0-f5479c9d43d0.png) -公钥给到开放平台,打开sop-gateway项目中的`ZuulConfig.java`,复制公钥 - -```java -appSecretStore.put(应用ID, 公钥内容); -``` - -- 应用ID(app_id):建议个格式为`yyyyMMddHHmmss+自增ID`,如2019032617262200001 -- 公钥内容:刚刚生成的公钥字符串 +sop-admin创建一个新ISV,将公私钥放入对应文本框中,保存。 接着私钥放入客户端进行调用。参见AlipayClientPostTest类 From 4fe912ab5814d37da993f263a4eb6406c4682771 Mon Sep 17 00:00:00 2001 From: tanghc Date: Tue, 13 Apr 2021 20:39:17 +0800 Subject: [PATCH 6/7] fix #I3IMEH --- sop-mysql5.6以下版本.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sop-mysql5.6以下版本.sql b/sop-mysql5.6以下版本.sql index 2b76307c..3702d176 100644 --- a/sop-mysql5.6以下版本.sql +++ b/sop-mysql5.6以下版本.sql @@ -232,8 +232,8 @@ CREATE TABLE `monitor_info` ( `total_request_count` bigint(20) NOT NULL DEFAULT '0' COMMENT '总调用次数', `success_count` bigint(20) NOT NULL DEFAULT '0' COMMENT '成功次数', `error_count` bigint(20) NOT NULL DEFAULT '0' COMMENT '失败次数(业务主动抛出的异常算作成功,如参数校验,未知的错误算失败)', - `gmt_create` datetime DEFAULT DEFAULT NULL, - `gmt_modified` datetime DEFAULT DEFAULT NULL, + `gmt_create` datetime DEFAULT NULL, + `gmt_modified` datetime DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `uk_routeid` (`route_id`,`instance_id`) USING BTREE, KEY `idex_name` (`name`) USING BTREE From 0b609305b1ab0a441612b21aaaff6626fb186eae Mon Sep 17 00:00:00 2001 From: tanghc Date: Wed, 14 Apr 2021 15:18:42 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gitee/sop/servercommon/param/ServiceParamValidator.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/param/ServiceParamValidator.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/param/ServiceParamValidator.java index c32c3762..30798702 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/param/ServiceParamValidator.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/param/ServiceParamValidator.java @@ -29,7 +29,10 @@ public class ServiceParamValidator implements ParamValidator { private static final String COMMA = ","; private static Object[] EMPTY_OBJ_ARRAY = {}; - private static final List SYSTEM_PACKAGE_LIST = Arrays.asList("java.lang", "java.math", "java.util", "sun.util"); + private static final List SYSTEM_PACKAGE_LIST = Arrays.asList( + "java.lang", "java.math", "java.util", "sun.util" + ,"org.springframework", "javax.servlet" + ); private static javax.validation.Validator validator;