Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pay
Project
Project
Details
Activity
Releases
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bp
pay
Commits
7a757390
Commit
7a757390
authored
Sep 10, 2021
by
万继龙
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'pay_wanjl_0830' into 'master'
Pay wanjl 0830 See merge request bp/pay!74
parents
b734e336
b84d1743
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
145 additions
and
19 deletions
+145
-19
PayException.php
application/exception/custom/PayException.php
+2
-0
PayOrder.php
application/models/order/mysql/PayOrder.php
+2
-2
Order.php
application/modules/Pay/controllers/Order.php
+10
-0
PayService.php
application/services/pay/PayService.php
+89
-11
PingxxService.php
application/services/pingxx/PingxxService.php
+1
-0
WalletService.php
application/services/wallet/WalletService.php
+13
-0
application.ini
conf/application.ini
+12
-2
cli.ini
conf/cli.ini
+16
-4
No files found.
application/exception/custom/PayException.php
View file @
7a757390
...
@@ -29,6 +29,8 @@ class PayException extends BaseException
...
@@ -29,6 +29,8 @@ class PayException extends BaseException
14
=>
'订单缺少商品信息,请联系管理员'
,
14
=>
'订单缺少商品信息,请联系管理员'
,
15
=>
'订单存在过期商品,不能支付'
,
15
=>
'订单存在过期商品,不能支付'
,
16
=>
'订单过期,不允许支付'
,
16
=>
'订单过期,不允许支付'
,
17
=>
'订单缺少过期时间,请联系管理员'
,
18
=>
'订单不存在,请重试'
,
];
];
}
}
application/models/order/mysql/PayOrder.php
View file @
7a757390
...
@@ -18,14 +18,14 @@ class PayOrder extends MysqlBase
...
@@ -18,14 +18,14 @@ class PayOrder extends MysqlBase
self
::
beginTransaction
();
self
::
beginTransaction
();
try
{
try
{
$_date
=
date
(
'Y-m-d H:i:s'
);
$order
=
self
::
getMaster
(
'*'
,
[
'order_id'
=>
$order_id
]);
$order
=
self
::
getMaster
(
'*'
,
[
'order_id'
=>
$order_id
,
'expire_time[>]'
=>
$_date
]);
if
(
empty
(
$order
))
{
if
(
empty
(
$order
))
{
$cnt
=
self
::
insert
(
$pay_order
,
[
'rowCount'
=>
true
]);
$cnt
=
self
::
insert
(
$pay_order
,
[
'rowCount'
=>
true
]);
if
(
$cnt
)
{
if
(
$cnt
)
{
$order
=
$pay_order
;
$order
=
$pay_order
;
}
}
}
}
self
::
commit
();
self
::
commit
();
}
catch
(
\PDOException
$e
)
{
}
catch
(
\PDOException
$e
)
{
...
...
application/modules/Pay/controllers/Order.php
View file @
7a757390
...
@@ -61,6 +61,16 @@ class OrderController extends Base
...
@@ -61,6 +61,16 @@ class OrderController extends Base
$this
->
success
([
'result'
=>
$ret
]);
$this
->
success
([
'result'
=>
$ret
]);
}
}
public
function
chargesAction
()
{
$params
=
$this
->
getRequest
()
->
getPost
();
$order_id
=
$params
[
'order_id'
]
??
''
;
$paySrv
=
new
PayService
();
$ret
=
$paySrv
->
pay_charges
(
$order_id
);
$this
->
success
([
'result'
=>
$ret
]);
}
public
function
write_offAction
()
{
public
function
write_offAction
()
{
$params
=
$this
->
params
;
$params
=
$this
->
params
;
...
...
application/services/pay/PayService.php
View file @
7a757390
...
@@ -49,13 +49,14 @@ class PayService
...
@@ -49,13 +49,14 @@ class PayService
throw
new
PayException
([
'cus'
=>
3
]);
throw
new
PayException
([
'cus'
=>
3
]);
}
}
if
(
!
empty
(
$order_info
[
'pay_expiration_time'
]))
{
if
(
empty
(
$order_info
[
'pay_expiration_time'
]))
{
throw
new
PayException
([
'cus'
=>
17
]);
}
$pay_expiration_time
=
strtotime
(
$order_info
[
'pay_expiration_time'
]);
$pay_expiration_time
=
strtotime
(
$order_info
[
'pay_expiration_time'
]);
if
(
$pay_expiration_time
<
time
())
{
if
(
$pay_expiration_time
<
time
())
{
throw
new
PayException
([
'cus'
=>
16
]);
throw
new
PayException
([
'cus'
=>
16
]);
}
}
}
if
(
empty
(
$data
[
'result'
][
'order_item_list'
]))
{
if
(
empty
(
$data
[
'result'
][
'order_item_list'
]))
{
throw
new
PayException
([
'cus'
=>
14
]);
throw
new
PayException
([
'cus'
=>
14
]);
...
@@ -93,9 +94,11 @@ class PayService
...
@@ -93,9 +94,11 @@ class PayService
throw
new
PayException
([
'cus'
=>
15
]);
throw
new
PayException
([
'cus'
=>
15
]);
}
}
// 判断是否存在有效订单
//订单过期时间必须满足 70s+
$max_expire_time
=
config
(
'pay'
,
'pay.expire_time'
)
??
1800
;
if
(
$pay_expiration_time
-
$now
<
70
)
{
$expire_time
=
time
()
+
$max_expire_time
;
$pay_expiration_time
=
$now
+
70
;
}
$pay_order_id
=
$this
->
gen_pay_order_id
(
$user_id
);
$pay_order_id
=
$this
->
gen_pay_order_id
(
$user_id
);
$new_pay_order
=
[
$new_pay_order
=
[
'pay_order_id'
=>
$pay_order_id
,
'pay_order_id'
=>
$pay_order_id
,
...
@@ -107,7 +110,7 @@ class PayService
...
@@ -107,7 +110,7 @@ class PayService
'pay_amount'
=>
$order_info
[
'payment'
],
'pay_amount'
=>
$order_info
[
'payment'
],
'pay_channel'
=>
$pay_method_id
,
'pay_channel'
=>
$pay_method_id
,
'third_order_id'
=>
''
,
'third_order_id'
=>
''
,
'expire_time'
=>
date
(
'Y-m-d H:i:s'
,
$
expire
_time
),
'expire_time'
=>
date
(
'Y-m-d H:i:s'
,
$
pay_expiration
_time
),
'source_name'
=>
10
,
'source_name'
=>
10
,
'service_name'
=>
1
,
'service_name'
=>
1
,
'business_from'
=>
$order_info
[
'business_from'
],
'business_from'
=>
$order_info
[
'business_from'
],
...
@@ -120,6 +123,11 @@ class PayService
...
@@ -120,6 +123,11 @@ class PayService
throw
new
PayException
([
'cus'
=>
4
]);
throw
new
PayException
([
'cus'
=>
4
]);
}
}
//不支持修改订单过期时间,再次调用支付服务
if
(
strtotime
(
$pay_order
[
'expire_time'
])
<
time
())
{
throw
new
PayException
([
'cus'
=>
16
]);
}
if
(
$pay_order
[
'pay_order_status'
]
==
Dictionary
::
O_PAY_STATUS_PAYED
)
{
if
(
$pay_order
[
'pay_order_status'
]
==
Dictionary
::
O_PAY_STATUS_PAYED
)
{
throw
new
PayException
([
'cus'
=>
5
]);
throw
new
PayException
([
'cus'
=>
5
]);
}
}
...
@@ -168,13 +176,25 @@ class PayService
...
@@ -168,13 +176,25 @@ class PayService
$ret
[
'exist'
]
=
true
;
$ret
[
'exist'
]
=
true
;
}
}
$channel_exist
=
false
;
$channel
=
$this
->
getChannel
(
$pay_method_id
);
if
(
!
empty
(
$ret
[
'charges'
][
'data'
]))
{
//是否存在
foreach
(
$ret
[
'charges'
][
'data'
]
as
$ch
)
{
if
(
$ch
[
'channel'
]
==
$channel
)
{
$channel_exist
=
true
;
}
}
}
//判断是否做过pay操作 charge
//判断是否做过pay操作 charge
if
(
empty
(
$ret
[
'charge'
])
)
{
if
(
$channel_exist
==
false
)
{
// 创建支付单
// 创建支付单
$payment
=
[
$payment
=
[
'charge_order_no'
=>
$pay_order
[
'pay_order_id'
],
'charge_order_no'
=>
$pay_order
[
'pay_order_id'
],
'charge_amount'
=>
$pay_order
[
'pay_amount'
],
'charge_amount'
=>
$pay_order
[
'pay_amount'
],
'channel'
=>
$
this
->
getChannel
(
$pay_method_id
)
,
'channel'
=>
$
channel
,
'extra'
=>
$extra
,
'extra'
=>
$extra
,
];
];
...
@@ -292,6 +312,64 @@ class PayService
...
@@ -292,6 +312,64 @@ class PayService
return
[
'pay_order_id'
=>
$pay_order_id
];
return
[
'pay_order_id'
=>
$pay_order_id
];
}
}
/**
* @param $order_id
* @return array
* @throws BaseException
* @throws PayException
* 返回订单状态及订单渠道列表
*/
public
function
pay_charges
(
$order_id
)
{
$pay_order
=
PayOrder
::
get
(
'*'
,
[
'order_id'
=>
$order_id
]);
if
(
empty
(
$pay_order
))
{
throw
new
PayException
([
'cus'
=>
18
]);
}
$data
=
[
'status'
=>
'created'
,
'max_expire_time'
=>
$pay_order
[
'expire_time'
],
'list'
=>
[]
];
$max_expire_time
=
strtotime
(
$pay_order
[
'expire_time'
]);
if
(
$max_expire_time
<
time
())
{
$data
[
"status"
]
=
'canceled'
;
}
if
(
empty
(
$pay_order
[
'third_order_id'
]))
{
return
$data
;
}
//paid、refunded、canceled、created
$ret
=
PingxxService
::
getInstance
()
->
getOrder
(
$pay_order
[
'third_order_id'
]);
if
(
!
empty
(
$ret
[
'error'
]))
{
throw
new
BaseException
([
'msg'
=>
$ret
[
'error'
][
'message'
],
'code'
=>
'2301'
]);
}
$data
[
"status"
]
=
$ret
[
"status"
];
if
(
!
empty
(
$ret
[
'charges'
][
'data'
]))
{
//是否存在
foreach
(
$ret
[
'charges'
][
'data'
]
as
$ch
)
{
$data
[
"list"
][]
=
[
'paid'
=>
$ch
[
'paid'
],
'refunded'
=>
$ch
[
'refunded'
],
'channel'
=>
$ch
[
'channel'
],
'time_expire'
=>
$ch
[
'time_expire'
],
];
if
(
$max_expire_time
<
$ch
[
'time_expire'
])
{
$max_expire_time
=
$ch
[
'time_expire'
];
}
}
}
$data
[
'max_expire_time'
]
=
date
(
'Y-m-d H:i:s'
,
$max_expire_time
);
return
$data
;
}
/**
/**
* @param $order_item_id
* @param $order_item_id
* @param $life_account_id
* @param $life_account_id
...
...
application/services/pingxx/PingxxService.php
View file @
7a757390
...
@@ -144,6 +144,7 @@ class PingxxService
...
@@ -144,6 +144,7 @@ class PingxxService
"body"
=>
"购买商品"
,
"body"
=>
"购买商品"
,
"uid"
=>
$order
[
'user_id'
],
"uid"
=>
$order
[
'user_id'
],
"client_ip"
=>
IP
::
ip
(),
"client_ip"
=>
IP
::
ip
(),
"time_expire"
=>
strtotime
(
$order
[
'expire_time'
]),
//订单过期时间 expire_time
'receipt_app'
=>
Pingpp
::
getAppId
(),
// 收款方应用
'receipt_app'
=>
Pingpp
::
getAppId
(),
// 收款方应用
'service_app'
=>
Pingpp
::
getAppId
(),
// 服务方应用
'service_app'
=>
Pingpp
::
getAppId
(),
// 服务方应用
'metadata'
=>
$metadata
,
// 商户定制信息
'metadata'
=>
$metadata
,
// 商户定制信息
...
...
application/services/wallet/WalletService.php
View file @
7a757390
...
@@ -23,6 +23,19 @@ class WalletService
...
@@ -23,6 +23,19 @@ class WalletService
throw
new
CodeSpecialException
(
"failed"
);
throw
new
CodeSpecialException
(
"failed"
);
}
}
// 服务增加签名
$appid
=
\Yaf\Application
::
app
()
->
getConfig
()
->
get
(
'wallet.appid'
);
$secret
=
\Yaf\Application
::
app
()
->
getConfig
()
->
get
(
'wallet.secret'
);
$params
[
'time'
]
=
date
(
'Y-m-d H:i:s'
);
$params
[
'transfer_service_id'
]
=
$appid
;
$params
[
'sign'
]
=
self
::
sign
(
$params
,
$secret
);
return
Sdk
::
call
(
$url
,
$params
);
return
Sdk
::
call
(
$url
,
$params
);
}
}
private
function
sign
(
$params
,
$secret
)
{
$sign
=
md5
(
$params
[
'time'
]
.
$secret
);
return
$sign
;
}
}
}
\ No newline at end of file
conf/application.ini
View file @
7a757390
...
@@ -41,12 +41,22 @@ dingTalk.keys[]="SEC0298ad3f80e16df12cd4d6f6c39e961b500e2ff486f4c4377c0e2af8f453
...
@@ -41,12 +41,22 @@ dingTalk.keys[]="SEC0298ad3f80e16df12cd4d6f6c39e961b500e2ff486f4c4377c0e2af8f453
pingxx.appid
=
"app_9m1ubDG4e1mPXLCG"
pingxx.appid
=
"app_9m1ubDG4e1mPXLCG"
wxApp.jw.order
=
"https://wx.appgc.cn/%23/bpmp/ticket/my"
wxApp.jw.order
=
"https://wx.appgc.cn/%23/bpmp/ticket/my"
[perf : common : exception : dingTalk]
wallet.appid
=
"21091014413030105002"
wallet.secret
=
"b62eff98ba17160df0161ede4eef2346"
[pref : prod : common : exception : dingTalk]
pingxx.appid
=
"app_XfjznTPSa5aLfvfH"
pingxx.appid
=
"app_XfjznTPSa5aLfvfH"
[test : common : exception : dingTalk]
[test : common : exception : dingTalk]
pingxx.appid
=
"app_W10Oe5XrvbzHfP4W"
pingxx.appid
=
"app_W10Oe5XrvbzHfP4W"
wxApp.jw.order
=
"https://testwx.appgc.cn/%23/bpmp/ticket/my"
wxApp.jw.order
=
"https://testwx.appgc.cn/%23/bpmp/ticket/my"
[dev : common : exception]
wallet.appid
=
"21090716133838205004"
wallet.secret
=
"f97c50e880d377a0e0f79aee1f639777"
[dev : common : exception : dingTalk]
pingxx.appid
=
"app_W10Oe5XrvbzHfP4W"
pingxx.appid
=
"app_W10Oe5XrvbzHfP4W"
wxApp.jw.order
=
"https://testwx.appgc.cn/%23/bpmp/ticket/my"
wallet.appid
=
"21090716133838205004"
wallet.secret
=
"f97c50e880d377a0e0f79aee1f639777"
\ No newline at end of file
conf/cli.ini
View file @
7a757390
...
@@ -15,14 +15,26 @@ dingTalk.tokens[]="5d754d76cac8c64aad495bc44f481677745ff831aee0517b6e5b3565be6ba
...
@@ -15,14 +15,26 @@ dingTalk.tokens[]="5d754d76cac8c64aad495bc44f481677745ff831aee0517b6e5b3565be6ba
dingTalk.keys
[]
="SEC0298ad3f80e16df12cd4d6f6c39e961b500e2ff486f4c4377c0e2af8f4539a74"
dingTalk.keys
[]
="SEC0298ad3f80e16df12cd4d6f6c39e961b500e2ff486f4c4377c0e2af8f4539a74"
[prod : common : dingTalk]
[prod : common :
exception :
dingTalk]
pingxx.appid
=
"app_9m1ubDG4e1mPXLCG"
pingxx.appid
=
"app_9m1ubDG4e1mPXLCG"
wxApp.jw.order
=
"https://wx.appgc.cn/%23/bpmp/ticket/my"
[perf : common : dingTalk]
wallet.appid
=
"21091014413030105002"
wallet.secret
=
"b62eff98ba17160df0161ede4eef2346"
[pref : prod : common : exception : dingTalk]
pingxx.appid
=
"app_XfjznTPSa5aLfvfH"
pingxx.appid
=
"app_XfjznTPSa5aLfvfH"
[test
: comm
on : dingTalk]
[test
: common : excepti
on : dingTalk]
pingxx.appid
=
"app_W10Oe5XrvbzHfP4W"
pingxx.appid
=
"app_W10Oe5XrvbzHfP4W"
wxApp.jw.order
=
"https://testwx.appgc.cn/%23/bpmp/ticket/my"
wallet.appid
=
"21090716133838205004"
wallet.secret
=
"f97c50e880d377a0e0f79aee1f639777"
[dev : common ]
[dev : common
: exception : dingTalk
]
pingxx.appid
=
"app_W10Oe5XrvbzHfP4W"
pingxx.appid
=
"app_W10Oe5XrvbzHfP4W"
wxApp.jw.order
=
"https://testwx.appgc.cn/%23/bpmp/ticket/my"
wallet.appid
=
"21090716133838205004"
wallet.secret
=
"f97c50e880d377a0e0f79aee1f639777"
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