|
@ -0,0 +1,51 @@
|
|
|
/**
|
|
|
* 简易WLYY SDK,提供WLYY接口调用。
|
|
|
*/
|
|
|
'use strict';
|
|
|
|
|
|
let http = require('http');
|
|
|
let configFile = require('../include/commons').CONFIG_FILE;
|
|
|
let config = require('../resources/config/' + configFile);
|
|
|
let log = require('./log.js');
|
|
|
|
|
|
class WlyyAssistantSDK {
|
|
|
constructor(){}
|
|
|
|
|
|
static request(userId, adminToken, token, imei, endpoint, method, handler){
|
|
|
let userAgent = {
|
|
|
admin_token: adminToken,
|
|
|
token: token,
|
|
|
uid: userId,
|
|
|
imei: imei
|
|
|
};
|
|
|
|
|
|
let options = {
|
|
|
hostname: config.wlyyDAServerConfig.host,
|
|
|
port: config.wlyyDAServerConfig.port,
|
|
|
path: config.wlyyDAServerConfig.model+endpoint,
|
|
|
method: method,
|
|
|
headers: {
|
|
|
'userAgent': JSON.stringify(userAgent)
|
|
|
}
|
|
|
};
|
|
|
|
|
|
let req = http.request(options, function (res) {
|
|
|
res.setEncoding('utf-8');
|
|
|
res.on('data', function (chunk) {
|
|
|
log.info('家庭医生助手平台->请求成功:', chunk);
|
|
|
|
|
|
handler(null, chunk);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
req.on('error', function (err) {
|
|
|
log.error('家庭医生助手平台->请求失败: ', err.message);
|
|
|
|
|
|
handler(err, null);
|
|
|
});
|
|
|
|
|
|
req.end();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
module.exports = WlyyAssistantSDK;
|