mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 12:56:28 +08:00
完善SDK
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
package com.gitee.sop.gateway.config;
|
||||
|
||||
import com.gitee.sop.gateway.service.ParamExecutor;
|
||||
import com.gitee.sop.gateway.service.RouteService;
|
||||
import com.gitee.sop.gateway.service.Serde;
|
||||
import com.gitee.sop.gateway.service.impl.ParamExecutorImpl;
|
||||
import com.gitee.sop.gateway.service.impl.RestRouteServiceImpl;
|
||||
import com.gitee.sop.gateway.service.impl.RouteServiceImpl;
|
||||
import com.gitee.sop.gateway.service.impl.SerdeGsonImpl;
|
||||
import com.gitee.sop.gateway.service.impl.SerdeImpl;
|
||||
import com.gitee.sop.gateway.service.manager.ApiManager;
|
||||
|
@@ -83,11 +83,6 @@ module.exports = class BaseRequest {
|
||||
* @returns 返回结果
|
||||
*/
|
||||
parseResponse(responseData) {
|
||||
let data = responseData['error_response'];
|
||||
if (!data) {
|
||||
const dataNodeName = this.getMethod().replace(/\./g, '_') + '_response';
|
||||
data = responseData[dataNodeName];
|
||||
}
|
||||
return data;
|
||||
return responseData;
|
||||
}
|
||||
};
|
||||
|
@@ -1,20 +1,20 @@
|
||||
const OpenClient = require('./common/OpenClient');
|
||||
|
||||
const StoryGetRequest = require('./request/StoryGetRequest');
|
||||
const ProductGetRequest = require('./request/ProductGetRequest');
|
||||
|
||||
// 应用ID
|
||||
const appId = '2019032617262200001';
|
||||
// 应用私钥,2048位,PKCS8
|
||||
const privateKey = 'MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXJv1pQFqWNA/++OYEV7WYXwexZK/J8LY1OWlP9X0T6wHFOvxNKRvMkJ5544SbgsJpVcvRDPrcxmhPbi/sAhdO4x2PiPKIz9Yni2OtYCCeaiE056B+e1O2jXoLeXbfi9fPivJZkxH/tb4xfLkH3bA8ZAQnQsoXA0SguykMRZntF0TndUfvDrLqwhlR8r5iRdZLB6F8o8qXH6U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EuVcliueJquR47IROdY8qmwqcBAN7Vg2K7r7CPlTKAWTRYMJxCT1Hi5gwJb+CZF3+IeYqsJk2NF2s0w5WJTE70k1BSvQsfIzAIDz2yE1oPHvwVAoGAA6e+xQkVH4fMEph55RJIZ5goI4Y76BSvt2N5OKZKd4HtaV+eIhM3SDsVYRLIm9ZquJHMiZQGyUGnsvrKL6AAVNK7eQZCRDk9KQz+0GKOGqku0nOZjUbAu6A2/vtXAaAuFSFx1rUQVVjFulLexkXR3KcztL1Qu2k5pB6Si0K/uwQ=';
|
||||
// 接口url
|
||||
const url = 'http://localhost:8081';
|
||||
const url = 'http://localhost:8081/api';
|
||||
|
||||
// 创建客户端
|
||||
const openClient = new OpenClient().setUrl(url).setAppId(appId).setPrivateKey(privateKey);
|
||||
|
||||
(async () => {
|
||||
// 创建请求
|
||||
const request = new StoryGetRequest();
|
||||
const request = new ProductGetRequest();
|
||||
|
||||
// 设置业务参数
|
||||
const bizModel = {
|
||||
|
@@ -4,7 +4,7 @@
|
||||
|
||||
## 封装步骤
|
||||
|
||||
1. 新建request类,继承BaseRequest,参考`StoryGetRequest.js`
|
||||
1. 新建request类,继承BaseRequest,参考`ProductGetRequest.js`
|
||||
|
||||
2. 调用接口,参考`main.js`
|
||||
|
||||
|
@@ -4,9 +4,9 @@ const RequestType = require('../common/RequestType');
|
||||
/**
|
||||
* 创建一个请求类,继承BaseRequest,重写三个函数
|
||||
*/
|
||||
module.exports = class StoryGetRequest extends BaseRequest {
|
||||
module.exports = class ProductGetRequest extends BaseRequest {
|
||||
getMethod() {
|
||||
return 'story.get';
|
||||
return 'product.get';
|
||||
}
|
||||
|
||||
getVersion() {
|
@@ -40,11 +40,7 @@ class BaseRequest:
|
||||
raise Exception('未实现BaseRequest.get_request_type()方法')
|
||||
|
||||
def parse_response(self, response_dict):
|
||||
response_data = response_dict.get('error_response')
|
||||
if response_data is None:
|
||||
data_name = self.get_method().replace('.', '_') + '_response'
|
||||
response_data = response_dict.get(data_name)
|
||||
return response_data
|
||||
return response_dict
|
||||
|
||||
|
||||
|
||||
|
@@ -48,7 +48,7 @@ class MyTestCase(unittest.TestCase):
|
||||
# for f in files.values():
|
||||
# f.close()
|
||||
|
||||
if response.get('code') == '10000':
|
||||
if response.get('code') == '0':
|
||||
print 'response: ', response
|
||||
print 'is_vip:', response.get('member_info').get('is_vip', 0)
|
||||
else:
|
||||
|
@@ -29,12 +29,7 @@ pub trait Request {
|
||||
fn get_base(&self) -> &BaseRequest;
|
||||
|
||||
fn parse_response<T: DeserializeOwned>(&self, root: HashMap<String, Value>) -> T {
|
||||
let mut data = root.get("error_response");
|
||||
if data.is_none() {
|
||||
let data_name = self.get_method().replace(".", "_") + "_response";
|
||||
data = root.get(data_name.as_str());
|
||||
}
|
||||
let value = serde_json::to_value(data.unwrap()).unwrap();
|
||||
let value = serde_json::to_value(root).unwrap();
|
||||
serde_json::from_value(value).unwrap()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user