Commit 3c72628f authored by 何娜's avatar 何娜

调试运营商接口

parent 32baf45b
Pipeline #27532 passed with stage
in 4 seconds
sudo: false
language: node_js
node_js:
- '8'
before_install:
- npm i npminstall -g
install:
- npm i npminstall && npminstall
- npminstall
script:
- npm run ci
after_script:
......
'use strict';
module.exports = app => {
// 自定义内容
......@@ -5,4 +7,4 @@ module.exports = app => {
const ctx = app.createAnonymousContext();
// ctx.helper.sendMsg({ message: '服务重启' });
});
};
\ No newline at end of file
};
......@@ -66,10 +66,10 @@ class OrderController extends Controller {
const { ctx, service } = this;
ctx.validate(this.createRule);
let { appKey, userId, notifyUrl, backUrl, orderId, phone, netMark } = ctx.request.body;
const appKeyInfo = await service.partner.fetchInfo(appKey);
if (!(appKeyInfo && appKeyInfo.valid === true && appKeyInfo.enableYys === true)) {
return ctx.fail('未开通此服务');
}
// const appKeyInfo = await service.partner.fetchInfo(appKey);
// if (!(appKeyInfo && appKeyInfo.valid === true && appKeyInfo.enableYys === true)) {
// return ctx.fail('未开通此服务');
// }
if (netMark !== 1) {
netMark = 0;
}
......
......@@ -44,11 +44,30 @@ class TaskController extends Controller {
};
}
async configs() {
const { ctx, service } = this;
const { appKey } = ctx.query;
let limitScriptsList = false;
if (appKey) {
const ret = await service.partner.fetchInfo(appKey);
if (ret) {
limitScriptsList = ret.hfExcludeScripts;
}
}
let data = await service.task.configs();
if (limitScriptsList) {
data = data.filter(item => {
return !(limitScriptsList.includes(item.id));
});
}
ctx.success(data);
}
async create() {
const { ctx, service } = this;
ctx.validate(this.createRule);
const { scriptId, orderId } = ctx.request.body;
const taskId = await service.task.create(scriptId);
const taskId = await service.task.create({ cityId: scriptId, orderId });
await service.order.update({ orderId, cityId: scriptId, taskId });
await service.cache.set({
key: String(taskId),
......@@ -107,9 +126,6 @@ class TaskController extends Controller {
};
switch (result.code) {
case -1:
case 106:
case 102:
case 204:
taskNote = {
status: 'failure',
note: { message: result.msg },
......@@ -130,7 +146,7 @@ class TaskController extends Controller {
case 110:
taskNote = {
status: 'query',
note: { message: 'login success' },
note: { message: 'submit success' },
};
break;
case 0:
......@@ -145,6 +161,7 @@ class TaskController extends Controller {
}
const { orderId, netMark } = order;
await service.washData.wash(result, orderId, netMark);
await service.washData.newWash(result, orderId, netMark);
await service.cache.set({
key: String(taskId),
value: taskNote,
......@@ -195,6 +212,32 @@ class TaskController extends Controller {
});
}
async newdataCallback() {
const { ctx, service } = this;
ctx.body = {
code: 200,
};
const { taskId, state } = ctx.request.body;
const order = await service.order.getOneByTaskId(String(taskId));
if (!order) {
throw new Error('任务不存在');
}
let taskNote = {
status: 'failure',
note: { message: '存储数据出错' },
};
if (state === 'success') {
taskNote = {
status: 'success',
note: { message: 'task success' },
};
}
await service.partner.notice(order, state, 1);
await service.cache.set({
key: String(taskId),
value: taskNote,
});
}
}
module.exports = TaskController;
'use strict';
const crypto = require('crypto');
const uuid = require('uuid/v1');
const uuid = require('uuid').v1;
const iconv = require('iconv-lite');
function process(data) {
......
......@@ -7,6 +7,8 @@ module.exports = app => {
const { router, controller } = app;
const yysRouter = router.namespace(app.config.projectRootPath);
yysRouter.get('/scripts', controller.task.configs); // 获取所有脚本配置信息
yysRouter.post('/tasks', controller.task.create); // 创建任务
yysRouter.get('/tasks/:taskId', controller.task.show); // 获取任务状态
yysRouter.post('/tasks/:taskId/submit', controller.task.submit); // 提交任务参数
......@@ -15,11 +17,11 @@ module.exports = app => {
yysRouter.post('/callback', controller.task.handleCallback); // 处理回调结果,不对外
yysRouter.post('/dataCallback', controller.task.dataCallback);// 数据处理完成结果,不对外
yysRouter.post('/newdataCallback', controller.task.newdataCallback);// 运营报告处理完成结果,不对外
// yysRouter.get('/scripts', controller.script.fetchScripts); // 获取所有脚本信息
// yysRouter.get('/scripts/:phone');// 手机号获取脚本信息
// yysRouter.get('/scripts/:scriptId', controller.script.fetchOneScripts); // 获取单一脚本信息
yysRouter.get('/scripts/:scriptId', controller.script.fetchOneScripts); // 获取单一脚本信息
yysRouter.get('/help/:scriptId', controller.script.fetchHelpInfo); // 获取帮助信息
yysRouter.get('/notice/:scriptId', controller.script.fetchNoticeInfo);// 获取提示信息
......@@ -40,6 +42,7 @@ module.exports = app => {
yysRouter.post('/getOrderSn', controller.order.fetchOrderId);// 合作方获取订单号
yysRouter.post('/getThxdData', controller.order.partnerShow);// 合作方获取订单数据
yysRouter.post('/getThxdReport', controller.order.partnerShow);// 合作方获取订单报告
// yysRouter.get('/orderData/:appKey/:orderId', controller.order.orderShow);// 获取展示页面数据
......
......@@ -120,11 +120,11 @@ class PartnerService extends Service {
return ret.data;
}
async notice(order, state) {
async notice(order, state, Num = 0) {
const { ctx, service } = this;
const { orderId, notifyUrl, userId, notice } = order;
const dbRes = await service.order.getOneByOrderId({ orderId, notice: 1 });
if (!dbRes && notifyUrl && notice !== '1') {
const { orderId, notifyUrl, userId } = order;
const dbRes = await service.order.getOneByOrderId({ orderId });
if (dbRes && notifyUrl && (+dbRes.notice + +dbRes.text1 < 2)) {
const ret = await ctx.curl(notifyUrl, {
charset: 'utf-8',
timeout: [30000, 30000],
......@@ -139,7 +139,11 @@ class PartnerService extends Service {
);
ctx.logger.info(`【Partner】 notice ${notifyUrl}`, 'orderId:', orderId, 'result:', ret.status, JSON.stringify(ret.data));
if (ret.status === 200) {
await order.update({ notice: '1' });
if (Num === 0) {
await order.update({ notice: 1 });
} else {
await order.update({ text1: 1 });
}
}
}
return;
......
......@@ -48,7 +48,7 @@ class StorageService extends Service {
method: 'get',
contentType: 'json',
});
ctx.logger.info(`【Storage】read url:`${readUrl}${orderId}` write result:`, JSON.stringify(result.data));
ctx.logger.info(`【Storage】read url:${readUrl}${orderId} write result:`, JSON.stringify(result.data));
if (result && result.data && result.data.code !== 0) {
ctx.logger.error(`storageAPI read ${readUrl}${orderId}`, JSON.stringify(result.data));
......
......@@ -35,17 +35,34 @@ class TaskService extends Service {
this.ctx.throw(400, { message: result.data.msg || result.data.data.img, code: result.data.code || -1 });
}
}
async configs() {
const { taskAPI, ctx } = this;
const { configUrl } = taskAPI;
const result = await this._request(configUrl, {
method: 'get',
contentType: 'json',
});
ctx.logger.info(`【Task】config ${configUrl} params`, JSON.stringify(result.data));
this._checkSuccess(result);
return result;
}
async create(data) {
const { ctx, taskAPI } = this;
const { createTaskUrl } = taskAPI;
const result = await this._request(createTaskUrl, {
method: 'post',
data: { cityId: data },
data: {
cityId: data.cityId,
orderId: data.orderId,
source: 'yysH5new',
},
contentType: 'json',
});
ctx.logger.info(`【Task】create ${createTaskUrl} cityId: ${data} result:`, JSON.stringify(result.data));
ctx.logger.info(`【Task】create ${createTaskUrl} cityId: ${JSON.stringify(data)} result:`, JSON.stringify(result.data.code));
this._checkSuccess(result);
return result.data.data.taskId;
return result.data.data;
}
async fetchCapture({ taskId, type, data }) {
......@@ -95,37 +112,26 @@ class TaskService extends Service {
async phoneArea(phone) {
const { ctx, phoneAreaAPI } = this;
const { bdhost, alhost } = phoneAreaAPI;
const { alhost } = phoneAreaAPI;
const phoneInfo = {
phone,
province: '',
operator: '',
};
let result = await ctx.curl(bdhost + phone, {
const result = await ctx.curl(alhost + phone, {
method: 'get',
timeout: [3000, 3000],
dataType: 'json',
});
ctx.logger.info('phoneArea', bdhost + phone, JSON.stringify(result), phone);
if (result.status !== 200 || result.data.responseHeader.status !== 200 || !result.data.response[phone]) {
result = await ctx.curl(alhost + phone, {
method: 'get',
timeout: [3000, 3000],
});
if (result.status !== 200) {
ctx.throw('400', '请检查手机号是否有效');
}
const html = ctx.helper.decode(result.data);
if (!html.match(/province:'(.*?)'/) || !html.match(/catName:'(.*?)'/)) {
ctx.throw('400', '请检查手机号是否有效');
}
phoneInfo.province = html.match(/province:'(.*?)'/)[1];
phoneInfo.operator = html.match(/catName:'(.*?)'/)[1];
ctx.logger.info('phoneArea', alhost + phone, JSON.stringify(phoneInfo), html, phone);
} else {
phoneInfo.province = result.data.response[phone].detail.province;
phoneInfo.operator = result.data.response[phone].detail.operator;
if (result.status !== 200) {
ctx.throw('400', '请检查手机号是否有效');
}
const html = ctx.helper.decode(result.data);
if (!html.match(/province:'(.*?)'/) || !html.match(/catName:'(.*?)'/)) {
ctx.throw('400', '请检查手机号是否有效');
}
phoneInfo.province = html.match(/province:'(.*?)'/)[1];
phoneInfo.operator = html.match(/catName:'(.*?)'/)[1];
ctx.logger.info('phoneArea', alhost + phone, JSON.stringify(phoneInfo), html, phone);
if (phoneInfo.province === '香港') {
phoneInfo.province = '广东';
}
......
......@@ -8,6 +8,8 @@ class WashDataService extends Service {
const { config } = this;
this.washUrl = config.washAPI.host + config.washAPI.washUrl;
this.callbackUrl = config.dataCallbackUrl;
this.newwashUrl = config.washAPI.newhost + config.washAPI.newwashUrl;
this.newcallbackUrl = config.newdataCallbackUrl;
}
async wash(data, orderId, netMark = 0) {
const { app, washUrl, ctx } = this;
......@@ -32,6 +34,30 @@ class WashDataService extends Service {
}
return washData.data;
}
async newWash(data, orderId, netMark = 0) {
const { app, newwashUrl, newcallbackUrl, ctx } = this;
const rawdata = {
data,
callbackUrl: newcallbackUrl,
orderId,
netMark,
};
const washData = await app.curl(newwashUrl,
{
charset: 'utf-8',
timeout: [3000, 3000],
dataType: 'json',
data: rawdata,
method: 'post',
contentType: 'json',
});
if (washData.status !== 200) {
ctx.logger.error(`【newWashData】url${newwashUrl} ,params`, rawdata, washData);
throw new Error('new清洗数据出错');
}
return washData.data;
}
}
module.exports = WashDataService;
......@@ -9,7 +9,7 @@ module.exports = () => {
config.redis = {
client: {
port: 6379,
host: '127.0.0.1',
host: '116.62.55.137',
password: 'DEV8redis',
db: 0,
},
......@@ -22,11 +22,12 @@ module.exports = () => {
};
config.taskAPI = {
host: 'http://tm.51gjj.com:4829',
createTaskUrl: '/thxdServices/createThxdTask',
fetchCodeUrl: '/thxdServices/queryThxdCode',
submitTaskUrl: '/thxdServices/queryThxd',
fetchTaskUrl: '/thxdServices/getThxdData',
host: 'https://uat-nginx.jianbing.com/scheduler-service/yys',
createTaskUrl: '/create',
fetchCodeUrl: '/phonecode',
submitTaskUrl: '/query',
fetchTaskUrl: '/data',
configUrl: '/configs',
};
config.partnerAPI = {
......@@ -73,6 +74,8 @@ module.exports = () => {
config.washAPI = {
host: 'http://t.51gjj.com:3007',
washUrl: '/dataProcessing',
newhost: 'http://118.31.186.162:8050',
newwashUrl: '/newdataProcessing',
};
config.signatureAPI = {
......@@ -100,7 +103,7 @@ module.exports = () => {
baseDir: 'model',
dialect: 'mysql',
host: 'rm-bp1272001633qc0x9o.mysql.rds.aliyuncs.com',
database: 'data_service_dev',
database: 'data_service_uat',
username: 'hexin',
password: 'gYUHszn9#q',
port: 3306,
......@@ -108,8 +111,9 @@ module.exports = () => {
};
config.callbackUrl = 'https://dev-nginx.jianbing.com/yysh5/callback';
config.dataCallbackUrl = 'https://dev-nginx.jianbing.com/yysh5/dataCallback';
config.callbackUrl = 'https://uat-nginx.jianbing.com/yysh5/callback';
config.dataCallbackUrl = 'https://uat-nginx.jianbing.com/yysh5/dataCallback';
config.newdataCallbackUrl = 'https://uat-nginx.jianbing.com/yysh5/newdataCallback';
return config;
};
......@@ -32,6 +32,14 @@ module.exports = () => {
fetchTaskUrl: '/thxdServices/getThxdData',
};
config.taskAPI = {
host: process.env.TASKAPI_HOST,
createTaskUrl: '/create',
fetchCodeUrl: '/phonecode',
submitTaskUrl: '/query',
fetchTaskUrl: '/data',
};
config.scriptsAPI = {
host: process.env.SCRIPTSAPI_HOST || 'https://uat-nginx.jianbing.com/zeus-api/v1',
fetchScriptsUrl: '/chaos/yys/two_dimension_array/queries',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment