Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
ydl-packages
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
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
许振钊
ydl-packages
Commits
02061305
Commit
02061305
authored
Aug 22, 2022
by
xuzhenzhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(custom): add appid,openid validate
-
parent
d32de7b1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
6 deletions
+28
-6
units.test.ts
packages/toolkit/__tests__/payment/units.test.ts
+7
-0
Defined.ts
packages/toolkit/src/Payment/Defined.ts
+4
-2
Payment.ts
packages/toolkit/src/Payment/Payment.ts
+16
-4
publish-next.sh
scripts/publish-next.sh
+1
-0
No files found.
packages/toolkit/__tests__/payment/units.test.ts
View file @
02061305
...
...
@@ -13,6 +13,13 @@ describe('测试: 创建实例', () => {
const
payment
=
new
Payment
()
expect
(
payment
.
limitPayChannels
).
toEqual
(
Object
.
keys
(
PayChannel
).
map
(
key
=>
key
))
})
test
(
'empty array'
,
()
=>
{
const
payment
=
new
Payment
({
payChannels
:
[]
})
expect
(
payment
.
limitPayChannels
).
toEqual
([])
})
})
test
(
'测试订单查询链接'
,
()
=>
{
...
...
packages/toolkit/src/Payment/Defined.ts
View file @
02061305
...
...
@@ -113,13 +113,15 @@ export enum PayErrorMessage {
BALANCE_EMPTY
=
'余额不足'
,
WECHAT_REDIRECT_URL_MISSING
=
`请填写微信回调地址页面 'redirectUrl`
,
WECHAT_REDIRECT_URL_ENCODE
=
'redirectUrl需要encode'
,
WECHAT_PAY_CHANNEL_MISSING
=
`缺少持的渠道参数:'WX_MWEB','WX_JSAPI'`
,
WECHAT_PAY_CHANNEL_MISSING
=
`缺少渠道参数:'WX_MWEB','WX_JSAPI'`
,
WECHAT_APPID_MISSING
=
'缺少微信APPID入参'
,
ALIPAY_QUIT_URL_MISSING
=
`缺少支付失败回调地址:'quitUrl'`
,
ALIPAY_RETURN_URL_MISSING
=
`缺少支付成功回调地址:'returnUrl'`
,
ALIPAY_PAY_CHANNEL_MISSING
=
`缺少持的渠道参数:'ALI_WAP'`
,
WECHAT_JSSDK_PAY_ERROR
=
'微信JSSDK支付失败'
,
WECHAT_H5_PAY_BREAK
=
'微信h5支付中断'
,
ALIPAY_H5_PAY_BREAK
=
'支付宝支付中断'
ALIPAY_H5_PAY_BREAK
=
'支付宝支付中断'
,
ALIPAY_APPID_MISSING
=
'缺少微信APPID入参'
,
}
export
type
ToPayReturns
=
{
...
...
packages/toolkit/src/Payment/Payment.ts
View file @
02061305
import
{
UNIT_PAY
,
IS_PAY
,
MY_BALANCE
}
from
"./API"
;
import
{
IS_PAY
,
MY_BALANCE
,
UNIT_PAY
}
from
"./API"
;
import
md5
from
'blueimp-md5'
import
qs
from
'qs'
import
{
Utils
}
from
"@/Utils/Utils"
;
...
...
@@ -145,7 +145,7 @@ export class Payment {
return
{
payAmount
,
payBalance
}
}
async
toPay
(
params
:
ToPayParams
):
Promise
<
ToPayReturns
>
{
public
async
toPay
(
params
:
ToPayParams
):
Promise
<
ToPayReturns
>
{
const
{
totalAmount
,
payType
,
returnUrl
,
orderId
,
redirectUrl
,
openId
,
appId
,}
=
params
let
quitUrl
=
params
.
quitUrl
// validate start >>>
...
...
@@ -170,6 +170,12 @@ export class Payment {
success
:
false
,
errorType
:
PayError
.
VALIDATE
}
}
else
if
(
!
appId
)
{
return
{
success
:
false
,
errorMessage
:
PayErrorMessage
.
WECHAT_APPID_MISSING
,
errorType
:
PayError
.
VALIDATE
}
}
}
else
{
return
{
...
...
@@ -198,6 +204,12 @@ export class Payment {
success
:
false
,
errorType
:
PayError
.
VALIDATE
}
}
else
if
(
!
appId
)
{
return
{
success
:
false
,
errorMessage
:
PayErrorMessage
.
ALIPAY_APPID_MISSING
,
errorType
:
PayError
.
VALIDATE
}
}
}
else
{
return
{
...
...
@@ -255,7 +267,7 @@ export class Payment {
return
{
success
:
false
,
errorType
:
PayError
.
UNKNOWN
}
}
getPayChannel
(
payType
:
PayType
):
PayChannel
|
null
{
private
getPayChannel
(
payType
:
PayType
):
PayChannel
|
null
{
switch
(
payType
)
{
case
PayType
.
WECHAT_BALANCE
:
case
PayType
.
WECHAT
:
...
...
@@ -271,7 +283,7 @@ export class Payment {
return
null
}
wechatPayJSSDK
(
wechatPayParams
:
WechatPayParams
):
Promise
<
boolean
>
{
private
wechatPayJSSDK
(
wechatPayParams
:
WechatPayParams
):
Promise
<
boolean
>
{
const
{
appId
,
timeStamp
,
nonceStr
,
signType
,
paySign
,
package
:
packageAlias
}
=
wechatPayParams
return
new
Promise
((
resolve
)
=>
{
window
.
WeixinJSBridge
.
invoke
(
...
...
scripts/publish-next.sh
View file @
02061305
...
...
@@ -4,6 +4,7 @@ npx changeset pre enter next
npx changeset
npx changeset version
--prelease
npx run lib
npx changeset publish
npx changeset pre
exit
...
...
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