Commit 3a86566a by wangyong

feat: (auth/settings) 磐农项目 易代账API地址修改

parent f4265bd7
var system = require("../../../system");
const CtlBase = require("../../ctl.base");
const CryptoJS = require("crypto-js");
var crypto = require('crypto');
const crypto = require("crypto");
const settings = require("./../../../../config/settings");
/**
* @module agriculture
* @class servicelistCtl
* 服务单ctl
* @class messageCtl
* 消息ctl
*/
class messageCtl extends CtlBase {
......@@ -16,33 +15,43 @@ class messageCtl extends CtlBase {
this.servicebillCtl = system.getObject("service.agriculture.servicebillCtl");
}
async message(meg) {
console.log('-----------------------------message--------------------');
console.log(meg)
const res = {};
switch (meg.type) {
case "CREATE_ACCOUNTING":
res = await this.servicebillCtl.create(meg);
async message(msg) {
const key = settings.ydzKey().msgSecret;
const plaintextMsg = this.decryptMessage(key, msg.encryptMsg);
console.log('-----------------------msg--------------------');
console.log(plaintextMsg);
switch (plaintextMsg.msgType) {
case "CREATE_ACCOUNTING": //新建会计
await this.servicebillCtl.create(plaintextMsg);
break;
case "APP_TICKET":
res = await this.service.ticketProcessing(meg);
case "APP_TICKET": // 应用票据
await this.service.tempMsgProcessing(plaintextMsg.msgType, plaintextMsg);
break;
case "TEMP_AUTH_CODE": //企业临时授权码
await this.service.tempMsgProcessing(plaintextMsg.msgType, plaintextMsg);
}
return { "result": "success" };
}
zeropad(inputData, length = 8) {
inputData = Buffer.from(inputData, "utf8").toString("hex");
const bitLength = inputData.length * length;
if (bitLength < 256) {
for (i = bitLength; i < 256; i += length) {
inputData += 0;
}
} else if (bitLength > 256) {
while ((inputData.length * length) % 256 != 0) {
inputData += 0;
}
}
return Buffer.from(inputData, "hex").toString("utf8");
};
/**
* 解密消息内容
* @param {string} key 16位密钥
* @param {string} msgContent 加密串儿
* @return {object} decryptMessage
*/
decryptMessage(key, msgContent) {
var iv = "";
var clearEncoding = 'utf8';
var cipherEncoding = 'base64';
var cipherChunks = [];
var decipher = crypto.createDecipheriv('aes-128-ecb', key, iv);
decipher.setAutoPadding(true);
cipherChunks.push(decipher.update(msgContent, cipherEncoding, clearEncoding));
cipherChunks.push(decipher.final(clearEncoding));
const decryptMessage = JSON.parse(cipherChunks.join(''));
return decryptMessage;
}
}
module.exports = messageCtl;
\ No newline at end of file
......@@ -25,7 +25,7 @@ class AuthCtl extends CtlBase {
/**
* 易代账获取初始化token
* @param {*} code
* @param {*} code 企业授权码
*/
async getOpenToken(body) {
const url = `${settings.ydzUrl()}/auth/getToken`
......@@ -59,6 +59,9 @@ class AuthCtl extends CtlBase {
}
const addRedisResult = await this.redisClient.setWithEx('ydzToken', JSON.stringify(ydzToken), Number(deTokenExp - timestamp));
// const getRedisResult = await this.redisClient.get('ydzToken');
console.log('------------------------------addRedisResult-----------------------');
console.log(ydzToken)
console.log(addRedisResult);
return system.getResult(addRedisResult);
} else {
return system.getResultFail(201, res.data.message);
......
const ServiceBase = require("../../sve.base");
const redisClient = system.getObject("util.redisClient");
const settings = require("./../../../../config/settings");
const System = require("../../../system");
const redisClient = System.getObject("util.redisClient");
class messageService extends ServiceBase {
class MessageService extends ServiceBase {
constructor() {
super("agriculture", ServiceBase.getDaoName(messageService));
super("agriculture", ServiceBase.getDaoName(MessageService));
}
async ticketProcessing(meg) {
const messageSecret = settings.ydzKey().messageSecret; // 密钥 16 位
const iv = messageSecret; // 初始向量 initial vector 16 位, messageSecret 和 iv 可以一致
//const data = CryptoJS.enc.Utf8.parse(meg.encryptMsg);
// console.log('-----------------data-------------------');
// console.log(meg.encryptMsg);
// var decrypted = CryptoJS.AES.decrypt(data, messageSecret, {
// iv: iv,
// mode: CryptoJS.mode.CBC,
// padding: CryptoJS.pad.Pkcs7
// });
// // 转换为 utf8 字符串
// console.log('---------------------------before -------------');
// console.log(decrypted);
// decrypted = CryptoJS.enc.Utf8.stringify(decrypted);
// console.log('------------------------decrypted--------------------')
// console.log(decrypted)
// console.log(iv.length);
// var clearEncoding = 'utf8'
// var cipherEncoding = 'base64'
// var cipherChunks = []
// var decipher = crypto.createCipheriv('aes-128-ecb', messageSecret, iv)
// decipher.setAutoPadding(false)
// cipherChunks.push(decipher.update(this.zeropad(meg.encryptMsg, 8), clearEncoding, cipherEncoding))
// cipherChunks.push(decipher.final(cipherEncoding))
// console.log(cipherChunks.join('').toUpperCase());
// return cipherChunks.join('').toUpperCase();
// const addRedisResult = await this.redisClient.setWithEx('APP_TICKET', JSON.stringify(obj), 2 * 60 * 60); //俩小时
// return addRedisResult;
async tempMsgProcessing(key, msgContent) {
//临时存储30分钟
//APP_TICKET: 每十分钟刷新一次,有效期30分钟
//TEMP_AUTH_CODE: 企业临时授权码
const addRedisResult = await redisClient.setWithEx(key, JSON.stringify(msgContent), 30 * 60);
return addRedisResult;
}
}
module.exports = messageService;
\ No newline at end of file
module.exports = MessageService;
\ No newline at end of file
......@@ -60,28 +60,35 @@ var settings = {
return "http://sytxpublic-msgq-service.chaolai/api/queueAction/producer/springBoard";
}
},
ydzUrl: function() { //TODO: 易代账URL
ydzUrl: function() { // 易代账URL
if (this.env == "dev") { //集测环境
return "https://inte-openapi.chanjet.com";
} else {
return "https://market.chanjet.com";
return "https://openapi.chanjet.com";
}
},
ydzKey: function() { //TODO: 易代账Key
ydzKey: function() { // 易代账Key
if (this.env == "dev") {
return {
"appKey": "qP2tgcfw",
"appSecret": "D25E0435ACFB4844DB75E7E0F87B9F71",
"messageSecret": "1234567890123456"
"msgSecret": "1234567890123456"
};
} else {
return {
"appKey": "cXqZIzIl",
"appSecret": "B5AE885F55652CE9A4686F96A4CD90D8",
"messageSecret": ""
"msgSecret": "WzeZ6EwkIAzUsa56"
};
}
},
javaUrl: function() {
if (this.env == "dev") {
return "";
} else {
return "";
}
},
pmappid: 1,
pmcompanyid: 1,
pmroleid: { "ta": 1, "pr": 2 },
......
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