PayReturnService.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace app\common\service;
  3. use addons\epay\library\Service;
  4. use app\common\model\Payment;
  5. use com\unionpay\acp\sdk\AcpService;
  6. use com\unionpay\acp\sdk\UnionQuery;
  7. use fast\Arr;
  8. use think\App;
  9. class PayReturnService{
  10. /** @var Payment */
  11. protected $payment;
  12. /**
  13. * @param Payment $payment
  14. */
  15. public function setPayment(Payment $payment): void
  16. {
  17. $this->payment = $payment;
  18. }
  19. public function companyBank(){
  20. require __DIR__.'/../library/upacp_demo_b2b/demo/api_02_b2b/Form_6_4_Query.php';
  21. $postData=input();
  22. $queryPay=uniCompanyQuery($postData['orderId'],$this->payment->create_time);
  23. $res=[
  24. $queryPay,
  25. 'success'
  26. ];
  27. if($res[0]){
  28. $this->setPayNo($postData['queryId']);
  29. }
  30. return $res;
  31. }
  32. public function wechat(){
  33. $payed=Service::checkNotify('wechat');
  34. $data=$payed?$payed->verify():[];
  35. $this->setPayNo($data['transaction_id']??null);
  36. return [
  37. $payed!==false,
  38. 'success'
  39. ];
  40. }
  41. protected function setPayNo($no){
  42. $this->payment->pay_no=$no;
  43. $this->payment->save();
  44. }
  45. public function returnUrl(){
  46. return request()->root(true);
  47. }
  48. public function alipay(){
  49. $payed=Service::checkNotify('alipay');
  50. $data=$payed?$payed->verify():[];
  51. $this->setPayNo($data['trade_no']??null);
  52. return [
  53. $payed!==false,
  54. 'success'
  55. ];
  56. }
  57. public function bankUnion(){
  58. require __DIR__.'/../library/upacp_demo_b2c/sdk/acp_service.php';
  59. $postData=input();
  60. $isPay=AcpService::validate($_POST);
  61. $queryPay=UnionQuery::query($postData['orderId'],$this->payment->create_time);
  62. $res=[
  63. $isPay && $queryPay,
  64. 'success'
  65. ];
  66. if($res[0]){
  67. $this->setPayNo($postData['queryId']);
  68. }
  69. return $res;
  70. }
  71. public function otherUser(){}
  72. public function offline(){}
  73. public function process(){
  74. $method=Arr::get(OrderPayService::$methods,$this->payment->pay_type);
  75. return App::invokeMethod([$this,$method]);
  76. }
  77. }