node调用python服务

const http = require( 'http');

function callPhoenixApi( filter, path) {
return new Promise(( resolve, reject) => {
const post_data = JSON. stringify( filter);

const options = {
// host: '100.90.112.17',
host: '10.95.156.249',
port: '5000',
path: path,
method: 'POST',
headers: {
'Content-Type' : 'application/json',
'Content-Length' : Buffer. byteLength( post_data, 'utf8')
}
};

const req = http. request( options, function( res) {
let c = '';
res. on( 'data', ( chunk) => {
c = chunk;
});
res. on( 'end', () => {
resolve( c. toString());
});
});

req. on( 'error', ( e) => {
reject( ` ${ e. message } `);
});

req. write( post_data);
req. end();

})
}

async function getStationInfoByOrder( B, ctx, next) {
let filter = ctx. request. body;
let path = '/getStationInfoByOrder';
await callPhoenixApi( filter, path). then( res => {
ctx. body = JSON. stringify( res);
});
let res = ctx. response;
}

async function getStationInfoById( B, ctx, next) {
let filter = ctx. request. body;
let path = '/getStationInfoByStationId';
try {
let result = await callPhoenixApi( filter, path);
ctx. body = JSON. stringify( result);
} catch ( err) {
}
}

async function getStationInfoByName( B, ctx, next) {
let filter = ctx. request. body;
let path = '/getStationInfoByStationName';
try {
let result = await callPhoenixApi( filter, path);
ctx. body = JSON. stringify( result);
} catch ( err) {
}
}

async function getStationInfoByRec( B, ctx, next) {
let filter = ctx. request. body;
let path = '/getStationInfoByRec';
try {
let result = await callPhoenixApi( filter, path);
ctx. body = JSON. stringify( result);

} catch ( err) {
}
}


module. exports = {
getstationinfobyorder: {
method: 'POST',
fn: getStationInfoByOrder
},
   querybyid: {
     method: 'POST',
     fn: getStationInfoById
  },
querybyname: {
   method: 'POST',
fn:getStationInfoByName
},
getstationinfobyrec:{
   method: 'POST',
fn:getStationInfoByRec
},
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值