EPay.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace App\Payments;
  3. class EPay {
  4. public function __construct($config)
  5. {
  6. $this->config = $config;
  7. }
  8. public function form()
  9. {
  10. return [
  11. 'url' => [
  12. 'label' => 'URL',
  13. 'description' => '',
  14. 'type' => 'input',
  15. ],
  16. 'pid' => [
  17. 'label' => 'PID',
  18. 'description' => '',
  19. 'type' => 'input',
  20. ],
  21. 'key' => [
  22. 'label' => 'KEY',
  23. 'description' => '',
  24. 'type' => 'input',
  25. ]
  26. ];
  27. }
  28. public function pay($order)
  29. {
  30. $params = [
  31. 'money' => $order['total_amount'] / 100,
  32. 'name' => $order['trade_no'],
  33. 'notify_url' => $order['notify_url'],
  34. 'return_url' => $order['return_url'],
  35. 'out_trade_no' => $order['trade_no'],
  36. 'pid' => $this->config['pid']
  37. ];
  38. ksort($params);
  39. reset($params);
  40. $str = stripslashes(urldecode(http_build_query($params))) . $this->config['key'];
  41. $params['sign'] = md5($str);
  42. $params['sign_type'] = 'MD5';
  43. return [
  44. 'type' => 1, // 0:qrcode 1:url
  45. 'data' => $this->config['url'] . '/submit.php?' . http_build_query($params)
  46. ];
  47. }
  48. public function notify($params)
  49. {
  50. $sign = $params['sign'];
  51. unset($params['sign']);
  52. unset($params['sign_type']);
  53. ksort($params);
  54. reset($params);
  55. $str = stripslashes(urldecode(http_build_query($params))) . $this->config['key'];
  56. if ($sign !== md5($str)) {
  57. return false;
  58. }
  59. return [
  60. 'trade_no' => $params['out_trade_no'],
  61. 'callback_no' => $params['trade_no']
  62. ];
  63. }
  64. }