Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋勇
zhichan
Commits
3a86566a
Commit
3a86566a
authored
Nov 18, 2020
by
wangyong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: (auth/settings) 磐农项目 易代账API地址修改
parent
f4265bd7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
68 deletions
+65
-68
icp-deliver/app/base/controller/impl/agriculture/messageCtl.js
+37
-27
icp-deliver/app/base/controller/impl/auth/authCtl.js
+4
-1
icp-deliver/app/base/service/impl/agriculture/messageSve.js
+12
-35
icp-deliver/app/config/settings.js
+12
-5
No files found.
icp-deliver/app/base/controller/impl/agriculture/messageCtl.js
View file @
3a86566a
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
servicelist
Ctl
*
服务单
ctl
* @class
message
Ctl
*
消息
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
(
me
g
);
case
"APP_TICKET"
:
// 应用票据
await
this
.
service
.
tempMsgProcessing
(
plaintextMsg
.
msgType
,
plaintextMs
g
);
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
icp-deliver/app/base/controller/impl/auth/authCtl.js
View file @
3a86566a
...
...
@@ -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
);
...
...
icp-deliver/app/base/service/impl/agriculture/messageSve.js
View file @
3a86566a
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
m
essageService
extends
ServiceBase
{
class
M
essageService
extends
ServiceBase
{
constructor
()
{
super
(
"agriculture"
,
ServiceBase
.
getDaoName
(
m
essageService
));
super
(
"agriculture"
,
ServiceBase
.
getDaoName
(
M
essageService
));
}
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
icp-deliver/app/config/settings.js
View file @
3a86566a
...
...
@@ -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"
,
"m
essage
Secret"
:
"1234567890123456"
"m
sg
Secret"
:
"1234567890123456"
};
}
else
{
return
{
"appKey"
:
"cXqZIzIl"
,
"appSecret"
:
"B5AE885F55652CE9A4686F96A4CD90D8"
,
"m
essageSecret"
:
"
"
"m
sgSecret"
:
"WzeZ6EwkIAzUsa56
"
};
}
},
javaUrl
:
function
()
{
if
(
this
.
env
==
"dev"
)
{
return
""
;
}
else
{
return
""
;
}
},
pmappid
:
1
,
pmcompanyid
:
1
,
pmroleid
:
{
"ta"
:
1
,
"pr"
:
2
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment