DahePayment.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. namespace App\Repositories\Service\Payment;
  3. class DahePayment extends PaymentInterface
  4. {
  5. /**
  6. * 支付请求地址
  7. *
  8. * @var string
  9. */
  10. private $payUrl = 'http://www.azhifu2022.com/Pay';
  11. const SUCCESS_STATUS = 1;
  12. /**
  13. * 公钥
  14. *
  15. * @var string
  16. */
  17. private $publicKey = 'LzMIHCQnVlWFWYVJlrcAmLDUjSraEHhL';
  18. /**
  19. * @var null
  20. */
  21. private static $_instance = null;
  22. /**
  23. * @return WhiteSharkPayment|null
  24. */
  25. public static function getInstance()
  26. {
  27. if (is_null(self::$_instance)) {
  28. self::$_instance = new self();
  29. }
  30. return self::$_instance;
  31. }
  32. public function createPayLink($data = array())
  33. {
  34. $payInfo = [
  35. 'fxid' => $data['partner_id'], //商户号
  36. 'fxddh' => $data['order_sn'],
  37. 'fxdesc' => 'PAY',
  38. 'fxattch' => 'PAY',
  39. 'fxfee' => sprintf('%.2f', $data['money']),
  40. 'fxnotifyurl' => $data['notify_url'],
  41. 'fxbackurl' => $data['pay_url'],
  42. 'fxpay' => $data['pay_attr_code'],
  43. ];
  44. $payInfo['fxip'] = '127.0.0.1';
  45. $payInfo['fxsign'] = md5($payInfo['fxid'] . $payInfo['fxddh'] . $payInfo['fxfee'] . $payInfo['fxnotifyurl'] . $this->publicKey);
  46. $sRes = $this->httpPost($this->payUrl, $payInfo);
  47. if (empty($sRes)) {
  48. $this->_lastError = '请求异常';
  49. payLogger(__CLASS__, '请求异常data=' . $sRes, $payInfo);
  50. return '';
  51. }
  52. $aRes = json_decode($sRes, true);
  53. if (empty($aRes)) {
  54. $this->_lastError = '请求异常!';
  55. payLogger(__CLASS__, '请求异常 (解析) data=' . $sRes, $payInfo);
  56. return '';
  57. }
  58. if ($aRes['status'] != self::SUCCESS_STATUS) {
  59. $this->_lastError = '请求异常,请求失败';
  60. payLogger(__CLASS__, '请求异常,请求失败 data=' . $sRes, $payInfo);
  61. return '';
  62. }
  63. return $aRes['payurl'];
  64. }
  65. public function queryOrder($data, &$orderSn, &$money, $partnerId)
  66. {
  67. $queryInfo = [
  68. 'fxid' => $partnerId,
  69. 'fxddh' => $orderSn,
  70. 'fxaction' => 'orderquery',
  71. ];
  72. $queryInfo['fxsign'] = md5($partnerId . $orderSn . 'orderquery' . $this->publicKey);
  73. $sRes = $this->httpPost($this->payUrl, $queryInfo);
  74. if (empty($sRes)) {
  75. $this->_lastError = '查询请求异常';
  76. payLogger(__CLASS__, '查询请求异常 data=' . $sRes, $queryInfo);
  77. return '';
  78. }
  79. $aRes = json_decode($sRes, true);
  80. if (empty($aRes)) {
  81. $this->_lastError = '查询解析异常';
  82. payLogger(__CLASS__, '查询解析异常 data=' . $sRes, $queryInfo);
  83. return '';
  84. }
  85. if ($aRes['fxstatus'] != self::SUCCESS_STATUS) {
  86. $this->_lastError = '查询订单状态异常';
  87. payLogger(__CLASS__, '查询订单状态异常 data=' . $sRes, $queryInfo);
  88. return '';
  89. }
  90. if ($money != $aRes['fxfee']) {
  91. $this->_lastError = '查询订单金额异常';
  92. payLogger(__CLASS__, '查询订单金额异常 data=' . $sRes, $queryInfo);
  93. return '';
  94. }
  95. return true;
  96. }
  97. public function notify(&$orderSn, &$tradeNo, &$money, $partnerId)
  98. {
  99. $data = request()->all();
  100. if ($data['fxstatus'] != self::SUCCESS_STATUS) {
  101. payLogger(__CLASS__, '回调订单状态失败', $data);
  102. return false;
  103. }
  104. $sign = md5($data['fxstatus'] . $partnerId . $data['fxddh'] . $data['fxfee'] . $this->publicKey);
  105. if ($sign != $data['fxsign']) {
  106. $this->_lastError = '验证失败!';
  107. payLogger(__CLASS__, '验证失败 key=' . $this->publicKey, $data);
  108. return false;
  109. }
  110. $money = $data['fxfee'];
  111. $res = $this->queryOrder($data, $data['fxddh'], $money, $partnerId);
  112. if (empty($res)) {
  113. return '';
  114. }
  115. $orderSn = $data['fxddh'];
  116. $tradeNo = $data['fxorder'];
  117. return true;
  118. }
  119. public function stopNotify()
  120. {
  121. return 'success';
  122. }
  123. }