PayReturnService.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. }
  21. public function wechat(){
  22. $payed=Service::checkNotify('wechat');
  23. $data=$payed?$payed->verify():[];
  24. $this->setPayNo($data['transaction_id']??null);
  25. return [
  26. $payed!==false,
  27. 'success'
  28. ];
  29. }
  30. protected function setPayNo($no){
  31. $this->payment->pay_no=$no;
  32. $this->payment->save();
  33. }
  34. public function returnUrl(){
  35. return request()->root(true);
  36. }
  37. public function alipay(){
  38. $payed=Service::checkNotify('alipay');
  39. $data=$payed?$payed->verify():[];
  40. $this->setPayNo($data['trade_no']??null);
  41. return [
  42. $payed!==false,
  43. 'success'
  44. ];
  45. }
  46. public function bankUnion(){
  47. require __DIR__.'/../library/upacp_demo_b2c/sdk/acp_service.php';
  48. $postData=input();
  49. $isPay=AcpService::validate($_POST);
  50. $queryPay=UnionQuery::query($postData['orderId'],$this->payment->create_time);
  51. $res=[
  52. $isPay && $queryPay,
  53. 'success'
  54. ];
  55. if($res[0]){
  56. $this->setPayNo($postData['queryId']);
  57. }
  58. return $res;
  59. }
  60. public function otherUser(){}
  61. public function offline(){}
  62. public function process(){
  63. $method=Arr::get(OrderPayService::$methods,$this->payment->pay_type);
  64. return App::invokeMethod([$this,$method]);
  65. }
  66. }