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
32fd971a
Commit
32fd971a
authored
Jul 12, 2021
by
wanjilong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add: 调整pingxx创建逻辑
parent
1559231e
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
88 additions
and
76 deletions
+88
-76
RefundException.php
application/exception/custom/RefundException.php
+1
-1
Sdk.php
application/library/Helpers/Sdk.php
+0
-1
Callback.php
application/modules/Pay/controllers/Callback.php
+16
-2
Order.php
application/modules/Pay/controllers/Order.php
+24
-47
PayService.php
application/services/pay/PayService.php
+38
-18
PingxxService.php
application/services/pingxx/PingxxService.php
+0
-5
RefundService.php
application/services/refund/RefundService.php
+9
-2
No files found.
application/exception/custom/RefundException.php
View file @
32fd971a
...
...
@@ -12,7 +12,7 @@ class RefundException extends BaseException
protected
$cus
=
[
0
=>
'系统异常请联系管理员'
,
1
=>
'订单信息不存在,请核对'
,
1
=>
'
获取
订单信息不存在,请核对'
,
2
=>
'退款已经成功操作,请核对'
,
3
=>
'退款进行中,请稍等'
,
4
=>
'目前仅支持支付后的订单退款,请核对'
,
...
...
application/library/Helpers/Sdk.php
View file @
32fd971a
...
...
@@ -28,7 +28,6 @@ class Sdk {
*/
$data
=
(
new
Request
())
->
post
(
$url
,
$params
,
2000
,
'json'
);
FileLog
::
info
(
'sdk_call:'
.
'services return'
,
json_encode
([
'url'
=>
$url
,
$headers
,
'req'
=>
$params
,
'res'
=>
$data
],
JSON_UNESCAPED_UNICODE
));
/*
[
"http_code"=> 200,
...
...
application/modules/Pay/controllers/Callback.php
View file @
32fd971a
...
...
@@ -25,9 +25,16 @@ class CallbackController extends Base
/**/
if
(
!
empty
(
$data
[
'data'
][
'object'
]))
{
if
(
$data
[
'type'
]
==
'charge.succeeded'
)
{
$merchant_order_no
=
$data
[
'data'
][
'object'
][
'order_no'
];
}
else
{
$merchant_order_no
=
$data
[
'data'
][
'object'
][
'merchant_order_no'
];
}
CallbackLog
::
insert
([
'type'
=>
$data
[
'type'
]
??
''
,
'merchant_order_no'
=>
$
data
[
'data'
][
'object'
][
'merchant_order_no'
]
??
''
,
'merchant_order_no'
=>
$
merchant_order_no
??
''
,
'object_id'
=>
$data
[
'data'
][
'object'
][
'id'
]
??
''
,
'data'
=>
base64_encode
(
gzcompress
(
$raw_data
)),
//压缩存储
]);
...
...
@@ -49,10 +56,17 @@ class CallbackController extends Base
$raw_data
=
file_get_contents
(
'php://input'
);
$data
=
json_decode
(
$raw_data
,
true
);
if
(
!
empty
(
$data
[
'data'
][
'object'
]))
{
if
(
$data
[
'type'
]
==
'refund.succeeded'
)
{
$merchant_order_no
=
$data
[
'data'
][
'object'
][
'order_no'
];
}
else
{
$merchant_order_no
=
$data
[
'data'
][
'object'
][
'merchant_order_no'
];
}
CallbackLog
::
insert
([
'type'
=>
$data
[
'type'
]
??
''
,
'merchant_order_no'
=>
$
data
[
'data'
][
'object'
][
'merchant_order_no'
]
??
''
,
'merchant_order_no'
=>
$
merchant_order_no
??
''
,
'object_id'
=>
$data
[
'data'
][
'object'
][
'id'
]
??
''
,
'data'
=>
base64_encode
(
gzcompress
(
$raw_data
)),
//压缩存储
]);
...
...
application/modules/Pay/controllers/Order.php
View file @
32fd971a
...
...
@@ -16,65 +16,42 @@ class OrderController extends Base
*/
public
function
payAction
()
{
try
{
$params
=
$this
->
params
;
$user_id
=
$params
[
'user_id'
];
$order_id
=
$params
[
'order_id'
];
$pay_method_id
=
$params
[
'pay_method_id'
]
??
106
;
$paySrv
=
new
PayService
();
$ret
=
$paySrv
->
do_pay
(
$order_id
,
$user_id
,
$pay_method_id
);
//兼容C端客户端支付,调整返回结构,ping++ 返回 order,原生:微信、支付宝返回charge
$result
=
[];
$result
[]
=
[
'k'
=>
'order'
,
'v'
=>
$ret
];
$this
->
success
([
'result'
=>
$result
]);
}
catch
(
PayException
$e
)
{
$this
->
failed
(
$e
->
getMessage
(),
$e
->
getCode
());
}
catch
(
\Exception
$e
)
{
FileLog
::
error
(
'pay-service:ping++支付报错'
,
json_encode
(
$params
,
JSON_UNESCAPED_UNICODE
),
$e
);
$this
->
failed
(
$e
->
getMessage
(),
$e
->
getCode
());
}
$params
=
$this
->
params
;
$user_id
=
$params
[
'user_id'
];
$order_id
=
$params
[
'order_id'
];
$pay_method_id
=
$params
[
'pay_method_id'
]
??
106
;
$paySrv
=
new
PayService
();
$ret
=
$paySrv
->
do_pay
(
$order_id
,
$user_id
,
$pay_method_id
);
//兼容C端客户端支付,调整返回结构,ping++ 返回 order,原生:微信、支付宝返回charge
$result
=
[];
$result
[]
=
[
'k'
=>
'order'
,
'v'
=>
$ret
];
$this
->
success
([
'result'
=>
$result
]);
}
public
function
refundAction
()
{
try
{
$params
=
$this
->
params
;
$user_id
=
$params
[
'user_id'
];
$order_item_id
=
$params
[
'order_item_id'
];
$params
=
$this
->
params
;
$user_id
=
$params
[
'user_id'
];
$order_item_id
=
$params
[
'order_item_id'
];
$refundSrv
=
new
RefundService
();
$ret
=
$refundSrv
->
do_refund
(
$order_item_id
,
$user_id
);
$refundSrv
=
new
RefundService
();
$ret
=
$refundSrv
->
do_refund
(
$order_item_id
,
$user_id
);
$this
->
success
([
'result'
=>
$ret
]);
$this
->
success
([
'result'
=>
$ret
]);
}
catch
(
RefundException
$e
)
{
$this
->
failed
(
$e
->
getMessage
(),
$e
->
getCode
());
}
catch
(
\Exception
$e
)
{
FileLog
::
error
(
'pay-service:ping++退款报错'
,
json_encode
(
$params
,
JSON_UNESCAPED_UNICODE
),
$e
);
$this
->
failed
(
$e
->
getMessage
(),
$e
->
getCode
());
}
}
public
function
write_offAction
()
{
try
{
$params
=
$this
->
params
;
$life_account_id
=
$params
[
'life_account_id'
];
$order_item_id
=
$params
[
'order_item_id'
];
$refundSrv
=
new
PayService
();
$ret
=
$refundSrv
->
write_off
(
$order_item_id
,
$life_account_id
);
$params
=
$this
->
params
;
$life_account_id
=
$params
[
'life_account_id'
];
$order_item_id
=
$params
[
'order_item_id'
];
$this
->
success
([
'result'
=>
$ret
]);
$refundSrv
=
new
PayService
();
$ret
=
$refundSrv
->
write_off
(
$order_item_id
,
$life_account_id
);
}
catch
(
RefundException
$e
)
{
$this
->
failed
(
$e
->
getMessage
(),
$e
->
getCode
());
}
catch
(
\Exception
$e
)
{
FileLog
::
error
(
'pay-service:核销报错'
,
json_encode
(
$params
,
JSON_UNESCAPED_UNICODE
),
$e
);
$this
->
failed
(
$e
->
getMessage
(),
$e
->
getCode
());
}
$this
->
success
([
'result'
=>
$ret
]);
}
}
application/services/pay/PayService.php
View file @
32fd971a
...
...
@@ -17,6 +17,7 @@ use App\Services\pingxx\PingxxService;
use
App\Services\wallet\WalletService
;
use
Helpers\Strategy
;
use
Helpers\Sdk
;
use
Yaf\Application
;
use
App\Exception\custom\PayException
;
...
...
@@ -45,6 +46,8 @@ class PayService
}
$metadata
=
[
'app_id'
=>
'merchant-c'
,
'environ'
=>
Application
::
app
()
->
environ
(),
'order_id'
=>
$order_id
,
'goods_sku_id'
=>
[],
'order_item_id'
=>
[],
...
...
@@ -77,17 +80,22 @@ class PayService
//获取或创建支付订单
$pay_order
=
PayOrder
::
get_valid_order
(
$order_id
,
$new_pay_order
);
if
(
empty
(
$pay_order
))
{
throw
new
PayException
([
'cus'
=>
0
]);
throw
new
PayException
([
'cus'
=>
1
0
]);
}
if
(
$pay_order
[
'pay_order_status'
]
==
Dictionary
::
O_PAY_STATUS_PAYED
)
{
throw
new
PayException
([
'cus'
=>
3
]);
}
// 支持幂等,存在有效订单需要可以重复支付
$ret
=
PingxxService
::
getInstance
()
->
createOrder
(
$pay_order
,
$metadata
);
// 已经创建,需要查询返回
if
(
!
empty
(
$pay_order
[
'third_order_id'
]))
{
$ret
=
PingxxService
::
getInstance
()
->
getOrder
(
$pay_order
[
'third_order_id'
]);
}
else
{
$ret
=
PingxxService
::
getInstance
()
->
createOrder
(
$pay_order
,
$metadata
);
}
if
(
!
empty
(
$ret
[
'error'
]))
{
throw
new
\Exception
(
$ret
[
'error'
][
'message'
],
'2
0
01'
);
throw
new
\Exception
(
$ret
[
'error'
][
'message'
],
'2
3
01'
);
}
if
(
$ret
[
"status"
]
==
'paid'
||
$ret
[
'status'
]
==
'refunded'
)
{
...
...
@@ -121,19 +129,27 @@ class PayService
$ret
[
'exist'
]
=
true
;
}
// 创建支付单
$payment
=
[
'charge_order_no'
=>
$pay_order
[
'pay_order_id'
],
'charge_amount'
=>
$pay_order
[
'pay_amount'
],
'channel'
=>
$this
->
getChannel
(
$pay_method_id
),
];
//判断是否做过pay操作 charge
if
(
empty
(
$ret
[
'charge'
]))
{
// 创建支付单
$payment
=
[
'charge_order_no'
=>
$pay_order
[
'pay_order_id'
],
'charge_amount'
=>
$pay_order
[
'pay_amount'
],
'channel'
=>
$this
->
getChannel
(
$pay_method_id
),
];
$pay
=
PingxxService
::
getInstance
()
->
pay
(
$ret
[
'id'
],
$payment
);
if
(
!
empty
(
$pay
[
'error'
]))
{
throw
new
\Exception
(
$pay
[
'error'
][
'message'
],
'2001'
);
$pay
=
PingxxService
::
getInstance
()
->
pay
(
$ret
[
'id'
],
$payment
);
if
(
!
empty
(
$pay
[
'error'
]))
{
throw
new
\Exception
(
$pay
[
'error'
][
'message'
],
'2002'
);
}
return
$pay
;
}
else
{
return
$ret
;
}
return
$pay
;
}
/**
...
...
@@ -151,6 +167,10 @@ class PayService
}
$object
=
$data
[
'data'
][
'object'
];
if
(
empty
(
$object
[
'metadata'
][
'app_id'
])
||
$object
[
'metadata'
][
'app_id'
]
!=
"merchant-c"
)
{
//非支付中心发出的订单,需要忽略
return
[
'id'
=>
$object
[
'id'
]];
}
if
(
$data
[
'type'
]
==
'charge.succeeded'
)
{
$pay_order_id
=
$object
[
'order_no'
];
...
...
@@ -641,18 +661,18 @@ class PayService
private
function
getChannel
(
$pay_method_id
)
{
$maps
=
[
106
=>
"wx"
,
//微信 App 支付
105
=>
"wx"
,
//微信 App 支付
106
=>
"alipay"
,
//支付宝
107
=>
"wx_pub"
,
//微信 JSAPI 支付
108
=>
"wx_pub_qr"
,
//微信 Native 支付
109
=>
"wx_wap"
,
//微信 H5 支付
110
=>
"wx_lite"
,
//微信小程序支付
120
=>
"alipay"
,
//支付宝
];
if
(
$maps
[
$pay_method_id
]
)
{
if
(
!
empty
(
$maps
[
$pay_method_id
])
)
{
return
$maps
[
$pay_method_id
];
}
else
{
return
$maps
[
10
6
];
return
$maps
[
10
5
];
}
}
}
\ No newline at end of file
application/services/pingxx/PingxxService.php
View file @
32fd971a
...
...
@@ -158,11 +158,6 @@ class PingxxService
}
public
function
pay
(
$orderId
,
$pay
)
{
$params
=
[
'charge_order_no'
=>
substr
(
md5
(
time
()),
0
,
10
),
'charge_amount'
=>
100
,
'channel'
=>
'alipay_qr'
,
];
try
{
FileLog
::
info
(
'ping++:'
.
'订单pay发起'
,
json_encode
(
$pay
,
JSON_UNESCAPED_UNICODE
));
...
...
application/services/refund/RefundService.php
View file @
32fd971a
...
...
@@ -17,6 +17,7 @@ use Helpers\Strategy;
use
Helpers\Logger
;
use
App\Exception\custom\RefundException
;
use
Yaf\Application
;
class
RefundService
{
...
...
@@ -57,6 +58,8 @@ class RefundService
'charge'
=>
$data
[
'pay_order'
][
'third_order_id'
],
'charge_amount'
=>
$data
[
'refund_order'
][
'refund_amount'
],
'metadata'
=>
[
'app_id'
=>
'merchant-c'
,
'environ'
=>
Application
::
app
()
->
environ
(),
'refund_order_id'
=>
$data
[
'refund_order'
][
'refund_order_id'
],
'order_item_id'
=>
$data
[
'refund_order'
][
'order_item_id'
],
'goods_sku_id'
=>
$order_item
[
'goods_sku_id'
]
??
''
,
...
...
@@ -69,7 +72,7 @@ class RefundService
$edit
=
[
'request_pingxx_success_time'
=>
date
(
'Y-m-d H:i:s'
)];
RefundOrder
::
update
(
$edit
,
[
'refund_order_id'
=>
$data
[
'refund_order'
][
'refund_order_id'
]]);
}
else
{
throw
new
\Exception
(
$ret
[
'error'
][
'message'
],
'20
0
1'
);
throw
new
\Exception
(
$ret
[
'error'
][
'message'
],
'20
1
1'
);
}
return
[
'order_item_id'
=>
$order_item_id
];
...
...
@@ -98,8 +101,12 @@ class RefundService
}
$object
=
$data
[
'data'
][
'object'
];
if
(
empty
(
$object
[
'metadata'
][
'app_id'
])
||
$object
[
'metadata'
][
'app_id'
]
!=
"merchant-c"
)
{
//非支付中心发出的订单,需要忽略
return
[
'id'
=>
$object
[
'id'
]];
}
if
(
$data
[
'type'
]
==
'
charge
.succeeded'
)
{
if
(
$data
[
'type'
]
==
'
refund
.succeeded'
)
{
$refund_order_id
=
$object
[
'order_no'
];
$refunded
=
$object
[
'succeed'
];
//"succeed": true,
}
else
{
...
...
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