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
db107f24
Commit
db107f24
authored
Nov 11, 2020
by
wangyong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: (authCtl) 磐农项目 openToken解决
parent
9b35fe57
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
106 additions
and
35 deletions
+106
-35
icp-deliver/app/base/controller/ctl.base.js
+0
-2
icp-deliver/app/base/controller/impl/auth/authCtl.js
+97
-16
icp-deliver/app/base/service/impl/agriculture/servicebillSve.js
+4
-4
icp-deliver/app/base/utils/ydzClient.js
+5
-13
No files found.
icp-deliver/app/base/controller/ctl.base.js
View file @
db107f24
...
@@ -17,8 +17,6 @@ class CtlBase {
...
@@ -17,8 +17,6 @@ class CtlBase {
return
system
.
getResult
(
up
);
return
system
.
getResult
(
up
);
}
}
async
create
(
pobj
,
qobj
,
req
)
{
async
create
(
pobj
,
qobj
,
req
)
{
console
.
log
(
'---------------------aaa------------------'
);
console
.
log
(
res
);
const
up
=
await
this
.
service
.
create
(
pobj
);
const
up
=
await
this
.
service
.
create
(
pobj
);
return
system
.
getResult
(
up
);
return
system
.
getResult
(
up
);
}
}
...
...
icp-deliver/app/base/controller/impl/auth/authCtl.js
View file @
db107f24
var
system
=
require
(
"../../../system"
)
var
system
=
require
(
"../../../system"
)
const
http
=
require
(
"http"
)
const
http
=
require
(
"http"
)
const
querystring
=
require
(
'querystring'
);
const
querystring
=
require
(
'querystring'
);
var
settings
=
require
(
"../../../../config/settings"
);
var
settings
=
require
(
"../../../../config/settings"
);
const
CtlBase
=
require
(
"../../ctl.base"
);
const
CtlBase
=
require
(
"../../ctl.base"
);
class
AuthCtl
extends
CtlBase
{
const
axios
=
require
(
"axios"
);
constructor
(){
super
(
"auth"
,
CtlBase
.
getServiceName
(
AuthCtl
));
class
AuthCtl
extends
CtlBase
{
}
constructor
()
{
async
saveAuths
(
pobj
,
query
,
req
){
super
(
"auth"
,
CtlBase
.
getServiceName
(
AuthCtl
));
var
auths
=
pobj
.
auths
;
this
.
redisClient
=
system
.
getObject
(
"util.redisClient"
);
var
xrtn
=
await
this
.
service
.
saveAuths
(
auths
,
pobj
.
app_id
,
pobj
.
company_id
);
}
return
system
.
getResult
(
xrtn
);
async
saveAuths
(
pobj
,
query
,
req
)
{
}
var
auths
=
pobj
.
auths
;
async
findAuthsByRoles
(
pobj
,
query
,
req
){
var
xrtn
=
await
this
.
service
.
saveAuths
(
auths
,
pobj
.
app_id
,
pobj
.
company_id
);
var
roleids
=
pobj
.
roleids
;
return
system
.
getResult
(
xrtn
);
var
xrtn
=
await
this
.
service
.
findAuthsByRole
(
roleids
,
pobj
.
app_id
,
pobj
.
company_id
);
}
return
system
.
getResult
(
xrtn
);
async
findAuthsByRoles
(
pobj
,
query
,
req
)
{
}
var
roleids
=
pobj
.
roleids
;
var
xrtn
=
await
this
.
service
.
findAuthsByRole
(
roleids
,
pobj
.
app_id
,
pobj
.
company_id
);
return
system
.
getResult
(
xrtn
);
}
/**
* 易代账获取初始化token
* @param {*} code
*/
async
getOpenToken
(
body
)
{
const
url
=
`
${
settings
.
ydzUrl
()}
/auth/getToken`
const
ydzKey
=
settings
.
ydzKey
();
let
params
=
{
grantType
:
"authorization_code"
,
appKey
:
ydzKey
.
appKey
,
redirectUri
:
""
,
code
:
body
.
code
}
const
res
=
await
this
.
getRequest
(
url
,
params
);
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 getRedisResult = await this.redisClient.get('ydzToken');
return
system
.
getResult
(
addRedisResult
);
}
else
{
return
system
.
getResultFail
(
201
,
res
.
data
.
message
);
}
}
/**
* 刷新opentoken(access_token)
*/
async
refreshToken
()
{
const
url
=
`
${
settings
.
ydzUrl
()}
/auth/refreshToken`
const
ydzKey
=
settings
.
ydzKey
();
const
getRedisResult
=
JSON
.
parse
(
await
this
.
redisClient
.
get
(
'ydzToken'
)).
refresh_token
;
let
params
=
{
grantType
:
"refresh_token"
,
appKey
:
ydzKey
.
appKey
,
refreshToken
:
getRedisResult
}
const
res
=
await
this
.
getRequest
(
url
,
params
);
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 getRedisResult = await this.redisClient.get('ydzToken');
return
system
.
getResult
(
addRedisResult
);
}
else
{
return
system
.
getResultFail
(
201
,
res
.
data
.
message
);
}
}
/**
* 公用get请求
* @param {*} url
* @param {*} data
*/
async
getRequest
(
url
,
data
=
{})
{
try
{
console
.
log
(
`
${
url
}
: 请求信息 ------- `
);
console
.
log
(
JSON
.
stringify
(
data
));
const
res
=
await
axios
.
get
(
url
,
{
params
:
data
,
headers
:
{
"Content-Type"
:
"application/json"
,
}
});
return
res
;
}
catch
(
err
)
{
console
.
log
(
`
${
url
}
: 返回错误信息 ------- `
);
console
.
log
(
err
)
throw
(
err
)
}
}
}
}
module
.
exports
=
AuthCtl
;
module
.
exports
=
AuthCtl
;
\ No newline at end of file
icp-deliver/app/base/service/impl/agriculture/servicebillSve.js
View file @
db107f24
...
@@ -103,9 +103,9 @@ class ServicebillService extends ServiceBase {
...
@@ -103,9 +103,9 @@ class ServicebillService extends ServiceBase {
taxClaimMethodEnum
:
"TAX_DECLARATION"
,
//申报方式:TAX_DECLARATION-税款申报;ZERO_DECLARATION-零申报;
taxClaimMethodEnum
:
"TAX_DECLARATION"
,
//申报方式:TAX_DECLARATION-税款申报;ZERO_DECLARATION-零申报;
isBuild
:
true
,
//是否建账
isBuild
:
true
,
//是否建账
accountBook
:
{
accountBook
:
{
name
:
`gsb_
${
findService
.
bizId
}
`
,
//账套名称
name
:
findService
.
companyInfo
.
companyName
,
//账套名称
acctgSystemId
:
findService
.
companyInfo
.
acctgSystemId
,
//会计制度;包括:10001=2013小企业会计准则;10002=2007企业会计准则;10003=民间非营利组织会计制度;10004=工会会计制度
acctgSystemId
:
findService
.
companyInfo
.
acctgSystemId
,
//会计制度;包括:10001=2013小企业会计准则;10002=2007企业会计准则;10003=民间非营利组织会计制度;10004=工会会计制度
openingPeriod
:
moment
().
year
(),
//开账期间
openingPeriod
:
`
${
moment
().
year
()}
+
${
moment
().
month
()}
`
,
//开账期间 当年当月,格式是 “YYYYMM”
taxpayerTypeEnum
:
findService
.
taxpayerType
,
//纳税性质,枚举包括:NORMAL_TAXPAYER=一般纳税人;SMALL_TAXPAYER=小规模纳税人
taxpayerTypeEnum
:
findService
.
taxpayerType
,
//纳税性质,枚举包括:NORMAL_TAXPAYER=一般纳税人;SMALL_TAXPAYER=小规模纳税人
acctgTransGroupEnum
:
'ACCTG'
//凭证类别,枚举包括:ACCTG=记账凭证等;RECEIPT_PAYMENT_TRANSFER=收付转凭证
acctgTransGroupEnum
:
'ACCTG'
//凭证类别,枚举包括:ACCTG=记账凭证等;RECEIPT_PAYMENT_TRANSFER=收付转凭证
}
}
...
@@ -115,10 +115,10 @@ class ServicebillService extends ServiceBase {
...
@@ -115,10 +115,10 @@ class ServicebillService extends ServiceBase {
mappingSetToQiFuTong
(
setInfo
,
findService
)
{
mappingSetToQiFuTong
(
setInfo
,
findService
)
{
let
toQFTSetData
=
{
let
toQFTSetData
=
{
bizId
:
findService
.
bizId
,
bizId
:
findService
.
bizId
,
subjec
tId
:
setInfo
.
custId
,
cus
tId
:
setInfo
.
custId
,
bookId
:
setInfo
.
assocTenantId
,
bookId
:
setInfo
.
assocTenantId
,
bkDomainName
:
setInfo
.
bkDomainName
,
bkDomainName
:
setInfo
.
bkDomainName
,
contactName
:
setInfo
.
customer
.
contact
Name
,
contactName
:
findService
.
companyInfo
.
company
Name
,
contactMobile
:
setInfo
.
customer
.
contactMobile
,
contactMobile
:
setInfo
.
customer
.
contactMobile
,
timeUnit
:
findService
.
timeUnit
,
timeUnit
:
findService
.
timeUnit
,
quantity
:
findService
.
quantity
,
quantity
:
findService
.
quantity
,
...
...
icp-deliver/app/base/utils/ydzClient.js
View file @
db107f24
...
@@ -2,6 +2,7 @@ const axios = require("axios");
...
@@ -2,6 +2,7 @@ const axios = require("axios");
const
settings
=
require
(
"../../config/settings"
);
const
settings
=
require
(
"../../config/settings"
);
const
system
=
require
(
"../system"
);
const
system
=
require
(
"../system"
);
const
ydzUrl
=
settings
.
ydzUrl
();
const
ydzUrl
=
settings
.
ydzUrl
();
const
redisClient
=
system
.
getObject
(
"util.redisClient"
);
/**
/**
* 请求易代账
* 请求易代账
...
@@ -10,27 +11,20 @@ const ydzUrl = settings.ydzUrl();
...
@@ -10,27 +11,20 @@ const ydzUrl = settings.ydzUrl();
const
pushYiDaZhang
=
async
(
data
=
{})
=>
{
const
pushYiDaZhang
=
async
(
data
=
{})
=>
{
const
{
appKey
,
appSecret
}
=
settings
.
ydzKey
();
const
{
appKey
,
appSecret
}
=
settings
.
ydzKey
();
// const openToken = await getOpenTokenByAppKey(appKey, appSecret);
const
openToken
=
JSON
.
parse
(
await
redisClient
.
get
(
'ydzToken'
)).
access_token
;
console
.
log
(
'----------------------------open-----------------------'
);
console
.
log
(
openToken
);
const
header
=
{
const
header
=
{
"Content-Type"
:
"application/json"
,
"Content-Type"
:
"application/json"
,
"appKey"
:
appKey
,
"appKey"
:
appKey
,
"appSecret"
:
appSecret
,
"appSecret"
:
appSecret
,
"openToken"
:
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2Nlc3NfdG9rZW4iOiJlYzQ4OTFjZS05OWIzLTQzNjAtYjMyMi04MzUyOWMxMGQ5ZjQiLCJzdWIiOiJpc3YiLCJhdWQiOiJpc3YiLCJuYmYiOjE2MDQ5NzgzOTksImFwcElkIjoiMTA2NSIsInNjb3BlIjoiYXV0aF9hbGwiLCJpc3MiOiJjaGFuamV0IiwiZXhwIjoxNjA1NDk2Nzk5LCJ1c2VySWQiOiI2MTAwMDQzMjU3NSIsImlhdCI6MTYwNDk3ODM5OSwib3JnSWQiOiI5MDAwMTIwNTYyNSIsIm9yZ0FjY291bnQiOiJ1MzEzbWN2czR5d2EifQ.gPpIvM75vL39RrcNNW3jWMw28z-5nj0JNOyHjA8LvGI"
"openToken"
:
openToken
}
}
const
manageId
=
await
getManageIdByOpenToken
(
header
);
const
manageId
=
await
getManageIdByOpenToken
(
header
);
const
pushYDZResult
=
await
postRequest
(
`
${
ydzUrl
}
/ydz/easyacctg/customer/create/
${
manageId
}
`
,
data
,
header
);
const
pushYDZResult
=
await
postRequest
(
`
${
ydzUrl
}
/ydz/easyacctg/customer/create/
${
manageId
}
`
,
data
,
header
);
return
pushYDZResult
;
return
pushYDZResult
;
}
}
const
getOpenTokenByAppKey
=
async
(
appKey
,
appSecret
)
=>
{
const
data
=
await
this
.
postRequest
(
`
${
ydzUrl
}
/api/opreceive/accessAuth/getAppTokenByAppKey`
,
{
"Content-Type"
:
"application/json"
,
"appKey"
:
appKey
,
"appSecret"
:
appSecret
});
return
data
.
token
}
const
getManageIdByOpenToken
=
async
(
headers
)
=>
{
const
getManageIdByOpenToken
=
async
(
headers
)
=>
{
const
url
=
`
${
ydzUrl
}
/ydz/setup/openAccess/MainTenant/findMainTenant`
const
url
=
`
${
ydzUrl
}
/ydz/setup/openAccess/MainTenant/findMainTenant`
const
rs
=
await
getRequest
(
url
,
{},
headers
);
const
rs
=
await
getRequest
(
url
,
{},
headers
);
...
@@ -93,7 +87,6 @@ const getRequest = async(url, data, headers = {}) => {
...
@@ -93,7 +87,6 @@ const getRequest = async(url, data, headers = {}) => {
module
.
exports
=
{
module
.
exports
=
{
pushYiDaZhang
,
pushYiDaZhang
,
getManageIdByOpenToken
,
getManageIdByOpenToken
,
// getAppTokenByAppKey,
postRequest
,
postRequest
,
getRequest
getRequest
}
}
\ 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