Commit 0426be07 authored by 姜登's avatar 姜登

forgot

parents
Pipeline #17823 passed with stage
'use strict';
module.exports = {
write: true,
prefix: '^',
plugin: 'autod-egg',
test: [
'test',
'benchmark',
],
dep: [
'egg',
'egg-scripts',
],
devdep: [
'egg-ci',
'egg-bin',
'egg-mock',
'autod',
'autod-egg',
'eslint',
'eslint-config-egg',
'webstorm-disable-index',
],
exclude: [
'./test/fixtures',
'./dist',
],
};
{
"extends": [
"eslint-config-egg"
],
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true
}
},
"rules": {
"indent": ["error", 2],
"array-bracket-spacing": ["error", "never"],
"linebreak-style": "off"
}
}
\ No newline at end of file
logs/
npm-debug.log
yarn-error.log
node_modules/
package-lock.json
yarn.lock
coverage/
.idea/
run/
.DS_Store
*.sw*
*.un~
variables:
DOCKER_REGISTRY: 't-docker.51gjj.com'
before_script:
- docker login -u pengtianzi -p 4dc8b3a4d91fa7fa $DOCKER_REGISTRY
stages:
- pre_deploy
build_docker_image:
stage: pre_deploy
script:
- export IMAGE_TAG=${CI_COMMIT_TAG:-latest}
- docker build -t $DOCKER_REGISTRY/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME:$IMAGE_TAG .
- docker push $DOCKER_REGISTRY/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME:$IMAGE_TAG
tags:
- docker-image-builder
sudo: false
language: node_js
node_js:
- '8'
install:
- npm i npminstall && npminstall
script:
- npm run ci
after_script:
- npminstall codecov && codecov
FROM t-docker.51gjj.com/tools/node:8.12.0
ENV LANG C.UTF-8
ENV NODE_ENV production
ENV PATH $PATH:/usr/local/node/bin/
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app/
RUN yarn config set registry "https://registry.npm.taobao.org/"
RUN yarn install
COPY . /usr/src/app
EXPOSE 7001
CMD [ "yarn", "docker" ]
<!--
* @Descripttion:
* @version:
* @Author: jd
* @Date: 2019-12-02 17:25:35
* @LastEditors: jd
* @LastEditTime: 2019-12-02 18:36:11
-->
# forgot_server
## QuickStart
<!-- add docs here for user -->
see [egg docs][egg] for more detail.
### Development
```bash
$ npm i
$ npm run dev
$ open http://localhost:7001/
```
### Deploy
```bash
$ npm start
$ npm stop
```
### npm scripts
- Use `npm run lint` to check code style.
- Use `npm test` to run unit test.
- Use `npm run autod` to auto detect dependencies upgrade, see [autod](https://www.npmjs.com/package/autod) for more detail.
[egg]: https://eggjs.org
\ No newline at end of file
# register_server
注册认证服务
## 快速入门
<!-- 在此次添加使用文档 -->
如需进一步了解,参见 [egg 文档][egg]
### 本地开发
```bash
$ npm i
$ npm run dev
$ open http://localhost:7001/
```
### 部署
```bash
$ npm start
$ npm stop
```
### 单元测试
- [egg-bin] 内置了 [mocha], [thunk-mocha], [power-assert], [istanbul] 等框架,让你可以专注于写单元测试,无需理会配套工具。
- 断言库非常推荐使用 [power-assert]
- 具体参见 [egg 文档 - 单元测试](https://eggjs.org/zh-cn/core/unittest)
### 内置指令
- 使用 `npm run lint` 来做代码风格检查。
- 使用 `npm test` 来执行单元测试。
- 使用 `npm run autod` 来自动检测依赖更新,详细参见 [autod](https://www.npmjs.com/package/autod)
[egg]: https://eggjs.org
module.exports = app => {
// 自定义内容
app.beforeStart(async () => {
const ctx = app.createAnonymousContext();
// ctx.helper.sendMsg({ message: '服务重启' });
});
};
\ No newline at end of file
'use strict';
const Controller = require('egg').Controller;
class OrderController extends Controller {
constructor(ctx) {
super(ctx);
this.createRule = {
appKey: 'string',
userId: {
type: 'string',
required: true,
},
};
}
async create() {
const { ctx, service } = this;
ctx.validate(this.createRule);
const { appKey, userId } = ctx.request.body;
const { type } = ctx.params;
await service.partner.checkInfo(appKey, type);
const orderId = ctx.helper.getUuid();
const object = {
orderId,
taskId: '',
userId,
cityId: '',
type,
appKey,
status: 'init',
};
await service.order.create(object);
ctx.success({ orderId: object.orderId });
}
}
module.exports = OrderController;
'use strict';
const Controller = require('egg').Controller;
class PartnerController extends Controller {
// constructor(ctx) {
// super(ctx);
// }
async show() {
const { ctx, service } = this;
const { appKey, type } = ctx.params;
const ret = await service.partner.fetchTheme(appKey, type);
if (ret && ret.appKey === appKey) {
ctx.success(ret);
return;
}
ctx.fail('尚未配置主题');
}
async fetchAgreements() {
const { ctx, service } = this;
const { id } = ctx.params;
const ret = await service.partner.fetchAgreements(id);
if (ret && String(ret.id) === id) {
ctx.success(ret);
return;
}
ctx.fail('未获取到协议');
}
}
module.exports = PartnerController;
'use strict';
const Controller = require('egg').Controller;
class ScriptController extends Controller {
constructor(ctx) {
super(ctx);
this.cityListRule = {
appKey: 'string',
};
this.paramsRule = {
type: {
type: 'enum',
required: true,
values: ['gjj', 'shebao', 'incomeTax'],
},
scriptId: {
type: 'string',
required: true,
format: /^\d+$/,
},
};
this.typeRule = {
type: {
type: 'enum',
required: true,
values: ['gjj', 'shebao', 'incomeTax'],
},
};
}
// async fetchScripts() {
// const { ctx, service } = this;
// ctx.validate(this.paramsRule, ctx.query);
// const { appKey, type } = ctx.query;
// let limitScriptsList = false;
// if (appKey) {
// const ret = await service.partner.fetchInfo(appKey);
// if (ret && (type === 'gjj')) {
// limitScriptsList = ret.hfExcludeScripts;
// }
// }
// let data = await service.scripts.fetchScripts(type);
// if (limitScriptsList) {
// data = data.filter(item => {
// return !(limitScriptsList.includes(item.id));
// });
// }
// ctx.success(data);
// }
async fetchOneScripts() {
const { ctx, service } = this;
ctx.validate(this.paramsRule, ctx.params);
let { scriptId, type } = ctx.params;
if (scriptId === 'auto') {
const ret = await service.scripts.fetchScriptIdByIp(type);
scriptId = ret.scriptId;
}
const data = await service.scripts.fetchOneScripts(scriptId, type);
ctx.success(data);
}
async fetchParamsInfo() {
const { ctx, service } = this;
ctx.validate(this.typeRule, ctx.params);
const { refresh = false } = ctx.query;
const { type } = ctx.params;
const data = await service.scripts.fetchParams(refresh, type);
ctx.success(data);
}
async fetchHelpInfo() {
const { ctx, service } = this;
ctx.validate(this.paramsRule, ctx.params);
const { scriptId, type } = ctx.params;
const data = await service.scripts.fetchHelp(scriptId, type);
ctx.success(data);
}
async fetchQueryButtonInfo() {
const { ctx, service } = this;
ctx.validate(this.paramsRule, ctx.params);
const { scriptId, type } = ctx.params;
const data = await service.scripts.fetchQueryButton(scriptId, type);
ctx.success(data);
}
async fetchNoticeInfo() {
const { ctx, service } = this;
ctx.validate(this.paramsRule, ctx.params);
const { scriptId, type } = ctx.params;
const data = await service.scripts.fetchNotice(scriptId, type);
ctx.success(data);
}
async fetchHubSeripts() {
const { ctx, service } = this;
ctx.validate(this.typeRule, ctx.params);
let { hubId, type } = ctx.params;
if (hubId === 'auto') {
const ret = await service.scripts.fetchScriptIdByIp(type);
hubId = ret.hubId;
}
const data = await service.scripts.fetchHubSeripts(hubId, type);
ctx.success(data);
}
}
module.exports = ScriptController;
'use strict';
const Controller = require('egg').Controller;
class TaskController extends Controller {
constructor(ctx) {
super(ctx);
this.createRule = {
scriptId: 'number',
orderId: {
type: 'string',
required: true,
format: /^(\w{8})-(\w{4})-(\w{4})-(\w{4})-(\w{12})$/,
message: '订单号格式错误',
},
// userId: 'string',
// appKey: 'string',
};
this.paramsRule = {
type: {
type: 'enum',
required: true,
values: ['gjj', 'shebao', 'incomeTax'],
},
};
this.submitRule = {
phone: { type: 'string', format: /^1\d{10}$/, required: false },
ID: { type: 'string', format: /^\d{14}(\d{3})?[\dXx]$/, required: false },
email: { type: 'email', required: false },
};
this.fetchCaptureRule = {
type: { type: 'enum', values: ['code', 'phone_code'] },
};
this.taskIdRule = {
taskId: { type: 'string', format: /\d+/ },
type: {
type: 'enum',
required: true,
values: ['gjj', 'shebao', 'incomeTax'],
},
};
this.cityListRule = {
sign: 'string',
params: {
type: 'object',
rule: {
token: 'string',
appKey: 'string',
timestamp: 'string',
},
},
};
}
async create() {
const { ctx, service } = this;
ctx.validate(this.createRule);
const { scriptId, appKey } = ctx.request.body;
const { type } = ctx.params;
await service.partner.checkInfo(appKey, type);
const taskId = await service.task.create(scriptId, type);
await service.cache.set({
key: String(taskId),
value: { status: 'init', note: { message: 'init' } },
type,
});
ctx.success({ taskId });
}
async submit() {
const { ctx, service, config } = this;
const { key, iv } = config.aesParams;
ctx.validate(this.submitRule);
const { taskId, type } = ctx.params;
const data = JSON.parse(JSON.stringify(ctx.request.body));
if (data.hasOwnProperty('password')) {
data.password = ctx.helper.aescipher('aes-128-cbc', key, iv, data.password);
}
if (data.hasOwnProperty('confirmPassword')) {
data.confirmPassword = ctx.helper.aescipher('aes-128-cbc', key, iv, data.confirmPassword);
}
if (data.hasOwnProperty('name')) {
data.name = ctx.helper.aescipher('aes-128-cbc', key, iv, data.name);
}
await service.cache.set({
key: String(taskId),
value: { status: 'login', note: { message: 'login' }, params: data },
type,
});
await service.task.submit({
taskId,
data: ctx.request.body,
callbackUrl: config.callbackUrl + type + '/callback',
type,
});
ctx.success({ taskId });
}
async fetchCapture() {
const { ctx, service } = this;
ctx.validate(this.fetchCaptureRule);
const { taskId, type: taskType } = ctx.params;
const { type } = ctx.request.body;
const result = await service.task.fetchCapture({
taskId,
type,
taskType,
});
ctx.success(result);
}
async show() {
const { ctx, service } = this;
ctx.validate(this.taskIdRule, ctx.params);
const { taskId, type } = ctx.params;
const data = await service.cache.get({ key: String(taskId), type });
ctx.success(data);
}
async handleCallback() {
const { ctx, service } = this;
const { taskId } = ctx.request.body;
const { type } = ctx.params;
ctx.body = {
code: '0',
};
const result = await service.task.fetchTask({ taskId: String(taskId), type });
let taskNote = {
status: 'init',
note: { message: 'init' },
};
switch (result.code) {
case -1:
case 106:
case 105:
taskNote = {
status: 'failure',
note: { message: result.msg },
};
break;
case 1:
if (result.data.data) {
result.data = {
data: JSON.parse(JSON.parse(result.data.data).post_data.strForNextStep),
loginParam: result.data.loginParam,
};
}
taskNote = {
status: 'next',
note: { message: 'waiting', nextStep: result.data },
};
break;
case 110:
taskNote = {
status: 'query',
note: { message: 'login success' },
};
break;
case 0:
taskNote = {
status: 'success',
note: { message: 'task success' },
};
break;
default:
ctx.logger.warn('handleCallback', JSON.stringify(result));
break;
}
await service.cache.set({
key: String(taskId),
value: taskNote,
type,
});
}
async fetchCityConfig() {
const { ctx, service } = this;
try {
ctx.validate(this.cityListRule);
await service.signature.signatureCheck(ctx.request.body);
const result = await service.scripts.getCityList(ctx.request.body);
ctx.body = result;
return;
} catch (err) {
ctx.logger.error('fetchCityConfig ERROR', JSON.stringify(err));
ctx.error(err);
}
}
}
module.exports = TaskController;
'use strict';
const Controller = require('egg').Controller;
class TokenController extends Controller {
constructor(ctx) {
super(ctx);
this.createRule = {
sign: 'string',
params: {
type: 'object',
rule: {
appKey: 'string',
timestamp: 'string',
},
},
};
}
async create() {
const { ctx, service } = this;
ctx.validate(this.createRule);
const token = await service.signature.createToken(ctx.request.body);
ctx.success({ data: token });
}
async partnerCreate() {
const { ctx, service } = this;
try {
ctx.validate(this.createRule);
const token = await service.signature.createToken(ctx.request.body);
ctx.body = {
code: 0,
data: { token },
msg: '',
};
} catch (err) {
ctx.logger.error('partnerCreate', JSON.stringify(err));
ctx.error(err);
}
}
}
module.exports = TokenController;
'use strict';
const NODE_CACHE = Symbol('Context#NodeCache');
const NodeCache = require('node-cache');
class Cache {
constructor(app) {
this.app = app;
this.name = 'unknown-cache';
}
async val(key, next, ttl) {
let data = await this.get(key);
if (data) {
return data;
}
data = await next(key);
await this.set(key, data, ttl);
return data;
}
async get(key) {
const startTime = +new Date();
const ret = await this._get(key);
let jsonText = JSON.stringify(ret);
if (jsonText === undefined) {
jsonText = 'undefined';
} else if (jsonText.length >= 128) {
if (/^\{/.test(jsonText)) {
jsonText = '{...}';
} else if (/^\[/.test(jsonText)) {
jsonText = '[...]';
} else {
jsonText = jsonText.substr(0, 125) + '...';
}
}
this.app.logger.info(`[cache] get (${+new Date() - startTime}ms) ${this.name}.${key}: ${jsonText}`);
return ret;
}
async set(key, value, ttl = 60) {
this.app.logger.info(`[cache] set (ms)${this.name}.${key}: ${value}`);
return await this._set(key, value, ttl);
}
async del(key) {
return await this._del(key);
}
}
class NodeCacheWrap extends Cache {
constructor(app) {
super(app);
this.cache = new NodeCache();
this.name = 'node-cache';
}
async _get(key) {
return this.cache.get(key);
}
async _set(key, value, ttl) {
const { cache } = this;
value = JSON.parse(JSON.stringify(value));
if (ttl > 0) {
cache.set(key, value, ttl);
} else {
cache.set(key, value);
}
}
async _del(key) {
const { cache } = this;
cache.del(key);
}
}
module.exports = {
get cache() {
if (!this[NODE_CACHE]) {
this[NODE_CACHE] = new NodeCacheWrap(this);
}
return this[NODE_CACHE];
},
};
'use strict';
module.exports = {
success(data = false) {
const method = this.request.method.toLowerCase();
if (method === 'get') {
this.status = 200;
this.body = data || {};
} else if (method === 'post') {
this.status = 201;
this.body = data || {};
} else if (method === 'put' || method === 'delete') {
this.status = data ? 200 : 204;
this.body = data ? data : '';
} else {
this.status = 204;
this.body = '';
}
},
fail(error = '') {
this.status = 400;
this.body = {
error,
};
},
error(err = '') {
this.status = 200;
if (err.code === 'invalid_param') {
this.body = { code: -1, msg: '请求参数有误' };
return;
}
if (!/token|appKey/.test(err.message)) {
if (/[a-zA-Z]+/.test(err.message)) {
this.body = { code: err.code || -1, msg: '系统错误, 请稍后再试' };
return;
}
}
this.body = { code: err.code || -1, msg: err.message || '' };
},
};
'use strict';
const crypto = require('crypto');
const uuid = require('uuid/v1');
function process(data) {
const keys = Object.keys(data);
keys.sort();
let sign_str = '';
keys.forEach(key => {
const v = data[key];
sign_str += `${key}=${v}&`;
});
return sign_str;
}
module.exports.getUuid = function() {
return uuid();
};
/**
* @desc:通知中心
* @author: JD
* @param {Object} content: 需要发送的预警信息模板
* @return {Boolean} 信息发送状态
*/
module.exports.sendMsg = async function(content) {
if (!content) return false;
const { app } = this;
const { baseURL, settingid, appSecret } = app.config.JBnotifyCenter;
const t = +new Date();
let sign_str = process({ timestamp: t, settingid, params: JSON.stringify(content) });
sign_str += `appsecret=${appSecret}`;
console.log(sign_str);
const sign = crypto
.createHash('md5')
.update(sign_str)
.digest('hex')
.toUpperCase();
const option = {
settingid,
timestamp: t,
sign,
params: content,
};
const result = await this.app.curl(baseURL, {
method: 'POST',
data: option,
dataType: 'json',
contentType: 'json',
});
return result;
};
module.exports.aescipher = function(algorithm, key, iv, data) {
const cipher = crypto.createCipheriv(algorithm, key, iv);
const cipherChunks = [];
cipherChunks.push(cipher.update(data, 'utf8', 'base64'));
cipherChunks.push(cipher.final('base64'));
console.log(data, ' ciphertext: ' + cipherChunks.join(''));
return cipherChunks.join('');
};
module.exports.aesdecipher = function(algorithm, key, iv, data) {
const decipher = crypto.createDecipheriv(algorithm, key, iv);
const cipherChunks = [];
cipherChunks.push(decipher.update(data, 'base64', 'utf8'));
cipherChunks.push(decipher.final('utf8'));
console.log(data, 'UTF8 plaintext deciphered: ' + cipherChunks.join(''));
return cipherChunks.join('');
};
'use strict';
module.exports = (options, app) => {
return async function errorHandler(ctx, next) {
try {
if (ctx.request.method === 'POST') {
app.logger.info(JSON.stringify(ctx.request.body));
}
await next();
} catch (err) {
// 所有的异常都在 app 上触发一个 error 事件,框架会记录一条错误日志
ctx.app.emit('error', err, ctx);
const status = err.status || 500;
// 生产环境时 500 错误的详细错误内容不返回给客户端,因为可能包含敏感信息
const error = status === 500 && ctx.app.config.env === 'prod'
? 'Internal Server Error'
: err.message;
// 从 error 对象上读出各个属性,设置到响应中
ctx.fail(error);
if (status === 422) {
ctx.body.detail = err.errors;
}
ctx.status = status;
}
};
};
'use strict';
module.exports = (options, app) => {
return async function(ctx, next) {
const { request } = ctx;
const { header } = request;
const ipStr = header['x-real-ip'] || header['x-forwarded-for'];
if (ipStr) {
request.ip = ipStr;
}
const start = new Date();
let ms = 0;
await next();
ms = new Date() - start;
app.logger.info(
`[middleware-response-time](${ms}ms) ${request.method} ${request.protocol}://${request.ip}${
request.originalUrl
} ${ctx.response.status}`
);
};
};
'use strict';
module.exports = app => {
const { DataTypes } = app.Sequelize;
const taskStatus = app.model.define('taskStatus', {
id: {
type: DataTypes.INTEGER,
allowNull: false,
autoIncrement: true,
primaryKey: true,
field: 'id',
},
orderId: {
type: DataTypes.STRING(50),
allowNull: false,
defaultValue: '',
field: 'orderId',
},
taskId: {
type: DataTypes.STRING(50),
allowNull: true,
defaultValue: '',
field: 'taskId',
},
userId: {
type: DataTypes.STRING(255),
allowNull: true,
defaultValue: '',
field: 'userId',
},
cityId: {
type: DataTypes.STRING(10),
allowNull: true,
defaultValue: '',
field: 'cityId',
},
type: {
type: DataTypes.STRING(50),
allowNull: false,
defaultValue: '',
field: 'type',
},
appKey: {
type: DataTypes.STRING(50),
allowNull: false,
field: 'appKey',
},
params: {
type: DataTypes.STRING(500),
allowNull: false,
defaultValue: '',
field: 'params',
set(val) {
const note = this.getDataValue('params');
if (!note) {
this.setDataValue('params', JSON.stringify(val));
}
},
},
status: {
type: DataTypes.STRING(20),
allowNull: true,
defaultValue: '',
field: 'status',
},
note: {
type: DataTypes.STRING(1000),
allowNull: true,
defaultValue: '',
field: 'note',
get() {
const note = this.getDataValue('note');
if (note) {
try {
return JSON.parse(note);
} catch (error) {
return {};
}
}
return {};
},
set(val) {
this.setDataValue('note', JSON.stringify(val));
},
},
created_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
field: 'createDate',
},
updated_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
field: 'updateDate',
},
text1: {
type: DataTypes.STRING(255),
allowNull: true,
defaultValue: '',
field: 'text1',
},
},
{
tableName: 'forgot_status',
});
return taskStatus;
};
'use strict';
/**
* @param {Egg.Application} app - egg application
*/
module.exports = app => {
const { controller } = app;
const router = app.router.namespace(app.config.projectRootPath);
router.post('/:type/tasks', controller.task.create); // 创建任务
router.get('/:type/tasks/:taskId', controller.task.show); // 获取任务状态
router.post('/:type/tasks/:taskId/submit', controller.task.submit); // 提交任务参数
router.post('/:type/tasks/:taskId/capture', controller.task.fetchCapture); // 获取验证码
router.post('/:type/callback', controller.task.handleCallback); // 处理回调结果,不对外
// router.get('/:type/scripts', controller.script.fetchScripts); // 获取所有脚本信息
router.get('/:type/scripts/:scriptId', controller.script.fetchOneScripts); // 获取单一脚本信息
router.get('/:type/help/:scriptId', controller.script.fetchHelpInfo); // 获取帮助信息
router.get('/:type/notice/:scriptId', controller.script.fetchNoticeInfo);// 获取提示信息
router.get('/:type/query_button/:scriptId', controller.script.fetchQueryButtonInfo); // 获取查询按钮信息
router.get('/:type/params', controller.script.fetchParamsInfo); // 获取登录参数字典
// router.post('/:type/tokens', controller.token.create); // 创建token
router.post('/:type/orders', controller.order.create); // 创建订单号
router.get('/:type/hubs/:hubId/scripts', controller.script.fetchHubSeripts);// 根据hubId 获取脚本数据(数组)
router.get('/:type/theme/:appKey', controller.partner.show);// 根据appkey查询合作方主题
router.get('/agreements/:id', controller.partner.fetchAgreements);// 查询协议
};
'use strict';
const Service = require('egg').Service;
class CacheService extends Service {
constructor(ctx) {
super(ctx);
const { config } = this;
const { taskPrefix } = config.lockKeys;
this.taskPrefix = taskPrefix;
}
/**
* 将taskId状态缓存到redis和数据库
* @param {Object} key taskId
* - value: 状态 提示信息 status 、note={}
* - exprie: 过期时间
*/
async set({ key, value = {}, type, exprie = 300 }) {
const { ctx, app, taskPrefix } = this;
const data = await app.redis.get(taskPrefix + type + key);
if (!data || (data && data.status !== 'success')) {
await app.redis.set(taskPrefix + type + key, JSON.stringify(value), 'EX', exprie);
}
const order = await ctx.model.TaskStatus.findOne({
where: { taskId: key, type },
});
if (order && order.status !== 'success') {
await order.update({ ...value });
} else {
ctx.logger.error('【Cache】set no order or already success', type, key);
}
ctx.logger.info(`【Cache】set ${type}${key} value:`, JSON.stringify(value));
}
/**
* 获取task状态 优先redis
* @param {Object} key taskId
* @return {Object} status note
*/
async get({ key, type }) {
const { ctx, app, taskPrefix } = this;
const data = await app.redis.get(taskPrefix + type + key);
if (data) {
ctx.logger.info(`【Cache】get From redis ${type}${key} data:`, data);
return JSON.parse(data);
}
const order = await ctx.model.TaskStatus.findOne({
where: { taskId: key, type },
});
if (order) {
ctx.logger.info(`【Cache】get From Model ${type}${key}order:`, JSON.stringify({ status: order.status, note: order.note }));
return { status: order.status, note: order.note };
}
ctx.logger.error(`【Cache】get No Result ${type}${key} `);
this.ctx.throw(400, { message: 'no taskId' });
}
}
module.exports = CacheService;
'use strict';
const Service = require('egg').Service;
class OrderService extends Service {
async getOneByOrderId(params) {
const { ctx } = this;
const order = await ctx.model.TaskStatus.findOne({
where: params,
});
return order;
}
async getOneByTaskId(taskId) {
const { ctx } = this;
const order = await ctx.model.TaskStatus.findOne({
where: { taskId },
});
return order;
}
async create(params) {
const { ctx } = this;
await ctx.model.TaskStatus.create(params);
return;
}
async update(params) {
const { ctx } = this;
const order = await ctx.model.TaskStatus.findAll({
where: { orderId: params.orderId },
order: [['createDate', 'DESC']],
});
if (order.length === 0) {
ctx.throw(400, { message: 'no order' });
return;
}
for (const item of order) {
if (item.status === 'success') {
ctx.throw(400, { message: 'orderId success' });
return;
}
}
const { appKey, taskId, notifyUrl, backUrl, userId } = order[0];
if (taskId) {
await ctx.model.TaskStatus.create({ appKey, status: 'init', notifyUrl, backUrl, userId, ...params });
} else {
await order[0].update(params);
}
return order[0];
}
}
module.exports = OrderService;
'use strict';
const Service = require('egg').Service;
class PartnerService extends Service {
constructor(ctx) {
super(ctx);
const { config: { partnerAPI } } = this;
this.partnerAPI = partnerAPI;
}
async fetchTheme(appKey, type) {
const { ctx, partnerAPI: { fetchTheme, host, redisThemePrefix } } = this;
if (appKey) {
const data = await this.app.redis.get(redisThemePrefix + type + appKey);
if (data) {
try {
return JSON.parse(data);
} catch (err) {
ctx.logger.error('【Scripts】fetchParams', redisThemePrefix + appKey, 'result:', data, err);
await this.app.redis.del(redisThemePrefix + type + appKey);
}
}
}
const ret = await ctx.curl(`${host + fetchTheme}`, {
charset: 'utf-8',
timeout: [30000, 30000],
dataType: 'json',
method: 'GET',
data: {
appKey,
subject: 'hf',
},
});
ctx.logger.info(`【Partner】 fetchTheme ${host + fetchTheme}/${appKey}`, JSON.stringify(ret.data));
if (ret.status === 200 && ret.data && ret.data.length > 0 && ret.data[0].appKey === appKey) {
await this.app.redis.set(redisThemePrefix + type + appKey, JSON.stringify(ret.data[0]), 'EX', 300);
}
return ret.data[0];
}
async fetchInfo(appKey) {
const { ctx, partnerAPI: { fetchInfo, host, redisInfoPrefix } } = this;
if (appKey) {
const data = await this.app.redis.get(redisInfoPrefix + appKey);
if (data) {
try {
return JSON.parse(data);
} catch (err) {
ctx.logger.error('【Scripts】fetchInfo', redisInfoPrefix + appKey, 'result:', data, err);
await this.app.redis.del(redisInfoPrefix + appKey);
}
}
}
const ret = await ctx.curl(`${host + fetchInfo}`, {
charset: 'utf-8',
timeout: [30000, 30000],
dataType: 'json',
method: 'GET',
data: {
appKey,
},
});
ctx.logger.info(`【Partner】 fetchInfo ${host + fetchInfo}?appKey=${appKey}`, JSON.stringify(ret.data));
if (ret.status === 200 && ret.data && ret.data.length > 0 && ret.data[0].appKey === appKey) {
await this.app.redis.set(redisInfoPrefix + appKey, JSON.stringify(ret.data[0]), 'EX', 300);
}
return ret.data[0];
}
async checkInfo(appKey, type) {
const { ctx } = this;
const appKeyInfo = await this.fetchInfo(appKey, type);
if (!(appKeyInfo && appKeyInfo.valid === true)) {
ctx.throw(422, { message: '无效的appKey' });
}
switch (type) {
case 'gjj':
if (appKeyInfo.enableHf !== true) {
ctx.throw(422, { message: '未开通此服务' });
}
break;
case 'shebao':
if (appKeyInfo.enableSs === true) {
ctx.throw(422, { message: '未开通此服务' });
}
break;
case 'incomeTax':
if (appKeyInfo.enableIt === true) {
ctx.throw(422, { message: '未开通此服务' });
}
break;
default:
ctx.throw(422, { message: '无效的类型' });
break;
}
}
async fetchAgreements(id) {
const { ctx, partnerAPI: { fetchAgreements, host, redisAgreementsPrefix } } = this;
const data = await this.app.redis.get(redisAgreementsPrefix + id);
if (data) {
try {
return JSON.parse(data);
} catch (err) {
ctx.logger.error('【Partner】 fetchAgreements', redisAgreementsPrefix + id, 'result:', JSON.stringify(data), err);
await this.app.redis.del(redisAgreementsPrefix + id);
}
}
const url = `${host + fetchAgreements}/${id}`;
const ret = await ctx.curl(url, {
charset: 'utf-8',
timeout: [30000, 30000],
dataType: 'json',
method: 'GET',
});
ctx.logger.info(`【Partner】 fetchAgreements ${url}`, JSON.stringify(ret.data));
if (ret.status === 200 && ret.data && ret.data.id === id) {
await this.app.redis.set(redisAgreementsPrefix + id, JSON.stringify(ret.data), 'EX', 300);
}
return ret.data;
}
}
module.exports = PartnerService;
'use strict';
const Service = require('egg').Service;
class ScriptsService extends Service {
constructor(ctx) {
super(ctx);
const { config } = this;
const { scriptsAPI } = config;
this.scriptsAPI = scriptsAPI;
this.baseURL = scriptsAPI.host;
this.fetchScriptsUrl = scriptsAPI.fetchScriptsUrl;
this.fetchOneScriptUrl = scriptsAPI.fetchOneScriptUrl;
this.fetchParamsInfoUrl = scriptsAPI.fetchParamsInfoUrl;
this.fetchHelpUrl = scriptsAPI.fetchHelpUrl;
this.redisScriptsKey = scriptsAPI.redisScriptsKey;
this.redisParamsKey = scriptsAPI.redisParamsKey;
this.redisScriptListKey = scriptsAPI.redisScriptListKey;
this.cityListUrl = scriptsAPI.cityListUrl;
}
checkType(type) {
const { ctx } = this;
let scriptsType = '';
switch (type) {
case 'gjj':
scriptsType = '/hf';
break;
case 'shebao':
break;
case 'incomeTax':
break;
default:
ctx.throw(422, { message: '无效的类型' });
break;
}
return scriptsType;
}
async fetchScripts(type) {
const { baseURL, fetchScriptsUrl, redisScriptsKey, ctx } = this;
const data = await this.app.redis.get(redisScriptsKey + type);
if (data) {
try {
return JSON.parse(data);
} catch (err) {
ctx.logger.error('【Scripts】fetchScriptsFromRedis', 'result:', data, err);
await this.app.redis.del(redisScriptsKey + type);
}
}
const result = await ctx.curl(baseURL + this.checkType(type) + fetchScriptsUrl, {
charset: 'utf-8',
timeout: [30000, 30000],
dataType: 'json',
contentType: 'json',
});
ctx.logger.info(`【Scripts】fetchScripts,${baseURL + fetchScriptsUrl}`, 'result:', type, JSON.stringify(result.data));
if (result.data && result.data.length > 0) {
await this.app.redis.set(redisScriptsKey + type, JSON.stringify(result.data), 'EX', 120);
}
return result.data;
}
async fetchOneScripts(scriptId, type) {
const { baseURL, fetchOneScriptUrl, redisScriptListKey, ctx } = this;
const data = await this.app.redis.get(redisScriptListKey + type + scriptId);
if (data) {
try {
return JSON.parse(data);
} catch (err) {
ctx.logger.error('【Scripts】fetchOneScriptsFromRedis', 'result:', data, err);
await this.app.redis.del(redisScriptListKey + type + scriptId);
}
}
const result = await ctx.curl(baseURL + this.checkType(type) + fetchOneScriptUrl + '/' + scriptId, {
charset: 'utf-8',
timeout: [30000, 30000],
dataType: 'json',
contentType: 'json',
});
if (result.data && (String(result.data.id) === scriptId)) {
await this.app.redis.set(redisScriptListKey + type + scriptId, JSON.stringify(result.data), 'EX', 120);
}
return result.data;
}
async fetchParams(refresh = false, type) {
const { baseURL, fetchParamsInfoUrl, redisParamsKey, ctx } = this;
if (!refresh) {
const data = await this.app.redis.get(redisParamsKey + type);
if (data) {
try {
return JSON.parse(data);
} catch (err) {
ctx.logger.error('【Scripts】fetchParams', 'result:', data, err);
await this.app.redis.del(redisParamsKey + type);
}
}
}
const result = await ctx.curl(baseURL + this.checkType(type) + fetchParamsInfoUrl, {
charset: 'utf-8',
timeout: [30000, 30000],
dataType: 'json',
contentType: 'json',
});
ctx.logger.info(`【Scripts】fetchParams,${baseURL + fetchParamsInfoUrl}`, 'result:', JSON.stringify(result.data));
if (result.data && result.data.length > 0) {
await this.app.redis.set(redisParamsKey + type, JSON.stringify(result.data), 'EX', 300);
}
return result.data;
}
async fetchHelp(scriptId, type) {
const { baseURL, scriptsAPI: { fetchHelpUrl }, ctx } = this;
const result = await ctx.curl(baseURL + this.checkType(type) + fetchHelpUrl + '/' + scriptId, {
charset: 'utf-8',
timeout: [30000, 30000],
dataType: 'json',
contentType: 'json',
});
return result.data;
}
async fetchQueryButton(scriptId, type) {
const { baseURL, scriptsAPI: { fetchQueryButtonUrl }, ctx } = this;
const result = await ctx.curl(baseURL + this.checkType(type) + fetchQueryButtonUrl + '/' + scriptId, {
charset: 'utf-8',
timeout: [30000, 30000],
dataType: 'json',
contentType: 'json',
});
return result.data;
}
async fetchNotice(scriptId, type) {
const { baseURL, scriptsAPI: { fetchNoticeUrl }, ctx } = this;
const result = await ctx.curl(baseURL + this.checkType(type) + fetchNoticeUrl + '/' + scriptId, {
charset: 'utf-8',
timeout: [30000, 30000],
dataType: 'json',
contentType: 'json',
});
return result.data;
}
async fetchHubSeripts(hubId, type) {
const { baseURL, scriptsAPI: { fetchHubSeriptsUrl }, ctx } = this;
const result = await ctx.curl(baseURL + this.checkType(type) + fetchHubSeriptsUrl + '/' + hubId + '/scripts', {
charset: 'utf-8',
timeout: [30000, 30000],
dataType: 'json',
contentType: 'json',
});
return result.data;
}
async fetchCityFormIp() {
const { ctx } = this;
const { ip } = ctx.request;
ctx.logger.info(JSON.stringify(ctx.request));
const ipArray = ip.split(',');
const url = `https://api.map.baidu.com/location/ip?ak=3TBenWOhPygtFFazaR5kSibU&ip=${ipArray[0]}`;
const result = await ctx.curl(url, {
charset: 'utf-8',
timeout: [30000, 30000],
dataType: 'json',
contentType: 'json',
});
if (result.data.status === 0) {
return result.data.content.address_detail.city;
}
ctx.logger.error('fetchCityFormIp', url, JSON.stringify(result.data));
return '北京市';
}
async fetchScriptByCityName(name, type) {
const { baseURL, scriptsAPI: { fetchScriptByCityNameUrl }, ctx } = this;
const result = await ctx.curl(baseURL + this.checkType(type) + fetchScriptByCityNameUrl + '?name=' + encodeURIComponent(name) + '&type=query', {
charset: 'utf-8',
timeout: [30000, 30000],
dataType: 'json',
contentType: 'json',
});
ctx.logger.info(`fetchScriptByCityName,${baseURL + fetchScriptByCityNameUrl + '?name=' + name}`, 'result:', JSON.stringify(result.data));
return result.data;
}
async fetchScriptIdByIp(type) {
const city = await this.fetchCityFormIp();
const scriptList = await this.fetchScriptByCityName(city, type);
return scriptList;
}
async fetchScriptName(scriptId) {
try {
const city = await this.fetchOneScripts(scriptId);
return city.name || '未知';
} catch (err) {
return '未知';
}
}
async getCityList(params) {
try {
const { cityListUrl, ctx } = this;
const result = await ctx.curl(cityListUrl, {
charset: 'utf-8',
timeout: [30000, 30000],
dataType: 'json',
contentType: 'json',
method: 'POST',
data: params,
});
return result.data;
} catch (err) {
this.ctx.logger.error(err);
return { code: -1, msg: '系统错误,请稍后重试' };
}
}
}
module.exports = ScriptsService;
'use strict';
const Service = require('egg').Service;
class SignatureService extends Service {
constructor(ctx) {
super(ctx);
const { config } = this;
const { signatureAPI, lockKeys } = config;
this.baseURL = signatureAPI.host;
this.fetchTokenUrl = signatureAPI.fetchTokenUrl;
this.fetchOrderIdUrl = signatureAPI.fetchOrderIdUrl;
this.signatureUrl = signatureAPI.signatureUrl;
this.signatureType = signatureAPI.signatureType;
this.LOCK_KEY = lockKeys.fecteToken;
this.SCRIPTS_KEY = lockKeys.token;
}
_request(url, opts) {
const { ctx, baseURL } = this;
url = `${baseURL}${url}`;
opts = {
charset: 'utf-8',
timeout: [30000, 30000],
dataType: 'json',
...opts,
};
ctx.logger.info('signnature', url, opts);
return ctx.curl(url, opts);
}
_checkSuccess(result) {
if (result.status !== 200) {
const errorMsg = result.data && result.data.error_msg ? result.data.error_msg : 'unknown error';
this.ctx.throw(result.status, errorMsg);
}
if (result.data.code !== 0) {
this.ctx.throw(400, { message: result.data.msg, code: result.data.code });
}
}
async createToken(params) {
const { fetchTokenUrl, ctx } = this;
const result = await this._request(fetchTokenUrl, {
method: 'post',
data: params,
contentType: 'json',
});
ctx.logger.info('【Signature】createToken params', JSON.stringify(params), 'result:', JSON.stringify(result.data));
this._checkSuccess(result);
return result.data.data.token;
}
async createOrderId(params) {
const { fetchOrderIdUrl, ctx } = this;
const result = await this._request(fetchOrderIdUrl, {
method: 'post',
data: params,
contentType: 'json',
});
ctx.logger.info('【Signature】createOrderId params', JSON.stringify(params), 'result:', JSON.stringify(result.data));
this._checkSuccess(result);
return result.data.data.orderSn;
}
async signatureCheck(params) {
const { signatureUrl, signatureType, ctx } = this;
const result = await this._request(signatureUrl, {
method: 'post',
data: { ...params, type: signatureType },
contentType: 'json',
});
ctx.logger.info('【Signature】signatureCheck params', JSON.stringify(params), 'result:', JSON.stringify(result.data));
this._checkSuccess(result);
return result.data.data;
}
}
module.exports = SignatureService;
'use strict';
const Service = require('egg').Service;
class StorageService extends Service {
constructor(ctx) {
super(ctx);
const { config } = this;
const { storageAPI } = config;
this.baseURL = storageAPI.host;
this.writeUrl = storageAPI.writeUrl;
this.readUrl = storageAPI.readUrl;
this.writeType = storageAPI.writeType;
this.readDataKey = storageAPI.readDataKey;
}
_request(url, opts) {
const { ctx, baseURL } = this;
url = `${baseURL}${url}`;
opts = {
charset: 'utf-8',
timeout: [30000, 30000],
dataType: 'json',
...opts,
};
return ctx.curl(url, opts);
}
async write(data) {
const { writeUrl, writeType, ctx } = this;
const result = await this._request(writeUrl, {
method: 'post',
data: { ...data, serviceType: writeType },
contentType: 'json',
});
ctx.logger.info(`【Storage】write url:${writeUrl} params`, JSON.stringify({ ...data, serviceType: writeType }), 'result:', JSON.stringify(result.data));
if (result.data.code !== '0') {
throw new Error('存储数据出错');
}
return;
}
async read(orderId, appKey) {
const { readUrl, readDataKey, ctx } = this;
const result = await this._request(`${readUrl}/${orderId}`, {
method: 'get',
contentType: 'json',
});
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));
ctx.throw(400, { message: result.data.msg });
}
await ctx.model.Cusdata.create({
appKey,
orderId,
type: 'gjj',
});
return result.data.data[readDataKey];
}
}
module.exports = StorageService;
/*
* @Descripttion:
* @version:
* @Author: jd
* @Date: 2019-12-02 17:25:35
* @LastEditors: jd
* @LastEditTime: 2019-12-03 15:28:31
*/
'use strict';
const Service = require('egg').Service;
class TaskService extends Service {
constructor(ctx) {
super(ctx);
const { config: { taskAPI, LOCK_KEY } } = this;
this.taskAPI = taskAPI;
this.baseURL = taskAPI.host;
this.citylistURL = taskAPI.citylist;
this.LOCK_KEY = LOCK_KEY;
}
checkType(type) {
const { ctx } = this;
let scriptsType = '';
switch (type) {
case 'gjj':
scriptsType = ':18524/gjjfindpwd';
break;
case 'shebao':
scriptsType = ':18523/shebaofindpwd';
break;
case 'incomeTax':
scriptsType = ':18518/gsfindpwd';
break;
default:
ctx.throw(422, { message: '无效的类型' });
break;
}
return scriptsType;
}
_request(url, opts) {
const { ctx, baseURL } = this;
url = `${baseURL}${url}`;
opts = {
charset: 'utf-8',
timeout: [30000, 30000],
dataType: 'json',
...opts,
};
return ctx.curl(url, opts);
}
_checkSuccess(result) {
if (result.status !== 200) {
const errorMsg = result.data && result.data.error_msg ? result.data.error_msg : 'unknown error';
this.ctx.throw(result.status, errorMsg);
}
if (result.data.code !== 0) {
this.ctx.throw(400, { message: result.data.msg || result.data.data.img, code: result.data.code || -1 });
}
}
async create(data, type) {
const { ctx, taskAPI } = this;
const { createTaskUrl } = taskAPI;
const result = await this._request(this.checkType(type) + createTaskUrl, {
method: 'post',
data: { cityId: data },
contentType: 'json',
});
ctx.logger.info(`【Task】create ${this.checkType(type) + createTaskUrl} cityId: ${data} result:`, JSON.stringify(result.data));
this._checkSuccess(result);
return result.data.data.taskId;
}
async fetchCapture({ taskId, taskType }) {
const { taskAPI, ctx } = this;
const { fetchCodeUrl } = taskAPI;
const result = await this._request(this.checkType(type) + fetchCodeUrl, {
method: 'post',
data: {
taskId,
taskType,
},
contentType: 'json',
});
ctx.logger.info(`【Task】fetchCapture ${this.checkType(type) + fetchCodeUrl} params`, JSON.stringify({
taskId,
type,
taskType,
}), JSON.stringify(result.data));
this._checkSuccess(result);
return result.data.data;
}
async submit(data) {
const { taskAPI, ctx } = this;
const { submitTaskUrl } = taskAPI;
const result = await this._request(this.checkType(type) + submitTaskUrl, {
method: 'post',
data,
contentType: 'json',
});
ctx.logger.info(`【Task】submit ${this.checkType(type) + submitTaskUrl} params`, JSON.stringify(data), JSON.stringify(result.data));
this._checkSuccess(result);
return result;
}
async fetchTask(data) {
const { taskAPI, ctx } = this;
const { fetchTaskUrl } = taskAPI;
const result = await this._request(this.checkType(type) + fetchTaskUrl, {
method: 'post',
data,
contentType: 'json',
});
ctx.logger.info(`【Task】fetchTask ${this.checkType(type) + fetchTaskUrl} params`, JSON.stringify(data), JSON.stringify(result.data));
return result.data;
}
}
module.exports = TaskService;
'use strict';
const Service = require('egg').Service;
class WashDataService extends Service {
constructor(ctx) {
super(ctx);
const { config } = this;
this.washUrl = config.washAPI.host + config.washAPI.washUrl;
this.clearGjj = ['ID', 'phone', 'birthday', 'email', 'address', 'card', 'deposit_base', 'person_rate', 'company_rate', 'marriage', 'sex', 'company_id'];
this.clearLoan = ['name', 'ID', 'warning_rate', 'fund_date', 'bank', 'phone', 'address', 'past_due', 'past_principle', 'past_interest', 'past_period', 'history_past_period', 'history_past_amount', 'assure_style', 'house_type', 'debit_account', 'left_period'];
}
async wash(data) {
const { app, washUrl, ctx, service } = this;
const rawdata = this._switchData(data);
const is_merge_detail = (await service.scripts.fetchOneScripts(rawdata.cityId)).is_merge_detail;
rawdata.is_merging = String(is_merge_detail);
const washData = await app.curl(washUrl,
{
charset: 'utf-8',
timeout: [30000, 30000],
dataType: 'json',
data: rawdata,
method: 'post',
contentType: 'json',
});
if (washData.status !== 200) {
ctx.logger.error(`【washData】url${washUrl} ,params`, rawdata, washData);
throw new Error('清洗数据出错');
}
if (washData.data.code !== 0) {
ctx.logger.error(`【washData】url${washUrl} ,params`, rawdata, washData.data);
throw new Error('清洗数据出错');
}
washData.data.data.general_analyzed_data.overdueClassify = {};
washData.data.data.general_analyzed_data.loanClassify = {};
washData.data.data.general_analyzed_data.blacklist = {};
return washData.data;
}
_switchData(data) {
const tmp = data.data;
const bar = {};
bar.taskId = tmp.taskId;
bar.cityId = tmp.cityId;
bar.data = JSON.parse(tmp.data);
bar.jsName = tmp.jsName;
return bar;
}
dealData(data, passID = false) {
const { clearGjj, clearLoan } = this;
delete data.data.general_analyzed_data;
for (const gjjItem of data.data.gjj_data) {
for (const text of clearGjj) {
if (!(passID && text === 'ID')) {
delete gjjItem.gjj_brief[text];
}
}
delete gjjItem.gjj_account_analyzed_data;
}
for (const loanItem of data.data.loan_data) {
for (const text of clearLoan) {
delete loanItem.loan_brief[text];
}
}
return data;
}
}
module.exports = WashDataService;
environment:
matrix:
- nodejs_version: '8'
install:
- ps: Install-Product node $env:nodejs_version
- npm i npminstall && node_modules\.bin\npminstall
test_script:
- node --version
- npm --version
- npm run test
build: off
'use strict';
module.exports = appInfo => {
const config = exports = {};
// use for cookie sign key, should change to your own and keep security
config.keys = appInfo.name + '_1542452126322_5140';
// add your config here
config.middleware = ['requestLog', 'errorHandler'];
config.logrotator = {
maxDays: 5,
}
// 是否启用csrf安全
config.security = {
csrf: {
enable: false,
},
domainWhiteList: [],
};
config.cors = {
origin: '*',
allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS',
credentials: true,
};
return config;
};
/*
* @Descripttion:
* @version:
* @Author: jd
* @Date: 2019-12-02 17:25:35
* @LastEditors: jd
* @LastEditTime: 2019-12-03 15:14:42
*/
'use strict';
module.exports = () => {
const config = exports = {};
config.debug = true;
config.projectRootPath = '/forgot_server';
config.aesParams = {
key: 'zqPMVFtyIrmWZrvZ',
iv: '3381872973569615',
};
config.redis = {
client: {
port: 6379,
host: '127.0.0.1',
password: 'DEV8redis',
db: 0,
},
};
config.JBnotifyCenter = {
baseURL: 'https://notifier.getxumi.com/api/notify',
settingid: '5cbef46823775d0001640fc8',
appSecret: '6bc693e3ce84478482880a3600c9a78c',
};
config.taskAPI = {
host: 'http://tm.51gjj.com',
createTaskUrl: '/createTask',
fetchCodeUrl: '/getCode',
submitTaskUrl: '/loginWeb',
fetchTaskUrl: '/getData',
};
config.partnerAPI = {
host: 'https://uat-nginx.jianbing.com/zeus-api/v1',
fetchTheme: '/chaos/theme',
fetchScripts: '/chaos/partners/scripts',
fetchAgreements: '/chaos/agreements',
redisThemePrefix: 'URANUS.FORGOT.PARNTERS.THEME',
redisScriptsPrefix: 'URANUS.FORGOT.PARNTERS.SCRIPTS',
redisAgreementsPrefix: 'URANUS.FORGOT.PARNTERS.Agreements',
fetchInfo: '/chaos/partner',
redisInfoPrefix: 'URANUS.FORGOT.PARNTERS.Info',
redisappKeyLimitPrefix: 'URANUS.FORGOT.PARNTERS.Limit',
};
config.scriptsAPI = {
host: 'https://uat-nginx.jianbing.com/zeus-api/v1/chaos',
fetchScriptsUrl: '/two_dimension_array/queries',
fetchOneScriptUrl: '/two_dimension_array/info',
fetchParamsInfoUrl: '/login_param_map',
fetchQueryButtonUrl: '/query_button',
fetchHelpUrl: '/help',
fetchNoticeUrl: '/notice',
fetchHubSeriptsUrl: '/hubs',
fetchScriptByCityNameUrl: '/city_scripts',
redisScriptsKey: 'URANUS.FORGOT.SCRIPTS',
redisParamsKey: 'URANUS.FORGOT.PARAMS',
redisScriptListKey: 'URANUS.FORGOT.SCRIPTLIST',
};
// config.signatureAPI = {
// host: 'http://tj3.51gjj.com:5118',
// fetchTokenUrl: '/Access/GetToken',
// fetchOrderIdUrl: '/Order/GetOrderSn',
// signatureUrl: '/Access/SignValidityCheck',
// signatureType: 'gjj',
// customerUrl: '/customer/query',
// };
config.lockKeys = {
taskPrefix: 'URANUS.FORGOT.TASK',
};
config.sequelize = {
datasources: [{
// 东八时区
timezone: '+08:00',
delegate: 'model',
baseDir: 'model',
dialect: 'mysql',
host: 'rm-bp1272001633qc0x9o.mysql.rds.aliyuncs.com',
database: 'data_service_dev',
username: 'hexin',
password: 'gYUHszn9#q',
port: 3306,
}],
};
config.callbackUrl = 'https://dev-nginx.jianbing.com/forgot_server/';
return config;
};
/*
* @Descripttion:
* @version:
* @Author: jd
* @Date: 2019-12-02 17:25:35
* @LastEditors: jd
* @LastEditTime: 2019-12-04 16:12:03
*/
'use strict';
module.exports = () => {
const config = exports = {};
config.debug = true;
config.logger = {
dir: '/jianbing/logs/forgot_server',
};
config.aesParams = {
key: 'zqPMVFtyIrmWZrvZ',
iv: '3381872973569615',
};
config.projectRootPath = '/forgot_server';
config.redis = {
client: {
port: process.env.REDIS_PORT || 6379,
host: process.env.REDIS_HOST || '127.0.0.1',
password: process.env.REDIS_PWD || 'DEV8redis',
db: process.env.REDIS_DB || 0,
},
};
config.JBnotifyCenter = {
baseURL: 'https://notifier.getxumi.com/api/notify',
settingid: '5cbef46823775d0001640fc8',
appSecret: '6bc693e3ce84478482880a3600c9a78c',
};
config.taskAPI = {
host: process.env.TASKAPI_HOST || 'http://tm.51gjj.com',
createTaskUrl: '/createTask',
fetchCodeUrl: '/getCode',
submitTaskUrl: '/loginWeb',
fetchTaskUrl: '/getData',
};
config.scriptsAPI = {
host: process.env.SCRIPTSAPI_HOST || 'https://uat-nginx.jianbing.com/zeus-api/v1/chaos',
fetchScriptsUrl: '/two_dimension_array/queries',
fetchOneScriptUrl: '/two_dimension_array/info',
fetchParamsInfoUrl: '/login_param_map',
fetchQueryButtonUrl: '/query_button',
fetchHelpUrl: '/help',
fetchNoticeUrl: '/notice',
fetchHubSeriptsUrl: '/hubs',
fetchScriptByCityNameUrl: '/city_scripts',
redisScriptsKey: 'URANUS.FORGOT.SCRIPTS',
redisParamsKey: 'URANUS.FORGOT.PARAMS',
redisScriptListKey: 'URANUS.FORGOT.SCRIPTLIST',
};
// config.signatureAPI = {
// host: process.env.SIGNATUREAPI_HOST || 'http://tj3.51gjj.com:5118',
// fetchTokenUrl: '/Access/GetToken',
// fetchOrderIdUrl: '/Order/GetOrderSn',
// signatureUrl: '/Access/SignValidityCheck',
// customerUrl: '/customer/query',
// };
config.partnerAPI = {
host: process.env.PARTNERAPI_HOST || 'https://uat-nginx.jianbing.com/zeus-api/v1',
fetchTheme: '/chaos/theme',
fetchScripts: '/chaos/partners/scripts',
fetchAgreements: '/chaos/agreements',
redisThemePrefix: 'URANUS.FORGOT.PARNTERS.THEME',
redisScriptsPrefix: 'URANUS.FORGOT.PARNTERS.SCRIPTS',
redisAgreementsPrefix: 'URANUS.FORGOT.PARNTERS.Agreements',
fetchInfo: '/chaos/partner',
redisInfoPrefix: 'URANUS.FORGOT.PARNTERS.Info',
redisappKeyLimitPrefix: 'URANUS.FORGOT.PARNTERS.Limit',
};
config.lockKeys = {
taskPrefix: 'URANUS.FORGOT.TASK',
};
config.sequelize = {
datasources: [{
// 东八时区
timezone: '+08:00',
delegate: 'model',
baseDir: 'model',
dialect: 'mysql',
host: process.env.MYSQL_PACHONG_HOST || 'rds-jb-08.mysql.rds.aliyuncs.com',
database: process.env.MYSQL_DATA_SERVER_DB_NAME || 'data_service_dev',
username: process.env.MYSQL_USER || 'hexin',
password: process.env.MYSQL_PWD || 'gYUHszn9#q',
port: process.env.MYSQL_PORT || 3306,
}],
};
config.callbackUrl = process.env.CALLBACK_URL || 'https://dev-nginx.jianbing.com/forgot_server/';
return config;
};
'use strict';
// had enabled by egg
// exports.static = true;
exports.mysql = {
enable: false,
package: 'egg-mysql',
};
exports.sequelize = {
enable: true,
package: 'egg-sequelize',
};
exports.redis = {
enable: true,
package: 'egg-redis',
};
exports.routerPlus = {
enable: true,
package: 'egg-router-plus',
};
exports.cors = {
enable: true,
package: 'egg-cors',
};
exports.validate = {
enable: true,
package: 'egg-validate',
};
{
"name": "forgot_server",
"version": "1.0.0",
"description": "",
"private": true,
"dependencies": {
"egg": "^2.2.1",
"egg-cors": "^2.1.1",
"egg-mysql": "^3.0.0",
"egg-redis": "^2.3.0",
"egg-router-plus": "^1.3.0",
"egg-scripts": "^2.5.0",
"egg-sequelize": "^4.2.0",
"egg-validate": "^2.0.2",
"mysql2": "^1.6.4",
"node-cache": "^4.2.0",
"node-uuid": "^1.4.8"
},
"devDependencies": {
"autod": "^3.0.1",
"autod-egg": "^1.0.0",
"egg-bin": "^4.3.5",
"egg-ci": "^1.8.0",
"egg-mock": "^3.14.0",
"eslint": "^4.11.0",
"eslint-config-egg": "^6.0.0",
"webstorm-disable-index": "^1.2.0"
},
"engines": {
"node": ">=8.9.0"
},
"scripts": {
"start": "egg-scripts start --daemon --title=egg-server-forgot_server",
"stop": "egg-scripts stop --title=egg-server-forgot_server",
"docker": "eggctl start --title=egg-server-forgot_server",
"dev": "egg-bin dev",
"debug": "egg-bin debug",
"test": "npm run lint -- --fix && npm run test-local",
"test-local": "egg-bin test",
"cov": "egg-bin cov",
"lint": "eslint .",
"ci": "npm run lint && npm run cov",
"autod": "autod"
},
"ci": {
"version": "8"
},
"repository": {
"type": "git",
"url": ""
},
"author": "jd",
"license": "MIT"
}
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