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
ca59afe3
Commit
ca59afe3
authored
Nov 17, 2020
by
wangyong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: (messageCtl) 磐农项目 监听消息API
parent
a94910ea
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
110 additions
and
5 deletions
+110
-5
icp-deliver/app/base/controller/ctl.base.js
+3
-0
icp-deliver/app/base/controller/impl/agriculture/messageCtl.js
+49
-0
icp-deliver/app/base/controller/impl/auth/authCtl.js
+4
-2
icp-deliver/app/base/service/impl/agriculture/messageSve.js
+43
-0
icp-deliver/app/config/settings.js
+11
-3
No files found.
icp-deliver/app/base/controller/ctl.base.js
View file @
ca59afe3
...
...
@@ -94,6 +94,9 @@ class CtlBase {
}
async
doexec
(
methodname
,
pobj
,
query
,
req
)
{
try
{
if
(
methodname
==
'message'
)
{
//易代账推送消息 headers里没有x-app-key
req
.
headers
[
"xappkey"
]
=
settings
.
ydzKey
().
appKey
;
}
let
xarg
=
await
this
.
setContextParams
(
pobj
,
query
,
req
);
if
(
xarg
&&
xarg
[
0
]
<
0
)
{
return
system
.
getResultFail
(...
xarg
);
...
...
icp-deliver/app/base/controller/impl/agriculture/messageCtl.js
0 → 100644
View file @
ca59afe3
var
system
=
require
(
"../../../system"
);
const
CtlBase
=
require
(
"../../ctl.base"
);
const
CryptoJS
=
require
(
"crypto-js"
);
var
crypto
=
require
(
'crypto'
);
const
settings
=
require
(
"./../../../../config/settings"
);
/**
* @module agriculture
* @class servicelistCtl
* 服务单ctl
*/
class
messageCtl
extends
CtlBase
{
constructor
()
{
super
(
"agriculture"
,
CtlBase
.
getServiceName
(
messageCtl
));
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
);
break
;
case
"APP_TICKET"
:
res
=
await
this
.
service
.
ticketProcessing
(
meg
);
break
;
}
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"
);
}
}
module
.
exports
=
messageCtl
;
\ No newline at end of file
icp-deliver/app/base/controller/impl/auth/authCtl.js
View file @
ca59afe3
...
...
@@ -5,7 +5,7 @@ var settings = require("../../../../config/settings");
const
CtlBase
=
require
(
"../../ctl.base"
);
const
axios
=
require
(
"axios"
);
const
co
=
require
(
"co
"
);
const
jwt
=
require
(
"jsonwebtoken
"
);
class
AuthCtl
extends
CtlBase
{
constructor
()
{
...
...
@@ -50,12 +50,14 @@ class AuthCtl extends CtlBase {
}
params
[
specialKey
]
=
data
;
const
res
=
await
this
.
getRequest
(
url
,
params
);
let
deTokenExp
=
Number
((
jwt
.
decode
(
res
.
data
.
result
.
access_token
).
exp
));
let
timestamp
=
Math
.
round
(
new
Date
()
/
1000
);
if
(
res
.
data
.
code
==
200
)
{
let
ydzToken
=
{
access_token
:
res
.
data
.
result
.
access_token
,
refresh_token
:
res
.
data
.
result
.
refresh_token
}
const
addRedisResult
=
await
this
.
redisClient
.
setWithEx
(
'ydzToken'
,
JSON
.
stringify
(
ydzToken
),
6
*
24
*
60
*
60
);
const
addRedisResult
=
await
this
.
redisClient
.
setWithEx
(
'ydzToken'
,
JSON
.
stringify
(
ydzToken
),
Number
(
deTokenExp
-
timestamp
)
);
// const getRedisResult = await this.redisClient.get('ydzToken');
return
system
.
getResult
(
addRedisResult
);
}
else
{
...
...
icp-deliver/app/base/service/impl/agriculture/messageSve.js
0 → 100644
View file @
ca59afe3
const
ServiceBase
=
require
(
"../../sve.base"
);
const
redisClient
=
system
.
getObject
(
"util.redisClient"
);
const
settings
=
require
(
"./../../../../config/settings"
);
class
messageService
extends
ServiceBase
{
constructor
()
{
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;
}
}
module
.
exports
=
messageService
;
\ No newline at end of file
icp-deliver/app/config/settings.js
View file @
ca59afe3
...
...
@@ -64,14 +64,22 @@ var settings = {
if
(
this
.
env
==
"dev"
)
{
//集测环境
return
"https://inte-openapi.chanjet.com"
;
}
else
{
return
""
;
return
"
https://market.chanjet.com
"
;
}
},
ydzKey
:
function
()
{
//TODO: 易代账Key
if
(
this
.
env
==
"dev"
)
{
return
{
"appKey"
:
"qP2tgcfw"
,
"appSecret"
:
"D25E0435ACFB4844DB75E7E0F87B9F71"
};
return
{
"appKey"
:
"qP2tgcfw"
,
"appSecret"
:
"D25E0435ACFB4844DB75E7E0F87B9F71"
,
"messageSecret"
:
"1234567890123456"
};
}
else
{
return
{
"appKey"
:
""
,
"appSecret"
:
""
};
return
{
"appKey"
:
"cXqZIzIl"
,
"appSecret"
:
"B5AE885F55652CE9A4686F96A4CD90D8"
,
"messageSecret"
:
""
};
}
},
pmappid
:
1
,
...
...
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