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
3917150f
Commit
3917150f
authored
Aug 28, 2020
by
DESKTOP-7Q3CA17\86137
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gsb
parent
08746d2b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
515 additions
and
33 deletions
+515
-33
bpo-web/app/base/api/impl/gemaApi.js
+132
-31
bpo-web/app/base/db/impl/qbgconfigDao.js
+10
-0
bpo-web/app/base/db/models/qbgconfig.js
+54
-0
bpo-web/app/base/db/models/usereaccount.js
+2
-2
bpo-web/app/base/service/impl/qbgconfigSve.js
+292
-0
bpo-web/app/config/settings.js
+25
-0
No files found.
bpo-web/app/base/api/impl/gemaApi.js
View file @
3917150f
//
// 北京歌马科技有限公司方案
//
// 使用签必果进行,三要素认证和静默签
//
//
// 前期数据准备
// 1. 创建企业账户和个人账户
//
// 2. 创建签约模板
//
// 3. 创建企业印章
//
//
//
//
// 接口
// 静默签约
// 先检查c_econtract中是否存在已签约记录(通过etemplate_id、身份证查询、eflowStatus='2'进行查询),存在直接返回成功,不存在去签必果api进行静默签
//
// 1. 个人三要素验证 - 签必果
//
// 2. 创建个人账户 - 签必果
//
// 3. p_user和p_user_eaccount逻辑
//
// 4. 静默签 - 签必果,签约成功后记录保存到c_econtract
//
// 按身份证查询签约
// 1. 查c_econtract和p_user_eaccount,返回签约结果
\ No newline at end of file
var
system
=
require
(
"../../system"
)
const
md5
=
require
(
"MD5"
);
const
logCtl
=
system
.
getObject
(
"web.oplogCtl"
);
const
moment
=
require
(
"moment"
);
const
uuidv1
=
require
(
'uuid/v1'
);
class
GemaApi
{
constructor
()
{
this
.
etemplatebusiSve
=
system
.
getObject
(
"service.etemplatebusiSve"
);
this
.
esettleSve
=
system
.
getObject
(
"service.esettleSve"
);
this
.
qbgconfigSve
=
system
.
getObject
(
"service.qbgconfigSve"
);
this
.
redisLock
=
system
.
getObject
(
"util.redisLock"
);
this
.
idcardClient
=
system
.
getObject
(
"util.idcardClient"
);
}
//三要素验证
async
autoSign
(
pobj
)
{
// 处理参数
var
param
=
{
ecid
:
this
.
trim
(
pobj
.
ecid
),
appId
:
this
.
trim
(
pobj
.
appId
),
userId
:
this
.
trim
(
pobj
.
userId
),
idName
:
this
.
trim
(
pobj
.
idName
),
mobile
:
this
.
trim
(
pobj
.
mobile
),
idNo
:
this
.
trim
(
pobj
.
idNo
),
bankno
:
this
.
trim
(
pobj
.
bankno
),
nonceStr
:
this
.
trim
(
pobj
.
nonceStr
),
sign
:
this
.
trim
(
pobj
.
sign
)
};
if
(
!
param
.
ecid
)
{
return
this
.
returnjson
(
-
1
,
"请传入薪必果提供的ecid"
)
}
if
(
!
param
.
appId
)
{
return
this
.
returnjson
(
-
1
,
"请传入薪必果提供的appId"
)
}
if
(
!
param
.
userId
)
{
return
this
.
returnjson
(
-
1
,
"请提供该用户的userId"
)
}
if
(
!
param
.
idName
)
{
return
this
.
returnjson
(
-
1
,
"请提供该用户姓名"
)
}
if
(
!
param
.
idNo
)
{
return
this
.
returnjson
(
-
1
,
"请提供该用户身份证号"
)
}
if
(
!
await
this
.
idcardClient
.
checkIDCard
(
param
.
idNo
))
{
return
this
.
returnjson
(
-
1
,
"身份证格式不正确"
);
}
let
card
=
await
this
.
idcardClient
.
cardInfo
(
param
.
idNo
);
let
age
=
card
.
age
||
0
;
if
(
!
age
)
{
return
this
.
returnjson
(
-
1
,
"身份证号格式错误, 只支持18位身份证号码"
);
}
if
(
card
.
sex
==
'male'
)
{
if
(
age
<
18
||
age
>
60
)
{
return
this
.
returnjson
(
-
1
,
"签约失败,男限制18-60岁之间"
)
}
}
else
{
if
(
age
<
18
||
age
>
55
)
{
return
this
.
returnjson
(
-
1
,
"签约失败,女限制18-55岁之间"
)
}
}
if
(
!
param
.
bankno
)
{
return
this
.
returnjson
(
-
1
,
"请提供该用户银行卡号"
)
}
if
(
!
param
.
nonceStr
)
{
return
this
.
returnjson
(
-
1
,
"请提供随机码"
)
}
// 查appId关联key
var
qbg
=
await
this
.
qbgconfigSve
.
findOne
({
appId
:
param
.
appId
});
if
(
!
qbg
||
!
qbg
.
key
)
{
return
this
.
returnjson
(
1001003
,
"配置信息错误,请联系薪必果人员进行配置"
);
}
// 签名
var
signArr
=
[];
var
keys
=
Object
.
keys
(
param
).
sort
();
for
(
var
i
=
0
;
i
<
keys
.
length
;
i
++
)
{
var
k
=
keys
[
i
];
var
v
=
param
[
k
];
if
(
!
k
||
!
v
||
k
==
'sign'
)
{
continue
;
}
signArr
.
push
(
k
+
"="
+
v
);
}
var
signStr
=
signArr
.
join
(
"&"
)
+
"&key="
+
qbg
.
key
;
var
sign
=
md5
(
signStr
).
toUpperCase
();
console
.
log
(
"---autoSign---签名---"
,
signStr
,
sign
);
if
(
param
.
sign
!=
sign
)
{
return
this
.
returnjson
(
1001001
,
`签名错误`
);
}
try
{
param
.
idNo
=
param
.
idNo
.
toUpperCase
();
param
.
bankno
=
param
.
bankno
.
replace
(
/
\s
*/g
,
""
);
var
key
=
param
.
idNo
+
"_"
+
param
.
ecid
const
id
=
uuidv1
();
await
this
.
redisLock
.
lock
(
key
,
id
,
20
);
var
result
=
await
this
.
qbgconfigSve
.
autoSign
(
param
,
qbg
);
await
this
.
redisLock
.
unLock
(
key
,
id
);
return
result
;
}
catch
(
error
)
{
console
.
log
(
error
);
}
}
trim
(
o
)
{
if
(
!
o
)
{
return
""
;
}
return
o
.
toString
().
trim
();
}
returnjson
(
code
,
msg
,
data
)
{
return
{
code
:
code
,
msg
:
msg
,
data
:
data
||
null
}
}
}
module
.
exports
=
GemaApi
;
bpo-web/app/base/db/impl/qbgconfigDao.js
0 → 100644
View file @
3917150f
const
system
=
require
(
"../../system"
);
const
Dao
=
require
(
"../dao.base"
);
class
QbgconfigDao
extends
Dao
{
constructor
()
{
super
(
Dao
.
getModelName
(
QbgconfigDao
));
}
}
module
.
exports
=
QbgconfigDao
;
bpo-web/app/base/db/models/qbgconfig.js
0 → 100644
View file @
3917150f
module
.
exports
=
(
db
,
DataTypes
)
=>
{
return
db
.
define
(
"qbgconfig"
,
{
appid
:
DataTypes
.
STRING
,
merchant_id
:
DataTypes
.
STRING
,
seal_id
:
DataTypes
.
STRING
,
key
:
DataTypes
.
STRING
,
template_id
:
DataTypes
.
STRING
,
initiator_account
:
DataTypes
.
STRING
,
merchant_name
:
DataTypes
.
STRING
,
ecompany_id
:
DataTypes
.
INTEGER
,
},{
paranoid
:
true
,
//假的删除
underscored
:
true
,
version
:
true
,
freezeTableName
:
true
,
//freezeTableName: true,
// define the table's name
tableName
:
'qbg_config'
,
validate
:
{
},
indexes
:[
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
bpo-web/app/base/db/models/usereaccount.js
View file @
3917150f
...
...
@@ -9,6 +9,7 @@ module.exports = (db, DataTypes) => {
eaccountid
:
DataTypes
.
STRING
,
bankno
:
DataTypes
.
STRING
(
30
),
email
:
DataTypes
.
STRING
(
50
),
esign_account
:
DataTypes
.
STRING
(
50
),
// 打零工新增字段
headUrl
:
DataTypes
.
STRING
(
300
),
...
...
@@ -109,4 +110,4 @@ module.exports = (db, DataTypes) => {
// }
]
});
}
\ No newline at end of file
}
bpo-web/app/base/service/impl/qbgconfigSve.js
0 → 100644
View file @
3917150f
const
system
=
require
(
"../../system"
);
const
ServiceBase
=
require
(
"../sve.base"
);
const
settings
=
require
(
"../../../config/settings"
);
const
moment
=
require
(
'moment'
);
const
axios
=
require
(
"axios"
);
const
md5
=
require
(
"MD5"
);
class
QbgconfigService
extends
ServiceBase
{
constructor
()
{
super
(
ServiceBase
.
getDaoName
(
QbgconfigService
));
this
.
econtractDao
=
system
.
getObject
(
"db.econtractDao"
)
this
.
userDao
=
system
.
getObject
(
"db.userDao"
)
this
.
usereaccountDao
=
system
.
getObject
(
"db.usereaccountDao"
)
this
.
API
=
settings
.
signApi
();
this
.
restClient
=
system
.
getObject
(
"util.restClient"
);
this
.
EXCEPT_KEYS
=
[
'sign'
,
'requestid'
,
'simpleFormFields'
];
this
.
redisClient
=
system
.
getObject
(
"util.redisClient"
);
}
/**
* 静默签 带三要素验证
* @param {ecid, appId, userId, idName, mobile, idNo, bankno, nonceStr, sign} params
*/
async
autoSign
(
params
,
qbg
)
{
let
ecid
=
params
.
ecid
;
// 验证身份证是否签约过
let
todays
=
moment
().
format
(
"YYYY-MM-DD"
)
+
" 00:00:00"
;
let
contractId
=
await
this
.
econtractDao
.
findSignedContractId
({
idno
:
params
.
idNo
,
ecid
:
ecid
,
today
:
todays
})
||
0
;
if
(
contractId
)
{
return
this
.
returnjson
(
0
,
"用户已经签约"
,
{
contractId
:
contractId
});
}
//1、三要素验证
var
bankthreeParamss
=
{
appId
:
params
.
appId
,
timestamp
:
new
Date
().
getTime
(),
nonceStr
:
params
.
nonceStr
,
idName
:
params
.
idName
,
idNo
:
params
.
idNo
,
bankNo
:
params
.
bankno
}
bankthreeParamss
.
sign
=
await
this
.
getsign
(
bankthreeParamss
,
qbg
.
key
);
let
bankthrees
=
await
axios
({
method
:
'post'
,
url
:
this
.
API
.
bankThree
,
data
:
bankthreeParamss
,
});
console
.
log
(
"三要素收费三要素请求返回==================================================="
,
bankthrees
);
if
(
bankthrees
.
data
.
status
==
0
&&
!
bankthrees
.
data
.
data
.
pass
)
{
return
this
.
returnjson
(
-
1
,
bankthrees
.
data
.
msg
);
}
//2、 创建账户--p_user
var
unionId
=
params
.
appId
+
"_"
+
params
.
ecid
+
"_"
+
params
.
userId
;
var
user
=
await
this
.
userDao
.
findOne
({
unionId
:
unionId
,
});
if
(
!
user
)
{
user
=
await
this
.
userDao
.
create
({
appkey
:
params
.
appId
,
unionId
:
unionId
,
userId3rd
:
params
.
userId
,
userName
:
params
.
idName
,
mobile
:
params
.
mobile
,
utype
:
0
,
});
}
// p_user_eaccount
var
eaccount
=
await
this
.
usereaccountDao
.
findOne
({
user_id
:
user
.
id
,
personsSign
:
params
.
idNo
,
})
||
{};
eaccount
.
user_id
=
user
.
id
;
eaccount
.
userName
=
params
.
idName
;
eaccount
.
mobile
=
params
.
mobile
;
eaccount
.
bankno
=
params
.
bankno
;
eaccount
.
personsSign
=
params
.
idNo
;
if
(
eaccount
.
id
)
{
await
eaccount
.
save
();
}
else
{
eaccount
=
await
this
.
usereaccountDao
.
create
(
eaccount
);
}
//创建账户
if
(
eaccount
.
id
&&
!
eaccount
.
esign_account
)
{
var
createAccount
=
{
appId
:
params
.
appId
,
timestamp
:
new
Date
().
getTime
(),
nonceStr
:
params
.
nonceStr
,
idName
:
params
.
idName
,
idNo
:
params
.
idNo
,
mobile
:
params
.
mobile
}
createAccount
.
sign
=
await
this
.
getsign
(
createAccount
,
qbg
.
key
);
let
qbgaccount
=
await
axios
({
method
:
'post'
,
url
:
this
.
API
.
createAccount
,
data
:
createAccount
,
});
console
.
log
(
qbgaccount
)
if
(
qbgaccount
.
data
.
status
==
0
&&
!
qbgaccount
.
data
.
data
.
accountId
)
{
return
this
.
returnjson
(
-
1
,
bankthrees
.
data
.
msg
);
}
eaccount
.
esign_account
=
qbgaccount
.
data
.
data
.
accountId
;
eaccount
.
save
();
}
var
today
=
moment
().
format
(
"YYYY-MM-DD"
)
//发起签署
var
toecontract
=
{
appId
:
params
.
appId
,
nonceStr
:
params
.
nonceStr
,
timestamp
:
new
Date
().
getTime
(),
initiatorAccountId
:
qbg
.
initiator_account
,
accountId
:
eaccount
.
esign_account
,
channel
:
1
,
contractName
:
qbg
.
merchant_name
,
simpleFormFields
:
{
nameA
:
qbg
.
merchant_name
,
nameB
:
params
.
idName
,
signDateA
:
today
,
signDateB
:
today
},
templateId
:
params
.
ecid
}
var
sign
=
await
this
.
getsign
(
toecontract
,
qbg
.
key
)
toecontract
.
sign
=
sign
;
console
.
log
(
toecontract
)
let
econtr
=
await
axios
({
method
:
'post'
,
url
:
this
.
API
.
autoSign
,
data
:
toecontract
,
});
console
.
log
(
econtr
)
// 创建合同
let
econtract
=
{
name
:
qbg
.
merchant_name
,
eflowstatusname
:
"签约中"
,
eflowstatus
:
"1"
,
user_id
:
eaccount
.
user_id
,
usereaccount_id
:
eaccount
.
id
,
etemplate_id
:
qbg
.
template_id
,
ecompany_id
:
qbg
.
ecompany_id
,
};
econtract
=
await
this
.
econtractDao
.
create
(
econtract
);
if
(
econtr
&&
econtr
.
data
&&
econtr
.
data
.
status
==
0
)
{
econtract
.
eflowid
=
econtr
.
data
.
data
.
flowId
;
econtract
.
edocid
=
econtr
.
data
.
data
.
docId
;
econtract
.
eflowstatus
=
'2'
;
econtract
.
eflowstatusname
=
"已完成"
;
var
signTime
=
new
Date
();
econtract
.
completed_at
=
signTime
;
econtract
.
begin_at
=
signTime
;
var
end_at
=
new
Date
();
end_at
.
setFullYear
(
end_at
.
getFullYear
()
+
1
);
econtract
.
end_at
=
end_at
;
await
econtract
.
save
();
this
.
syncSign
(
econtract
.
id
);
this
.
redisClient
.
rpushBCD
({
id
:
econtract
.
id
,
sve
:
"e"
});
return
this
.
returnjson
(
0
,
"success"
,
{
contractId
:
econtract
.
id
});
}
return
this
.
returnjson
(
-
1
,
econtr
.
data
.
msg
||
"签约失败"
,
econtr
.
data
.
status
);
}
async
getsign
(
params
,
secret
)
{
let
keys
=
Object
.
keys
(
params
).
sort
();
let
signArr
=
[];
for
(
let
k
=
0
;
k
<
keys
.
length
;
k
++
)
{
let
tKey
=
keys
[
k
];
if
(
this
.
EXCEPT_KEYS
.
indexOf
(
tKey
)
==
-
1
&&
params
[
tKey
])
{
signArr
.
push
(
tKey
+
"="
+
params
[
tKey
]);
}
}
let
signStr
=
signArr
.
join
(
"&"
)
+
"&key="
+
secret
;
let
sign
=
md5
(
signStr
).
toUpperCase
();
return
sign
;
}
returnjson
(
code
,
msg
,
data
)
{
return
{
code
:
code
,
msg
:
msg
,
data
:
data
||
null
}
}
async
syncSign
(
contractId
)
{
var
contract
=
await
this
.
dao
.
findById
(
contractId
);
if
(
!
contract
)
{
return
null
;
}
var
account
=
await
this
.
usereaccountDao
.
findById
(
contract
.
usereaccount_id
);
if
(
!
account
)
{
return
null
;
}
var
user
=
await
this
.
userDao
.
findById
(
account
.
user_id
);
var
busi
=
await
this
.
ecompanybusiDao
.
findOne
({
etemplate_id
:
contract
.
enttemplate_id
});
if
(
!
account
.
isPush
&&
busi
&&
busi
.
postsignurl
)
{
var
param
=
{
"appId"
:
busi
.
appId
,
"idNo"
:
account
.
personsSign
,
"idName"
:
account
.
userName
,
"bankNo"
:
account
.
bankno
,
"mobile"
:
account
.
mobile
,
"appId3rd"
:
user
.
appId3rd
||
""
,
"userCode3rd"
:
user
.
userCode3rd
||
""
,
"userId3rd"
:
user
.
userId3rd
||
""
,
"branchCode3rd"
:
user
.
branchCode3rd
||
""
,
"nonceStr"
:
await
this
.
getUidStr
(
16
),
"beginDate"
:
await
this
.
formateTime
(
contract
.
begin_at
),
"endDate"
:
await
this
.
formateTime
(
contract
.
end_at
),
};
if
(
!
user
.
userCode3rd
&&
!
user
.
userId3rd
)
{
param
.
openId
=
user
.
openId
;
}
if
(
this
.
ydCompanyIds
.
indexOf
(
contract
.
entcompany_id
)
>
-
1
)
{
param
.
pbType
=
"eSign"
;
}
var
signArr
=
[];
signArr
.
push
(
"appId="
+
param
.
appId
);
signArr
.
push
(
"appId3rd="
+
param
.
appId3rd
);
signArr
.
push
(
"bankNo="
+
param
.
bankNo
);
signArr
.
push
(
"beginDate="
+
param
.
beginDate
);
signArr
.
push
(
"branchCode3rd="
+
param
.
branchCode3rd
);
signArr
.
push
(
"endDate="
+
param
.
endDate
);
signArr
.
push
(
"idName="
+
param
.
idName
);
signArr
.
push
(
"idNo="
+
param
.
idNo
);
signArr
.
push
(
"mobile="
+
param
.
mobile
);
signArr
.
push
(
"nonceStr="
+
param
.
nonceStr
);
if
(
!
user
.
userCode3rd
&&
!
user
.
userId3rd
)
{
signArr
.
push
(
"openId="
+
param
.
openId
);
}
// if (contract.ecompany_id == 10173 || contract.ecompany_id == 10174 || contract.ecompany_id == 10175 || contract.ecompany_id == 10207) {
if
(
this
.
ydCompanyIds
.
indexOf
(
contract
.
entcompany_id
)
>
-
1
)
{
signArr
.
push
(
"pbType=eSign"
);
}
signArr
.
push
(
"userCode3rd="
+
param
.
userCode3rd
);
signArr
.
push
(
"userId3rd="
+
param
.
userId3rd
);
signArr
.
push
(
"key="
+
busi
.
key
);
param
.
sign
=
md5
(
signArr
.
join
(
"&"
)).
toUpperCase
();
console
.
log
(
JSON
.
stringify
(
param
));
var
rs
=
""
;
try
{
var
rs
=
await
this
.
restClient
.
execPost
(
param
,
busi
.
postsignurl
);
if
(
rs
.
stdout
)
{
let
rsData
=
JSON
.
parse
(
rs
.
stdout
);
if
(
rsData
.
code
==
"0"
||
rsData
.
code
==
"0000"
)
{
account
.
isPush
=
true
;
account
.
save
();
}
}
return
rs
.
stdout
;
}
catch
(
error
)
{
console
.
log
(
rs
,
"push sign url "
+
busi
.
postsignurl
,
"rs = "
+
rs
);
console
.
log
(
error
);
return
"error"
;
}
}
}
}
module
.
exports
=
QbgconfigService
;
bpo-web/app/config/settings.js
View file @
3917150f
...
...
@@ -30,6 +30,31 @@ var settings = {
return
"http://43.247.184.94:7200/"
;
}
},
signApi
:
function
()
{
let
domain
=
''
;
if
(
this
.
env
==
"dev"
)
{
domain
=
"http://39.107.234.14:3603"
;
}
else
{
domain
=
"https://qianbiguo-api.gongsibao.com"
;
}
return
{
//三要素验证
"bankThree"
:
`
${
domain
}
/api/sign/authApi/bankThree`
,
//创个人账户
"createAccount"
:
`
${
domain
}
/api/sign/signApi/createAccount`
,
//发起签署
"autoSign"
:
`
${
domain
}
/api/sign/signApi/autoSign`
,
//创建企业模板印章
"organize"
:
`
${
domain
}
/sign/seal/create/organize`
,
//创建公司图片印章
"organizeimage"
:
`
${
domain
}
/sign/seal/create/organize/image`
,
};
},
localPath
:
function
()
{
var
os
=
require
(
"os"
);
let
platform
=
os
.
platform
()
||
""
;
...
...
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