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
20809075
Commit
20809075
authored
Nov 19, 2020
by
wangyong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: (accounting) 磐农项目 回传会计信息调整
parent
7d23c34f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
67 deletions
+83
-67
icp-deliver/app/base/controller/impl/auth/authCtl.js
+42
-33
icp-deliver/app/base/service/impl/agriculture/messageSve.js
+3
-1
icp-deliver/app/base/service/impl/agriculture/servicebillSve.js
+10
-3
icp-deliver/app/base/utils/toQft/baseClient.js
+28
-30
No files found.
icp-deliver/app/base/controller/impl/auth/authCtl.js
View file @
20809075
...
...
@@ -7,6 +7,7 @@ const CtlBase = require("../../ctl.base");
const
axios
=
require
(
"axios"
);
const
jwt
=
require
(
"jsonwebtoken"
);
const
{
appKey
,
appSecret
}
=
settings
.
ydzKey
();
const
ydz_prefix
=
"ydz:"
;
class
AuthCtl
extends
CtlBase
{
constructor
()
{
...
...
@@ -29,13 +30,15 @@ class AuthCtl extends CtlBase {
*/
async
getAppCredentials
()
{
const
url
=
`
${
settings
.
ydzUrl
()}
/auth/appAuth/getAppAccessToken`
;
const
{
appTicket
}
=
JSON
.
parse
(
await
this
.
redisClient
.
get
(
'APP_TICKET'
)).
bizContent
;
const
{
appTicket
}
=
JSON
.
parse
(
await
this
.
redisClient
.
get
(
`
${
ydz_prefix
}
APP_TICKET`
)).
bizContent
;
const
headers
=
{
"Content-Type"
:
"application/json"
,
appKey
,
appSecret
};
return
await
this
.
postRequest
(
url
,
{
appTicket
},
headers
);
const
creRes
=
await
this
.
postRequest
(
url
,
{
appTicket
},
headers
);
const
addRedisResult
=
await
this
.
redisClient
.
setWithEx
(
`
${
ydz_prefix
}
appAccessToken`
,
JSON
.
stringify
(
creRes
.
result
));
return
creRes
.
result
;
};
/**
...
...
@@ -43,11 +46,11 @@ class AuthCtl extends CtlBase {
*/
async
getPermanentAuthCode
()
{
const
url
=
`
${
settings
.
ydzUrl
()}
/auth/orgAuth/getPermanentAuthCode`
;
const
{
result
}
=
await
this
.
getAppCredentials
(
);
//获取应用凭证
const
{
tempAuthCode
}
=
JSON
.
parse
(
await
this
.
redisClient
.
get
(
'TEMP_AUTH_CODE'
)).
bizContent
;
//
const
{
appAccessToken
}
=
JSON
.
parse
(
await
this
.
redisClient
.
get
(
`
${
ydz_prefix
}
appAccessToken`
)
);
//获取应用凭证
const
{
tempAuthCode
}
=
JSON
.
parse
(
await
this
.
redisClient
.
get
(
`
${
ydz_prefix
}
TEMP_AUTH_CODE`
)).
bizContent
;
//获取企业临时授权码
const
params
=
{
appAccessToken
:
result
.
appAccessToken
,
//应用凭证
tempAuthCode
appAccessToken
,
//应用凭证
tempAuthCode
//企业临时授权码
}
const
headers
=
{
"Content-Type"
:
"application/json"
,
...
...
@@ -56,9 +59,10 @@ class AuthCtl extends CtlBase {
};
const
perResult
=
await
this
.
postRequest
(
url
,
params
,
headers
);
if
(
perResult
.
code
==
200
)
{
// const addRedisResult = await this.redisClient.setWithEx('PERMANENT_AUTH_CODE', JSON.stringify(perResult.result));
return
perResult
.
result
;
}
else
{
console
.
log
(
'--------------getPermanentAuthCode-----ERROR-----------------'
);
console
.
log
(
perResult
)
return
system
.
getResultFail
(
perResult
);
}
}
...
...
@@ -68,13 +72,10 @@ class AuthCtl extends CtlBase {
*/
async
getOrgAccessToken
()
{
const
url
=
`
${
settings
.
ydzUrl
()}
/auth/orgAuth/getOrgAccessToken`
;
const
{
result
}
=
await
this
.
getAppCredentials
();
//获取应用凭证
const
permanentAuthCode
=
(
await
this
.
getPermanentAuthCode
()).
permanentAuthCode
;
console
.
log
(
'[[-----------'
)
console
.
log
(
permanentAuthCode
);
// const { permanentAuthCode } = JSON.parse(await this.redisClient.get('PERMANENT_AUTH_CODE')); //
const
{
appAccessToken
}
=
await
this
.
getAppCredentials
();
//获取应用凭证
const
permanentAuthCode
=
(
await
this
.
getPermanentAuthCode
()).
permanentAuthCode
;
//获取企业永久授权码
const
params
=
{
appAccessToken
:
result
.
appAccessToken
,
//应用凭证
appAccessToken
,
//应用凭证
permanentAuthCode
//企业永久授权码
}
const
headers
=
{
...
...
@@ -83,6 +84,7 @@ class AuthCtl extends CtlBase {
appSecret
};
const
OrgResult
=
await
this
.
postRequest
(
url
,
params
,
headers
);
const
addRedisResult
=
await
this
.
redisClient
.
setWithEx
(
`
${
ydz_prefix
}
orgAccessToken`
,
JSON
.
stringify
(
OrgResult
.
result
),
OrgResult
.
result
.
expireTime
);
return
OrgResult
.
result
;
}
...
...
@@ -95,11 +97,13 @@ class AuthCtl extends CtlBase {
const
url
=
`
${
settings
.
ydzUrl
()}
/auth/getToken`
;
return
await
this
.
publicTokenFun
(
url
,
"authorization_code"
,
appKey
,
body
.
code
,
"code"
);
}
else
{
//用户永久授权码
const
url
=
`
${
settings
.
ydzUrl
()}
/auth/token/getTokenByPermanentCode`
console
.
log
(
'---------------------------co---------------'
);
const
{
user_auth_permanent_code
}
=
JSON
.
parse
(
await
this
.
redisClient
.
get
(
'ydzToken'
));
const
url
=
`
${
settings
.
ydzUrl
()}
/auth/token/getTokenByPermanentCode`
;
const
{
user_auth_permanent_code
}
=
JSON
.
parse
(
await
this
.
redisClient
.
get
(
`
${
ydz_prefix
}
ydzToken`
));
//用户永久授权码
console
.
log
(
user_auth_permanent_code
);
const
{
orgAccessToken
}
=
await
this
.
getOrgAccessToken
();
//获取企业凭证
const
{
orgAccessToken
}
=
JSON
.
parse
(
await
this
.
redisClient
.
get
(
`
${
ydz_prefix
}
orgAccessToken`
));
if
(
!
orgAccessToken
)
{
orgAccessToken
=
(
await
this
.
getOrgAccessToken
()).
orgAccessToken
;
//获取企业凭证
}
const
params
=
{
orgAccessToken
,
//企业凭证
userAuthPermanentCode
:
user_auth_permanent_code
//企业永久授权码
...
...
@@ -111,8 +115,8 @@ class AuthCtl extends CtlBase {
};
const
perToTokenResult
=
await
this
.
postRequest
(
url
,
params
,
headers
);
if
(
perToTokenResult
.
code
==
200
)
{
cons
ole
.
log
(
'------------------------ssfdfdfdfdf---------'
);
console
.
log
(
perToTokenResult
);
cons
t
addRedisResult
=
await
this
.
setRedisValue
(
`
${
ydz_prefix
}
ydzToken`
,
perToTokenResult
.
result
);
return
system
.
getResultSuccess
(
perToTokenResult
)
}
else
{
return
system
.
getResultFail
(
perToTokenResult
);
}
...
...
@@ -125,7 +129,7 @@ class AuthCtl extends CtlBase {
*/
async
refreshToken
()
{
const
url
=
`
${
settings
.
ydzUrl
()}
/auth/refreshToken`
;
const
getRedisResult
=
JSON
.
parse
(
await
this
.
redisClient
.
get
(
'ydzToken'
)).
refresh_token
;
const
getRedisResult
=
JSON
.
parse
(
await
this
.
redisClient
.
get
(
`
${
ydz_prefix
}
ydzToken`
)).
refresh_token
;
return
await
this
.
publicTokenFun
(
url
,
"refresh_token"
,
appKey
,
getRedisResult
,
"refreshToken"
)
};
...
...
@@ -137,24 +141,29 @@ class AuthCtl extends CtlBase {
params
[
specialKey
]
=
data
;
const
res
=
await
this
.
getRequest
(
url
,
params
);
if
(
res
.
data
.
code
==
200
)
{
const
ydzToken
=
{
access_token
:
res
.
data
.
result
.
access_token
,
refresh_token
:
res
.
data
.
result
.
refresh_token
,
user_auth_permanent_code
:
res
.
data
.
result
.
user_auth_permanent_code
}
const
deTokenExp
=
Number
((
jwt
.
decode
(
res
.
data
.
result
.
access_token
).
exp
));
const
timestamp
=
Math
.
round
(
new
Date
()
/
1000
);
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
(
`Request:
${
JSON
.
stringify
(
res
.
data
)}
`
);
console
.
log
(
`addRedisResult:
${
addRedisResult
}
`
);
return
system
.
getResult
(
addRedisResult
);
const
addRedisResult
=
await
this
.
setRedisValue
(
`
${
ydz_prefix
}
ydzToken`
,
res
.
data
.
result
);
return
system
.
getResultSuccess
(
res
);
}
else
{
return
system
.
getResultFail
(
201
,
res
.
data
.
message
);
}
};
async
setRedisValue
(
key
,
data
)
{
const
ydzToken
=
{
access_token
:
data
.
access_token
,
refresh_token
:
data
.
refresh_token
,
user_auth_permanent_code
:
data
.
user_auth_permanent_code
}
const
deTokenExp
=
Number
((
jwt
.
decode
(
data
.
access_token
).
exp
));
const
timestamp
=
Math
.
round
(
new
Date
()
/
1000
);
const
addRedisResult
=
await
this
.
redisClient
.
setWithEx
(
key
,
JSON
.
stringify
(
ydzToken
),
Number
(
deTokenExp
-
timestamp
));
// const getRedisResult = await this.redisClient.get('ydzToken');
console
.
log
(
'------------------------------addRedisResult-----------------------'
);
console
.
log
(
`Request:
${
JSON
.
stringify
(
data
)}
`
);
console
.
log
(
`addRedisResult:
${
addRedisResult
}
`
);
return
addRedisResult
;
}
/**
* 公用get请求
* @param {*} url
...
...
icp-deliver/app/base/service/impl/agriculture/messageSve.js
View file @
20809075
...
...
@@ -2,6 +2,7 @@ const ServiceBase = require("../../sve.base");
const
settings
=
require
(
"./../../../../config/settings"
);
const
System
=
require
(
"../../../system"
);
const
redisClient
=
System
.
getObject
(
"util.redisClient"
);
const
ydz_prefix
=
"ydz:"
;
class
MessageService
extends
ServiceBase
{
constructor
()
{
...
...
@@ -11,7 +12,8 @@ class MessageService extends ServiceBase {
async
tempMsgProcessing
(
key
,
msgContent
,
time
)
{
//APP_TICKET: 每十分钟刷新一次,有效期30分钟
//TEMP_AUTH_CODE: 企业临时授权码
const
addRedisResult
=
await
redisClient
.
setWithEx
(
key
,
JSON
.
stringify
(
msgContent
),
time
);
const
perKey
=
ydz_prefix
+
key
;
const
addRedisResult
=
await
redisClient
.
setWithEx
(
perKey
,
JSON
.
stringify
(
msgContent
),
time
);
return
addRedisResult
;
}
}
...
...
icp-deliver/app/base/service/impl/agriculture/servicebillSve.js
View file @
20809075
...
...
@@ -69,9 +69,16 @@ class ServicebillService extends ServiceBase {
backData
.
note
=
findOne
.
feedback_notes
;
}
//推送企服通
await
TOQFT
.
getClientByType
(
"pannong"
).
pushQiFuTong
(
obj
.
username
,
{
"actionType"
:
"feedback"
,
"actionBody"
:
backData
});
const
result
=
await
TOQFT
.
getClientByType
(
"pannong"
).
pushQiFuTong
(
obj
.
username
,
{
"actionType"
:
"feedback"
,
"actionBody"
:
backData
});
if
(
result
.
code
==
200
)
{
return
result
;
}
else
{
console
.
log
(
result
);
throw
new
Error
(
result
);
}
}
else
{
console
.
log
(
'查无此单:'
+
obj
.
bizId
);
console
.
log
(
'未查询到此服务单'
+
obj
.
bizId
);
throw
new
Error
(
'未查询到此服务单'
+
obj
.
bizId
);
}
}
mappingQiFuTong
(
findService
,
findAccount
)
{
...
...
@@ -81,7 +88,7 @@ class ServicebillService extends ServiceBase {
accCode
:
findAccount
.
accCode
,
accName
:
findAccount
.
accName
,
accaddress
:
findAccount
.
accaddress
,
workingYears
:
findAccount
.
workingYears
,
//
workingYears: findAccount.workingYears,
accCredentials
:
findAccount
.
accCredentials
,
accAccount
:
findAccount
.
accAccount
,
accountingName
:
findAccount
.
name
,
...
...
icp-deliver/app/base/utils/toQft/baseClient.js
View file @
20809075
...
...
@@ -12,31 +12,30 @@ const qifutongUrl = settings.qifutongUrl();
*/
class
BaseClient
{
constructor
(
appKey
,
secret
,
url
)
{
this
.
appKey
=
appKey
;
this
.
secret
=
secret
;
this
.
url
=
url
}
/**
* 推送到 启服通
* @param {*} user
* @param {*} data
*/
this
.
appKey
=
appKey
;
this
.
secret
=
secret
;
this
.
url
=
url
}
/**
* 推送到 启服通
* @param {*} user
* @param {*} data
*/
async
pushQiFuTong
(
user
,
data
)
{
const
header
=
await
this
.
getLoginByUserName
(
user
);
await
this
.
postRequest
(
`
${
qifutongUrl
}${
this
.
url
}
`
,
data
,
header
);
return
await
this
.
postRequest
(
`
${
qifutongUrl
}${
this
.
url
}
`
,
data
,
header
);
}
async
getLoginByUserName
(
user
)
{
const
token
=
await
this
.
getAppTokenByAppKey
(
this
.
appKey
,
this
.
secret
);
const
data
=
await
this
.
postRequest
(
`
${
centerChannelUrl
}
/api/opreceive/accessAuth/springBoard`
,
{
"actionType"
:
"getLoginByUserName"
,
"actionBody"
:
{
"channelUserId"
:
user
,
" user"
:
user
,
"userName"
:
user
}
},
{
const
data
=
await
this
.
postRequest
(
`
${
centerChannelUrl
}
/api/opreceive/accessAuth/springBoard`
,
{
"actionType"
:
"getLoginByUserName"
,
"actionBody"
:
{
"channelUserId"
:
user
,
" user"
:
user
,
"userName"
:
user
}
},
{
token
});
return
{
...
...
@@ -46,14 +45,13 @@ class BaseClient {
}
async
getAppTokenByAppKey
(
appKey
,
secret
)
{
const
data
=
await
this
.
postRequest
(
`
${
centerChannelUrl
}
/api/opreceive/accessAuth/getAppTokenByAppKey`
,
{
"actionType"
:
"getAppTokenByAppKey"
,
"actionBody"
:
{
"appkey"
:
appKey
,
"secret"
:
secret
}
});
const
data
=
await
this
.
postRequest
(
`
${
centerChannelUrl
}
/api/opreceive/accessAuth/getAppTokenByAppKey`
,
{
"actionType"
:
"getAppTokenByAppKey"
,
"actionBody"
:
{
"appkey"
:
appKey
,
"secret"
:
secret
}
});
return
data
.
token
}
...
...
@@ -72,8 +70,7 @@ class BaseClient {
console
.
log
(
`
${
url
}
: 返回信息 ------- `
);
console
.
log
(
result
);
system
.
execLogs
(
`请求启服通`
,
{
`请求启服通`
,
{
url
,
data
,
headers
...
...
@@ -96,4 +93,4 @@ class BaseClient {
}
}
}
module
.
exports
=
BaseClient
;
module
.
exports
=
BaseClient
;
\ No newline at end of file
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