AliPay.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace Aix\Pay\Contracts;
  3. use Aix\Pay\Data\PayOrder;
  4. use Yansongda\Pay\Pay;
  5. class AliPay implements PayInterface
  6. {
  7. protected $alipay;
  8. protected $config = [
  9. 'app_id' => '',
  10. 'notify_url' => '',
  11. 'return_url' => '',
  12. 'ali_public_key' => '',
  13. 'private_key' => '',
  14. 'log' => [ // optional
  15. 'file' => './logs/alipay/alipay.log',
  16. 'level' => 'debug', // 建议生产环境等级调整为 info,开发环境为 debug
  17. 'type' => 'daily', // optional, 可选 daily.
  18. 'max_file' => 30, // optional, 当 type 为 daily 时有效,默认 30 天
  19. ],
  20. ];
  21. /**
  22. * AliPay constructor.
  23. */
  24. public function __construct()
  25. {
  26. $this->config['app_id']=config('aix.system.pay.alipay.app_id');
  27. $this->config['notify_url']=route('payhook.ali');
  28. $this->config['ali_public_key']=config('aix.system.pay.alipay.ali_public_key');
  29. $this->config['private_key']=config('aix.system.pay.alipay.private_key');
  30. $this->config['log']['file']=storage_path('logs/alipay.log');
  31. $this->alipay=Pay::alipay($this->config);
  32. }
  33. /**
  34. * 扫码支付
  35. * @param PayOrder $payOrder
  36. * @return mixed
  37. */
  38. public function scan(PayOrder $payOrder)
  39. {
  40. $order = [
  41. 'out_trade_no' => $payOrder->trade_no.time(),
  42. 'total_amount' => $payOrder->price,
  43. 'subject' => $payOrder->subject,
  44. 'body' => $payOrder->detail,
  45. ];
  46. return $this->alipay->scan($order);
  47. }
  48. public function web(PayOrder $payOrder)
  49. {
  50. $order = [
  51. 'out_trade_no' => $payOrder->trade_no.time(),
  52. 'total_amount' => $payOrder->price,
  53. 'subject' => $payOrder->subject,
  54. 'body' => $payOrder->detail,
  55. 'return_url' => $payOrder->return_url,
  56. ];
  57. return $this->alipay->web($order);
  58. }
  59. /**
  60. * 回调验签
  61. * @return mixed
  62. * @throws \Yansongda\Pay\Exceptions\InvalidArgumentException
  63. * @throws \Yansongda\Pay\Exceptions\InvalidConfigException
  64. * @throws \Yansongda\Pay\Exceptions\InvalidSignException
  65. */
  66. public function verify()
  67. {
  68. return $this->alipay->verify();
  69. }
  70. /**
  71. * 回调回复
  72. * @return mixed
  73. */
  74. public function success()
  75. {
  76. return $this->alipay->success();
  77. }
  78. /**
  79. * 手机网页支付
  80. * @param PayOrder $payOrder
  81. * @return mixed
  82. */
  83. public function wap(PayOrder $payOrder)
  84. {
  85. $order = [
  86. 'out_trade_no' => $payOrder->trade_no.time(),
  87. 'total_amount' => $payOrder->price,
  88. 'subject' => $payOrder->subject,
  89. 'body' => $payOrder->detail,
  90. 'return_url' => $payOrder->return_url,
  91. ];
  92. return $this->alipay->wap($order);
  93. }
  94. }