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
e7ed0bd2
Commit
e7ed0bd2
authored
Jul 04, 2020
by
zhaoxiqing
Browse files
Options
Browse Files
Download
Plain Diff
gsb
parents
ae503322
40a744af
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
733 additions
and
185 deletions
+733
-185
esign-api/app/base/api/api.base.js
+60
-71
esign-api/app/base/api/impl/op/action.js
+1
-48
esign-api/app/base/api/impl/sign/authApi.js
+71
-0
esign-api/app/base/api/impl/sign/signApi.js
+106
-0
esign-api/app/base/db/impl/common/tradelogDao.js
+11
-0
esign-api/app/base/db/models/common/tradelog.js
+30
-0
esign-api/app/base/service/impl/fee/feeSve.js
+2
-48
esign-api/app/base/service/impl/merchant/merchantSve.js
+23
-2
esign-api/app/base/service/impl/order/orderSve.js
+43
-0
esign-api/app/base/service/impl/order/orderauthlogSve.js
+20
-0
esign-api/app/base/service/impl/order/orderproductSve.js
+21
-0
esign-api/app/base/service/impl/order/ordersignlogSve.js
+20
-0
esign-api/app/base/service/impl/product/productSve.js
+35
-0
esign-api/app/base/service/impl/sign/authSve.js
+153
-8
esign-api/app/base/service/impl/sign/signSve.js
+133
-2
esign-api/app/base/system.js
+4
-6
No files found.
esign-api/app/base/api/api.base.js
View file @
e7ed0bd2
...
@@ -6,9 +6,10 @@ const md5 = require("MD5");
...
@@ -6,9 +6,10 @@ const md5 = require("MD5");
class
APIBase
extends
DocBase
{
class
APIBase
extends
DocBase
{
constructor
()
{
constructor
()
{
super
();
super
();
this
.
cacheManager
=
system
.
getObject
(
"db.common.cacheManager"
);
this
.
merchantSve
=
system
.
getObject
(
"service.merchant.merchantSve"
);
this
.
logCtl
=
system
.
getObject
(
"web.common.oplogCtl"
);
this
.
oplogSve
=
system
.
getObject
(
"service.common.oplogSve"
);
this
.
oplogSve
=
system
.
getObject
(
"service.common.oplogSve"
);
this
.
SIGN_GNAME
=
[
'sign'
];
this
.
EXCEPT_KEYS
=
[
'sign'
,
'requestid'
];
}
}
getUUID
()
{
getUUID
()
{
var
uuid
=
uuidv4
();
var
uuid
=
uuidv4
();
...
@@ -21,96 +22,87 @@ class APIBase extends DocBase {
...
@@ -21,96 +22,87 @@ class APIBase extends DocBase {
}
}
return
o
.
toString
().
trim
();
return
o
.
toString
().
trim
();
}
}
/**
async
validSign
(
params
)
{
* 验证签名
* @param {*} params 要验证的参数
let
appId
=
this
.
trim
(
params
.
appId
);
* @param {*} app_key 应用的校验key
let
timestamp
=
Number
(
params
.
timestamp
);
*/
let
nonceStr
=
this
.
trim
(
params
.
nonceStr
);
async
verifySign
(
params
,
app_key
)
{
let
now
=
new
Date
().
getTime
();
if
(
!
params
)
{
if
(
now
-
timestamp
>
60
*
60
*
60
*
1000
)
{
return
system
.
getResult
(
null
,
"请求参数为空"
);
return
system
.
getResultFail
(
1000000
,
"请求超时"
);
}
if
(
!
appId
)
{
return
system
.
getResultFail
(
1000000
,
"请填写appId"
);
}
}
if
(
!
params
.
sign
)
{
if
(
!
nonceStr
)
{
return
system
.
getResult
(
null
,
"请求参数sign
为空"
);
return
system
.
getResult
Fail
(
1000000
,
"随机码
为空"
);
}
}
if
(
!
params
.
times_tamp
)
{
return
system
.
getResult
(
null
,
"请求参数times_tamp为空"
);
// TODO redis通过sign幂等验证
// 幂等验证代码xxxx
let
app
=
await
this
.
merchantSve
.
apiWidthCache
({
id
:
appId
})
if
(
!
app
||
!
app
.
id
)
{
return
system
.
getResultFail
(
1000000
,
"appId不存在"
);
}
}
var
signArr
=
[];
if
(
!
app
.
is_enabled
)
{
var
keys
=
Object
.
keys
(
params
).
sort
();
return
system
.
getResultFail
(
1000000
,
"该应用已失效"
);
if
(
keys
.
length
==
0
)
{
return
system
.
getResult
(
null
,
"请求参数信息为空"
);
}
}
if
(
!
app
.
merchant_id
)
{
return
system
.
getResultFail
(
1000000
,
"该应用未绑定商户"
);
}
let
keys
=
Object
.
keys
(
params
).
sort
();
let
signArr
=
[];
for
(
let
k
=
0
;
k
<
keys
.
length
;
k
++
)
{
for
(
let
k
=
0
;
k
<
keys
.
length
;
k
++
)
{
cons
t
tKey
=
keys
[
k
];
le
t
tKey
=
keys
[
k
];
if
(
t
Key
!=
"sign"
&&
params
[
tKey
])
{
if
(
t
his
.
EXCEPT_KEYS
.
indexOf
(
tKey
)
==
-
1
&&
params
[
tKey
])
{
signArr
.
push
(
tKey
+
"="
+
params
[
tKey
]);
signArr
.
push
(
tKey
+
"="
+
params
[
tKey
]);
}
}
}
}
if
(
signArr
.
length
==
0
)
{
return
system
.
getResult
(
null
,
"请求参数组装签名参数信息为空"
);
let
signStr
=
signArr
.
join
(
"&"
)
+
"&key="
+
app
.
secret
;
}
let
sign
=
md5
(
signStr
).
toUpperCase
();
var
resultSignStr
=
signArr
.
join
(
"&"
)
+
"&key="
+
app_key
;
console
.
log
(
params
.
sign
,
signStr
,
sign
);
var
resultTmpSign
=
md5
(
resultSignStr
).
toUpperCase
();
if
(
params
.
sign
!=
sign
)
{
if
(
params
.
sign
!=
resultTmpSign
)
{
return
system
.
getResultFail
(
1001001
,
this
.
getSignErrorMsg
(
sign
));
return
system
.
getResult
(
null
,
"签名验证失败"
);
}
}
params
.
app
=
app
;
return
system
.
getResultSuccess
();
return
system
.
getResultSuccess
();
}
}
/**
* 白名单验证
getSignErrorMsg
(
sign
)
{
* @param {*} gname 组名
let
signErrorMsg
=
"签名验证失败"
;
* @param {*} methodname 方法名
if
(
settings
.
env
==
"dev"
)
{
*/
signErrorMsg
=
signErrorMsg
+
"---"
+
sign
;
async
isCheckWhiteList
(
gname
,
methodname
)
{
}
var
fullname
=
gname
+
"."
+
methodname
;
return
signErrorMsg
;
var
lst
=
[
"test.testApi"
];
var
x
=
lst
.
indexOf
(
fullname
);
return
x
>=
0
;
}
}
async
checkAcck
(
gname
,
methodname
,
pobj
,
query
,
req
)
{
var
appInfo
=
null
;
async
checkSign
(
gname
,
params
)
{
var
result
=
system
.
getResultSuccess
();
if
(
this
.
SIGN_GNAME
.
indexOf
(
gname
)
!=
-
1
)
{
var
ispass
=
await
this
.
isCheckWhiteList
(
gname
,
methodname
);
return
await
this
.
validSign
(
params
);
var
appkey
=
req
.
headers
[
"accesskey"
];
var
app_id
=
req
.
headers
[
"app_id"
];
if
(
ispass
)
{
return
result
;
}
//在白名单里面
if
(
app_id
)
{
// var signResult = await this.verifySign(pobj.action_body, appInfo.appSecret);
// if (signResult.status != 0) {
// result.status = system.signFail;
// result.msg = signResult.msg;
// }
}
//验签
else
if
(
appkey
)
{
appInfo
=
await
this
.
cacheManager
[
"ApiAccessKeyCheckCache"
].
cache
(
appkey
,
{
status
:
true
},
3000
);
if
(
!
appInfo
||
!
appInfo
.
app
)
{
result
.
status
=
system
.
tokenFail
;
result
.
msg
=
"请求头accesskey失效,请重新获取"
;
}
}
//验证accesskey
else
{
result
.
status
=
-
1
;
result
.
msg
=
"请求头没有相关访问参数,请验证后在进行请求"
;
}
}
return
result
;
return
system
.
getResultSuccess
()
;
}
}
async
doexec
(
gname
,
methodname
,
pobj
,
query
,
req
)
{
async
doexec
(
gname
,
methodname
,
pobj
,
query
,
req
)
{
var
requestid
=
this
.
getUUID
();
var
requestid
=
this
.
getUUID
();
pobj
.
requestid
=
requestid
;
let
rtn
;
let
rtn
;
try
{
try
{
let
signRes
=
await
this
.
checkSign
(
gname
,
pobj
);
if
(
signRes
.
status
!==
0
)
{
return
signRes
;
}
rtn
=
await
this
[
methodname
](
pobj
,
query
,
req
)
||
{};
rtn
=
await
this
[
methodname
](
pobj
,
query
,
req
)
||
{};
rtn
.
requestid
=
requestid
;
rtn
.
requestid
=
requestid
;
return
rtn
;
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
log
(
e
.
stack
,
"api调用出现异常,请联系管理员.........."
)
console
.
log
(
e
.
stack
,
"api调用出现异常,请联系管理员.........."
)
rtn
=
system
.
getResultFail
(
-
200
,
"出现异常,请联系管理员"
);
rtn
=
system
.
getResultFail
(
-
200
,
"出现异常,请联系管理员"
);
rtn
.
requestid
=
requestid
;
rtn
.
requestid
=
requestid
;
}
return
rtn
;
tr
y
{
}
finall
y
{
this
.
oplogSve
.
createDb
({
this
.
oplogSve
.
createDb
({
appid
:
""
,
appid
:
""
,
appkey
:
""
,
appkey
:
""
,
...
@@ -122,10 +114,7 @@ class APIBase extends DocBase {
...
@@ -122,10 +114,7 @@ class APIBase extends DocBase {
agent
:
req
.
uagent
,
agent
:
req
.
uagent
,
opTitle
:
"api服务提供方appKey:"
+
settings
.
appKey
,
opTitle
:
"api服务提供方appKey:"
+
settings
.
appKey
,
});
});
}
catch
(
e
)
{
console
.
log
(
new
Date
(),
requestid
,
e
.
stack
);
}
}
return
rtn
;
}
}
}
}
module
.
exports
=
APIBase
;
module
.
exports
=
APIBase
;
...
...
esign-api/app/base/api/impl/op/action.js
View file @
e7ed0bd2
...
@@ -8,7 +8,7 @@ class ActionAPI extends APIBase {
...
@@ -8,7 +8,7 @@ class ActionAPI extends APIBase {
this
.
authSve
=
system
.
getObject
(
"service.sign.authSve"
);
this
.
authSve
=
system
.
getObject
(
"service.sign.authSve"
);
this
.
merchantSve
=
system
.
getObject
(
"service.merchant.merchantSve"
);
this
.
merchantSve
=
system
.
getObject
(
"service.merchant.merchantSve"
);
// this.userSve = system.getObject("service.user.userSve");
// this.userSve = system.getObject("service.user.userSve");
this
.
enginsignSve
=
system
.
getObject
(
"service.engine.enginesignSve"
);
this
.
enginsignSve
=
system
.
getObject
(
"service.engine.enginesignSve"
);
}
}
/**
/**
* 接口跳转
* 接口跳转
...
@@ -25,11 +25,6 @@ class ActionAPI extends APIBase {
...
@@ -25,11 +25,6 @@ class ActionAPI extends APIBase {
return
system
.
getResult
(
null
,
"action_type参数不能为空"
);
return
system
.
getResult
(
null
,
"action_type参数不能为空"
);
}
}
try
{
try
{
// 验证签名
let
signRes
=
await
this
.
validSign
(
pobj
.
action_body
);
if
(
signRes
.
status
!==
0
)
{
return
signRes
;
}
result
=
await
this
.
handleRequest
(
pobj
.
action_process
,
pobj
.
action_type
,
pobj
.
action_body
);
result
=
await
this
.
handleRequest
(
pobj
.
action_process
,
pobj
.
action_type
,
pobj
.
action_body
);
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
);
console
.
log
(
error
);
...
@@ -78,48 +73,6 @@ class ActionAPI extends APIBase {
...
@@ -78,48 +73,6 @@ class ActionAPI extends APIBase {
return
opResult
;
return
opResult
;
}
}
async
validSign
(
params
)
{
// 1000000 报文参数问题 1001001 签名错误
let
appId
=
this
.
trim
(
params
.
appId
);
let
timestamp
=
Number
(
params
.
timestamp
);
let
nonceStr
=
Number
(
params
.
nonceStr
);
let
now
=
new
Date
().
getTime
();
if
(
now
-
timestamp
>
60
*
60
*
60
*
1000
)
{
return
system
.
getResultFail
(
1000000
,
"请求超时"
);
}
if
(
!
appId
)
{
return
system
.
getResultFail
(
1000000
,
"请填写appId"
);
}
if
(
!
nonceStr
)
{
return
system
.
getResultFail
(
1000000
,
"随机码为空"
);
}
// TODO redis通过sign幂等验证
// 幂等验证代码xxxx
let
app
=
await
this
.
merchantSve
.
apiInfo
({
id
:
appId
})
if
(
!
app
.
data
||
!
app
.
data
.
id
)
{
return
system
.
getResultFail
(
1000000
,
"appId不存在"
);
}
app
=
app
.
data
;
let
keys
=
Object
.
keys
(
params
).
sort
();
let
signArr
=
[];
for
(
let
k
=
0
;
k
<
keys
.
length
;
k
++
)
{
let
tKey
=
keys
[
k
];
if
(
tKey
!=
"sign"
&&
params
[
tKey
])
{
signArr
.
push
(
tKey
+
"="
+
params
[
tKey
]);
}
}
let
sign
=
md5
(
signArr
.
join
(
"&"
)
+
"&key="
+
app
.
secret
).
toUpperCase
();
console
.
log
(
sign
);
console
.
log
(
params
.
sign
,
sign
);
if
(
params
.
sign
!=
sign
)
{
return
system
.
getResultFail
(
1001001
,
"签名验证失败"
);
}
return
system
.
getResultSuccess
();
}
exam
()
{
exam
()
{
return
`<pre><pre/>`
;
return
`<pre><pre/>`
;
}
}
...
...
esign-api/app/base/api/impl/sign/authApi.js
0 → 100644
View file @
e7ed0bd2
var
APIBase
=
require
(
"../../api.base"
);
var
system
=
require
(
"../../../system"
);
class
TestAPI
extends
APIBase
{
constructor
()
{
super
();
this
.
authSve
=
system
.
getObject
(
"service.sign.authSve"
);
}
async
nameTwo
(
pobj
,
query
,
req
)
{
try
{
return
await
this
.
authSve
.
nameTwo
(
pobj
);
}
catch
(
e
)
{
console
.
log
(
e
);
return
system
.
getResultFail
(
500
,
"请求异常"
)
}
}
async
bankThree
(
pobj
,
query
,
req
)
{
try
{
return
await
this
.
authSve
.
bankThree
(
pobj
);
}
catch
(
e
)
{
console
.
log
(
e
);
return
system
.
getResultFail
(
500
,
"请求异常"
)
}
}
async
bankFour
(
pobj
,
query
,
req
)
{
try
{
return
await
this
.
authSve
.
bankFour
(
pobj
);
}
catch
(
e
)
{
console
.
log
(
e
);
return
system
.
getResultFail
(
500
,
"请求异常"
)
}
}
exam
()
{
return
""
;
}
classDesc
()
{
return
{
groupName
:
""
,
groupDesc
:
""
,
name
:
""
,
desc
:
""
,
exam
:
""
,
};
}
methodDescs
()
{
return
[
{
methodDesc
:
""
,
methodName
:
""
,
paramdescs
:
[
{
paramDesc
:
""
,
paramName
:
""
,
paramType
:
""
,
defaultValue
:
""
,
}
],
rtnTypeDesc
:
""
,
rtnType
:
""
}
];
}
}
module
.
exports
=
TestAPI
;
esign-api/app/base/api/impl/sign/signApi.js
0 → 100644
View file @
e7ed0bd2
var
APIBase
=
require
(
"../../api.base"
);
var
system
=
require
(
"../../../system"
);
class
SignAPI
extends
APIBase
{
constructor
()
{
super
();
this
.
signSve
=
system
.
getObject
(
"service.sign.signSve"
);
}
/**
* 创建模板
* @param pobj
* @returns {Promise<{msg: *, data: *, status: *}|*|undefined>}
*/
async
createTemplate
(
pobj
,
query
,
req
)
{
try
{
return
await
this
.
signSve
.
createTemplate
(
pobj
);
}
catch
(
e
)
{
console
.
log
(
e
);
return
system
.
getResultFail
(
500
,
"请求异常"
)
}
}
/**
* 创建个人账户
* @param req
* @returns {Promise<{msg: *, data: *, status: *}|*|undefined>}
*/
async
createAccount
(
pobj
,
query
,
req
)
{
try
{
return
await
this
.
signSve
.
createAccount
(
pobj
);
}
catch
(
e
)
{
console
.
log
(
e
);
return
system
.
getResultFail
(
500
,
"请求异常"
)
}
}
/**
* 创建企业印章
* @param req
* @returns {Promise<{msg: *, data: *, status: *}|*|undefined>}
*/
async
createEntSeal
(
pobj
,
query
,
req
)
{
try
{
return
await
this
.
signSve
.
createEntSeal
(
pobj
);
}
catch
(
e
)
{
console
.
log
(
e
);
return
system
.
getResultFail
(
500
,
"请求异常"
)
}
}
// 静默签
async
autoSign
(
pobj
,
query
,
req
)
{
try
{
return
await
this
.
signSve
.
autoSign
(
pobj
);
}
catch
(
e
)
{
console
.
log
(
e
);
return
system
.
getResultFail
(
500
,
"请求异常"
)
}
}
// 手动签
async
handSign
(
pobj
,
query
,
req
)
{
try
{
return
await
this
.
signSve
.
handSign
(
pobj
);
}
catch
(
e
)
{
console
.
log
(
e
);
return
system
.
getResultFail
(
500
,
"请求异常"
)
}
}
exam
()
{
return
""
;
}
classDesc
()
{
return
{
groupName
:
""
,
groupDesc
:
""
,
name
:
""
,
desc
:
""
,
exam
:
""
,
};
}
methodDescs
()
{
return
[
{
methodDesc
:
""
,
methodName
:
""
,
paramdescs
:
[
{
paramDesc
:
""
,
paramName
:
""
,
paramType
:
""
,
defaultValue
:
""
,
}
],
rtnTypeDesc
:
""
,
rtnType
:
""
}
];
}
}
module
.
exports
=
SignAPI
;
esign-api/app/base/db/impl/common/tradelogDao.js
0 → 100644
View file @
e7ed0bd2
const
system
=
require
(
"../../../system"
);
const
Dao
=
require
(
"../../dao.base"
);
class
TradeLogDao
extends
Dao
{
constructor
()
{
super
(
Dao
.
getModelName
(
TradeLogDao
));
}
}
module
.
exports
=
TradeLogDao
;
\ No newline at end of file
esign-api/app/base/db/models/common/tradelog.js
0 → 100644
View file @
e7ed0bd2
const
system
=
require
(
"../../../system"
);
const
settings
=
require
(
"../../../../config/settings"
);
const
uiconfig
=
system
.
getUiConfig2
(
settings
.
appKey
);
module
.
exports
=
(
db
,
DataTypes
)
=>
{
return
db
.
define
(
"tradelog"
,
{
requestid
:
DataTypes
.
STRING
,
merchant_id
:
DataTypes
.
STRING
,
product_id
:
DataTypes
.
STRING
,
trade_amt
:
DataTypes
.
BIGINT
,
result
:
DataTypes
.
INTEGER
,
fee
:
{
type
:
DataTypes
.
BOOLEAN
,
defaultValue
:
false
},
fee_remark
:
DataTypes
.
STRING
,
},
{
paranoid
:
false
,
//假的删除
underscored
:
true
,
version
:
true
,
freezeTableName
:
true
,
//freezeTableName: true,
// define the table's name
tableName
:
'api_trade_log'
,
validate
:
{
},
indexes
:
[
]
});
}
esign-api/app/base/service/impl/fee/feeSve.js
View file @
e7ed0bd2
...
@@ -7,59 +7,14 @@ class FeeService extends ServiceBase {
...
@@ -7,59 +7,14 @@ class FeeService extends ServiceBase {
// 引擎不可以引用任何
// 引擎不可以引用任何
}
}
/**
// 交易计费
* 账户查询
async
trade
(
params
)
{
* @param params
* account_id: 账户id
* @returns
*/
async
account
(
params
)
{
try
{
return
await
this
.
callms
(
"engine_fee"
,
"accountInfo"
,
params
);
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
/**
* @param params
* {
* "currentPage": 1,
* "pageSize": 10,
* "account_id": "1",
* "trade_type": "1",
* "trade_no": "123313",
* "tradeTimeBegin": "2020-06-26 04:21:31",
* "tradeTimeEnd": "2020-06-26 05:11:31"
* }
* @returns
*/
async
accountTradePage
(
params
)
{
try
{
try
{
return
await
this
.
callms
(
"engine_fee"
,
"accountTrade"
,
params
);
return
await
this
.
callms
(
"engine_fee"
,
"accountTrade"
,
params
);
}
catch
(
error
)
{
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
}
}
/**
* account_id
* @param params
* {
* "account_id": "1",
* "trade_type": "1",
* "trade_nos": ['1','2'],
* }
* @returns {Promise<{msg: string, data: (*|null), bizmsg: string, status: number}|{msg: string, data, bizmsg: *|string, status: number}|any|undefined>}
*/
async
tradeMapByIds
(
params
)
{
try
{
return
await
this
.
callms
(
"engine_fee"
,
"tradeMapByIds"
,
params
);
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
}
}
module
.
exports
=
FeeService
;
module
.
exports
=
FeeService
;
\ No newline at end of file
esign-api/app/base/service/impl/merchant/merchantSve.js
View file @
e7ed0bd2
...
@@ -4,11 +4,32 @@ const ServiceBase = require("../../svems.base")
...
@@ -4,11 +4,32 @@ const ServiceBase = require("../../svems.base")
class
MerchantService
extends
ServiceBase
{
class
MerchantService
extends
ServiceBase
{
constructor
()
{
constructor
()
{
super
();
super
();
this
.
redisClient
=
system
.
getObject
(
"util.redisClient"
);
this
.
APP_CACHE_KEY
=
"APP_CACHE_KEY_"
;
}
}
async
apiInfo
(
params
)
{
async
apiInfoById
(
params
)
{
let
apires
=
await
this
.
callms
(
"sve_merchant"
,
"apiInfoById"
,
params
)
||
{};
return
apires
.
data
;
}
async
apiWidthCache
(
params
)
{
try
{
try
{
return
await
this
.
callms
(
"sve_merchant"
,
"apiInfoById"
,
params
);
let
key
=
this
.
APP_CACHE_KEY
+
params
.
app_id
;
let
app
=
await
this
.
redisClient
.
get
(
key
);
if
(
app
)
{
app
=
JSON
.
parse
(
app
);
}
if
(
!
app
||
!
app
.
id
||
params
.
forceUpdate
)
{
app
=
await
this
.
apiInfoById
(
params
);
if
(
!
app
)
{
// TODO 缓存穿透,暂时不做,没时间了
return
null
;
}
await
this
.
redisClient
.
setWithEx
(
key
,
JSON
.
stringify
(
app
),
60
*
5
);
return
app
;
}
return
app
;
}
catch
(
error
)
{
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
...
...
esign-api/app/base/service/impl/order/orderSve.js
0 → 100644
View file @
e7ed0bd2
const
system
=
require
(
"../../../system"
);
const
ServiceBase
=
require
(
"../../svems.base"
)
class
OrderService
extends
ServiceBase
{
constructor
()
{
super
();
this
.
orderproductSve
=
system
.
getObject
(
"service.order.orderproductSve"
);
this
.
productSve
=
system
.
getObject
(
"service.product.productSve"
);
}
async
getMerchantOrderProduct
(
merchantId
,
apiPrev
)
{
let
orderProductList
=
await
this
.
orderproductSve
.
getMerchantLiveProduct
({
merchant_id
:
merchantId
});
if
(
!
orderProductList
||
orderProductList
.
length
==
0
)
{
return
system
.
getResultFail
(
1002001
,
"暂无可用订单,请先下单"
);
}
let
productIds
=
[];
for
(
let
op
of
orderProductList
)
{
productIds
.
push
(
Number
(
op
.
product_id
||
0
));
}
let
productMap
=
await
this
.
productSve
.
getMapByIds
({
ids
:
productIds
});
productMap
=
productMap
.
data
;
let
orderProduct
;
for
(
let
op
of
orderProductList
)
{
let
product
=
productMap
[
Number
(
op
.
product_id
||
0
)];
if
(
product
.
api
&&
product
.
api
.
startsWith
(
apiPrev
))
{
orderProduct
=
op
;
orderProduct
.
channel
=
Number
(
product
.
api
.
split
(
"_"
)[
1
]);
break
;
}
}
if
(
!
orderProduct
)
{
return
system
.
getResultFail
(
1002002
,
"订单未设置该产品"
);
}
return
system
.
getResultSuccess
(
orderProduct
);
}
}
module
.
exports
=
OrderService
;
\ No newline at end of file
esign-api/app/base/service/impl/order/orderauthlogSve.js
0 → 100644
View file @
e7ed0bd2
const
system
=
require
(
"../../../system"
);
const
ServiceBase
=
require
(
"../../svems.base"
)
class
OrderAuthlogService
extends
ServiceBase
{
constructor
()
{
super
();
}
/**
* fn:保存身份认证日志
* @param params
* @returns {Promise<void>}
*/
async
saveEorderAuthLog
(
params
){
return
await
this
.
callms
(
"sve_order"
,
"saveEorderAuthLog"
,
params
);
}
}
module
.
exports
=
OrderAuthlogService
;
\ No newline at end of file
esign-api/app/base/service/impl/order/orderproductSve.js
0 → 100644
View file @
e7ed0bd2
const
system
=
require
(
"../../../system"
);
const
ServiceBase
=
require
(
"../../svems.base"
)
class
OrderProductService
extends
ServiceBase
{
constructor
()
{
super
();
}
// 查商户下订单可用产品
async
getMerchantLiveProduct
(
params
)
{
let
res
=
await
this
.
callms
(
"sve_order"
,
"getMerchantLiveProduct"
,
params
);
if
(
res
.
status
==
0
)
{
return
res
.
data
;
}
return
[];
}
}
module
.
exports
=
OrderProductService
;
\ No newline at end of file
esign-api/app/base/service/impl/order/ordersignlogSve.js
0 → 100644
View file @
e7ed0bd2
const
system
=
require
(
"../../../system"
);
const
ServiceBase
=
require
(
"../../svems.base"
)
class
OrderSignLogService
extends
ServiceBase
{
constructor
()
{
super
();
}
/**
* fn:保存签约日志
* @param params
* @returns {Promise<void>}
*/
async
saveEorderSignLog
(
params
){
return
await
this
.
callms
(
"sve_order"
,
"saveEorderSignLog"
,
params
);
}
}
module
.
exports
=
OrderSignLogService
;
\ No newline at end of file
esign-api/app/base/service/impl/product/productSve.js
0 → 100644
View file @
e7ed0bd2
const
system
=
require
(
"../../../system"
);
const
ServiceBase
=
require
(
"../../svems.base"
)
class
ProductService
extends
ServiceBase
{
constructor
()
{
super
();
}
async
getByIds
(
params
)
{
try
{
return
await
this
.
callms
(
"engine_product"
,
"getByIds"
,
params
)
}
catch
(
error
)
{
throw
error
}
}
async
getMapByIds
(
params
)
{
try
{
return
await
this
.
callms
(
"engine_product"
,
"getMapByIds"
,
params
)
}
catch
(
error
)
{
throw
error
}
}
async
apiMap
(
params
)
{
try
{
return
await
this
.
callms
(
"engine_product"
,
"apiMap"
,
params
)
}
catch
(
error
)
{
throw
error
}
}
}
module
.
exports
=
ProductService
;
\ No newline at end of file
esign-api/app/base/service/impl/sign/authSve.js
View file @
e7ed0bd2
...
@@ -3,37 +3,182 @@ const ServiceBase = require("../../svems.base")
...
@@ -3,37 +3,182 @@ const ServiceBase = require("../../svems.base")
class
AuthService
extends
ServiceBase
{
class
AuthService
extends
ServiceBase
{
constructor
()
{
constructor
()
{
// 1000000 报文参数问题 1001001 签名错误 1002001费用不足 1002002 订单未设置该产品
super
();
super
();
this
.
feeSve
=
system
.
getObject
(
"service.fee.feeSve"
);
this
.
orderSve
=
system
.
getObject
(
"service.order.orderSve"
);
this
.
orderauthlogSve
=
system
.
getObject
(
"service.order.orderauthlogSve"
);
this
.
enginesignSve
=
system
.
getObject
(
"service.engine.enginesignSve"
);
this
.
tradelogDao
=
system
.
getObject
(
"db.common.tradelogDao"
);
}
}
async
nameTwo
(
params
)
{
async
nameTwo
(
params
)
{
try
{
try
{
// 通过应用id查询商户订单信息,确定产品认证接口
let
idName
=
this
.
trim
(
params
.
idName
);
return
this
.
doAuth
(
params
);
let
idNo
=
this
.
trim
(
params
.
idNo
).
toUpperCase
();
if
(
!
idName
)
{
return
system
.
getResultFail
(
1000000
,
"姓名错误"
);
}
if
(
!
idNo
)
{
return
system
.
getResultFail
(
1000000
,
"身份证错误"
);
}
params
.
apiName
=
"nameTwo"
;
return
this
.
authentication
(
params
,
async
(
p
)
=>
{
return
await
this
.
enginesignSve
.
TwoFactorVerification
({
id_name
:
idName
,
id_no
:
idNo
,
channel
:
p
.
orderProduct
.
channel
,
auth_type
:
2
,
});
});
}
catch
(
error
)
{
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
console
.
log
(
error
);
return
system
.
getResultFail
(
500
,
`系统错误 错误信息
${
error
}
`
);
}
}
}
}
async
bankThree
(
params
)
{
async
bankThree
(
params
)
{
try
{
try
{
return
this
.
doAuth
(
params
);
let
idName
=
this
.
trim
(
params
.
idName
);
let
idNo
=
this
.
trim
(
params
.
idNo
).
toUpperCase
();
let
bankNo
=
this
.
trim
(
params
.
bankNo
);
if
(
!
idName
)
{
return
system
.
getResultFail
(
1000000
,
"姓名错误"
);
}
if
(
!
idNo
)
{
return
system
.
getResultFail
(
1000000
,
"身份证错误"
);
}
if
(
!
bankNo
)
{
return
system
.
getResultFail
(
1000000
,
"银行卡号错误"
);
}
params
.
apiName
=
"bankThree"
;
return
this
.
authentication
(
params
,
async
(
p
)
=>
{
let
validRes
=
await
this
.
enginesignSve
.
ThreeFactorVerification
({
id_name
:
idName
,
id_no
:
idNo
,
bank_no
:
bankNo
,
channel
:
p
.
orderProduct
.
channel
,
auth_type
:
2
,
});
return
validRes
;
});
}
catch
(
error
)
{
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
}
}
async
bankFour
(
params
)
{
async
bankFour
(
params
)
{
try
{
try
{
return
this
.
doAuth
(
params
);
let
idName
=
this
.
trim
(
params
.
idName
);
let
idNo
=
this
.
trim
(
params
.
idNo
).
toUpperCase
();
let
bankNo
=
this
.
trim
(
params
.
bankNo
);
let
mobile
=
this
.
trim
(
params
.
mobile
);
if
(
!
idName
)
{
return
system
.
getResultFail
(
1000000
,
"姓名错误"
);
}
if
(
!
idNo
)
{
return
system
.
getResultFail
(
1000000
,
"身份证错误"
);
}
if
(
!
bankNo
)
{
return
system
.
getResultFail
(
1000000
,
"银行卡号错误"
);
}
if
(
!
mobile
)
{
return
system
.
getResultFail
(
1000000
,
"银行卡号错误"
);
}
params
.
apiName
=
"bankFour"
;
return
this
.
authentication
(
params
,
async
(
p
)
=>
{
let
validRes
=
await
this
.
enginesignSve
.
FourFactorVerification
({
id_name
:
idName
,
id_no
:
idNo
,
bank_no
:
bankNo
,
mobile
:
mobile
,
channel
:
p
.
orderProduct
.
channel
,
auth_type
:
2
,
});
return
validRes
;
});
}
catch
(
error
)
{
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
}
}
async
doAuth
(
params
)
{
async
authentication
(
params
,
validMethod
)
{
// 1. 扣费
let
app
=
params
.
app
;
let
merchantId
=
app
.
merchant_id
;
// 获取订单产品
let
orderProduct
=
await
this
.
orderSve
.
getMerchantOrderProduct
(
merchantId
,
params
.
apiName
);
if
(
orderProduct
.
status
!==
0
)
{
return
orderProduct
;
}
orderProduct
=
orderProduct
.
data
;
params
.
orderProduct
=
orderProduct
;
// 扣费
let
tres
=
await
this
.
trade
(
params
);
if
(
tres
.
status
!==
0
)
{
return
tres
;
}
let
tradeLog
=
tres
.
data
.
tradeLog
;
let
trade
=
tres
.
data
.
trade
;
// 2. 调用认证引擎
// 2. 调用认证引擎
// 3. 异步调用订单消费逻辑
let
res
=
await
validMethod
(
params
);
let
pass
=
res
.
status
===
0
;
// 生成订单
let
logres
=
await
this
.
orderauthlogSve
.
saveEorderAuthLog
({
order_id
:
orderProduct
.
id
,
product_id
:
orderProduct
.
product_id
,
platform_name
:
app
.
name
,
platform_id
:
app
.
id
,
spended_num
:
trade
.
trade_amt
,
user_name
:
params
.
idName
,
// 使用方
actual_spend_name
:
app
.
merchant_name
,
// 实际使用方
engine_trade_id
:
trade
.
id
,
pass
:
pass
?
1
:
0
});
console
.
log
(
logres
);
// 4. 返回认证结果
// 4. 返回认证结果
return
system
.
getResultSuccess
({
pass
:
pass
},
res
.
msg
);
}
// 交易
async
trade
(
params
)
{
let
orderProduct
=
params
.
orderProduct
;
let
trade_amt
=
1
;
if
(
orderProduct
==
2
)
{
trade_amt
=
Number
(
orderProduct
.
price
);
}
let
tradeLog
=
await
this
.
tradelogDao
.
create
({
requestid
:
params
.
requestid
,
merchant_id
:
orderProduct
.
merchant_id
,
product_id
:
orderProduct
.
product_id
,
trade_amt
:
trade_amt
,
result
:
0
,
});
let
tradeRes
=
await
this
.
feeSve
.
trade
({
account_id
:
orderProduct
.
engine_account_id
,
trade_amt
:
trade_amt
,
trade_no
:
tradeLog
.
id
,
trade_desc
:
"二要素验证"
,
});
if
(
tradeRes
.
status
!==
0
)
{
tradeLog
.
result
=
2
;
tradeLog
.
fee
=
0
;
tradeLog
.
fee_remark
=
"扣费失败,"
+
tradeRes
.
msg
;
await
tradeLog
.
save
();
return
system
.
getResultFail
(
1002001
,
"扣费失败,"
+
tradeRes
.
msg
);
}
else
{
tradeLog
.
result
=
1
;
tradeLog
.
fee
=
1
;
tradeLog
.
fee_remark
=
"扣费成功"
;
await
tradeLog
.
save
();
}
return
system
.
getResultSuccess
({
tradeLog
:
tradeLog
,
trade
:
tradeRes
.
data
})
}
}
}
}
...
...
esign-api/app/base/service/impl/sign/signSve.js
View file @
e7ed0bd2
...
@@ -4,26 +4,156 @@ const ServiceBase = require("../../svems.base")
...
@@ -4,26 +4,156 @@ const ServiceBase = require("../../svems.base")
class
AuthService
extends
ServiceBase
{
class
AuthService
extends
ServiceBase
{
constructor
()
{
constructor
()
{
super
();
super
();
this
.
feeSve
=
system
.
getObject
(
"service.fee.feeSve"
);
this
.
orderSve
=
system
.
getObject
(
"service.order.orderSve"
);
this
.
orderauthlogSve
=
system
.
getObject
(
"service.order.orderauthlogSve"
);
this
.
enginesignSve
=
system
.
getObject
(
"service.engine.enginesignSve"
);
this
.
tradelogDao
=
system
.
getObject
(
"db.common.tradelogDao"
);
}
}
async
createAccount
(
params
)
{
async
createAccount
(
params
)
{
try
{
try
{
// 通过应用id查询商户订单信息,确定产品认证接口
params
.
apiName
=
"sign@"
;
params
.
isFee
=
false
;
// 验证参数
let
idName
=
this
.
trim
(
params
.
idName
);
let
idNo
=
this
.
trim
(
params
.
idNo
).
toUpperCase
();
let
mobile
=
this
.
trim
(
params
.
mobile
);
if
(
!
idName
)
{
return
system
.
getResultFail
(
1000000
,
"姓名错误"
);
}
if
(
!
idNo
)
{
return
system
.
getResultFail
(
1000000
,
"身份证错误"
);
}
return
this
.
operatorSign
(
params
,
async
(
p
)
=>
{
// 调用创建账户API
let
validRes
=
await
this
.
enginesignSve
.
createAccount
({
id_name
:
idName
,
id_no
:
idNo
,
mobile
:
mobile
,
channel
:
p
.
orderProduct
.
channel
,
});
return
validRes
;
});
}
catch
(
error
)
{
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
}
}
async
createTemplate
(
params
)
{
async
createTemplate
(
params
)
{
try
{
try
{
params
.
apiName
=
"sign@"
;
params
.
isFee
=
false
;
}
catch
(
error
)
{
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
}
}
async
sign
(
params
)
{
async
handSign
(
params
)
{
try
{
try
{
params
.
apiName
=
"sign@hand"
;
params
.
isFee
=
true
;
}
catch
(
error
)
{
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
}
}
async
autosign
(
params
)
{
params
.
apiName
=
"sign@auto"
;
params
.
isFee
=
true
;
try
{
}
catch
(
error
)
{
return
system
.
getResult
(
null
,
`系统错误 错误信息
${
error
}
`
);
}
}
async
operatorSign
(
params
,
operatorMethod
)
{
let
app
=
params
.
app
;
let
merchantId
=
app
.
merchant_id
;
let
isFee
=
params
.
isFee
;
// 获取订单产品
let
orderProduct
=
await
this
.
orderSve
.
getMerchantOrderProduct
(
merchantId
,
params
.
apiName
);
if
(
orderProduct
.
status
!==
0
)
{
return
orderProduct
;
}
orderProduct
=
orderProduct
.
data
;
params
.
orderProduct
=
orderProduct
;
// 扣费
let
tradeLog
;
let
trade
;
if
(
isFee
)
{
let
tres
=
await
this
.
trade
(
params
);
if
(
tres
.
status
!==
0
)
{
return
tres
;
}
trade
=
tres
.
data
.
trade
;
}
// 2. 调用签约引擎接口
let
res
=
await
operatorMethod
(
params
);
if
(
isFee
)
{
// 生成订单
// let logres = await this.orderauthlogSve.saveEorderAuthLog({
// order_id: orderProduct.id,
// product_id: orderProduct.product_id,
// platform_name: app.name,
// platform_id: app.id,
// spended_num: trade.trade_amt,
// user_name: params.idName, // 使用方
// actual_spend_name: app.merchant_name,// 实际使用方
// engine_trade_id: trade.id,
// pass: pass ? 1 : 0
// });
// console.log(logres);
}
// 4. 返回认证结果
return
system
.
getResultSuccess
(
res
.
data
,
res
.
msg
);
}
// 交易
async
trade
(
params
)
{
let
orderProduct
=
params
.
orderProduct
;
let
trade_amt
=
1
;
if
(
orderProduct
==
2
)
{
trade_amt
=
Number
(
orderProduct
.
price
);
}
let
tradeLog
=
await
this
.
tradelogDao
.
create
({
requestid
:
params
.
requestid
,
merchant_id
:
orderProduct
.
merchant_id
,
product_id
:
orderProduct
.
product_id
,
trade_amt
:
trade_amt
,
result
:
0
,
});
let
tradeRes
=
await
this
.
feeSve
.
trade
({
account_id
:
orderProduct
.
engine_account_id
,
trade_amt
:
trade_amt
,
trade_no
:
tradeLog
.
id
,
trade_desc
:
"二要素验证"
,
});
if
(
tradeRes
.
status
!==
0
)
{
tradeLog
.
result
=
2
;
tradeLog
.
fee
=
0
;
tradeLog
.
fee_remark
=
"扣费失败,"
+
tradeRes
.
msg
;
await
tradeLog
.
save
();
return
system
.
getResultFail
(
1002001
,
"扣费失败,"
+
tradeRes
.
msg
);
}
else
{
tradeLog
.
result
=
1
;
tradeLog
.
fee
=
1
;
tradeLog
.
fee_remark
=
"扣费成功"
;
await
tradeLog
.
save
();
}
return
system
.
getResultSuccess
({
tradeLog
:
tradeLog
,
trade
:
tradeRes
.
data
})
}
}
}
module
.
exports
=
AuthService
;
module
.
exports
=
AuthService
;
\ No newline at end of file
esign-api/app/base/system.js
View file @
e7ed0bd2
...
@@ -172,16 +172,14 @@ class System {
...
@@ -172,16 +172,14 @@ class System {
let
dev
=
"http://39.107.234.14"
;
let
dev
=
"http://39.107.234.14"
;
return
{
return
{
// 产品引擎
// 产品引擎
engine_product
:
local
+
":3571"
+
path
,
engine_product
:
dev
+
":3571"
+
path
,
// 计费引擎
// 计费引擎
engine_fee
:
local
+
":3572"
+
path
,
engine_fee
:
dev
+
":3572"
+
path
,
// 认证引擎
// 认证引擎
engine_auth
:
local
+
":3573"
+
path
,
engine_auth
:
dev
+
":3573"
+
path
,
// 签约引擎
engine_sign
:
dev
+
":3574"
+
path
,
// 用户服务
// 用户服务
sve_uc
:
local
+
":3651"
+
path
,
sve_uc
:
dev
+
":3651"
+
path
,
// 商户服务
// 商户服务
sve_merchant
:
dev
+
":3652"
+
path
,
sve_merchant
:
dev
+
":3652"
+
path
,
// 订单服务
// 订单服务
...
...
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