QianlaibaoPayment.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/1/31
  6. * Time: 17:28
  7. */
  8. namespace Biz\Pay\Payment;
  9. use Biz\Pay\NewBasePayment;
  10. use Biz\Pay\PayInfo;
  11. class QianlaibaoPayment extends NewBasePayment
  12. {
  13. /**
  14. * 基础配置
  15. * @return void
  16. */
  17. function config()
  18. {
  19. $this->apiUrl = 'https://www.qlbzhifu.com/pay.h';
  20. $this->setReturnType();//根据客户端类型返回支付接口类型
  21. $this->success = 'success';
  22. }
  23. /**
  24. * 接收通知
  25. * @param array $data
  26. * @return void [type] [description] 返回为1或success视接口而定
  27. */
  28. function notify(array $data)
  29. {
  30. $param = [
  31. 'version' => strip_tags($data['version']),
  32. 'merchant_no' => strip_tags($data['merchant_no']),
  33. 'out_trade_no' => strip_tags($data['out_trade_no']),
  34. 'payment_type' => strip_tags($data['payment_type']),
  35. 'user_account' => strip_tags($data['user_account']),
  36. 'trade_no' => strip_tags($data['trade_no']),
  37. 'trade_status' => strip_tags($data['trade_status']),
  38. 'notify_time' => urldecode(strip_tags($data['notify_time'])),
  39. 'body' => strip_tags($data['body']),
  40. 'total_fee' => strip_tags($data['total_fee']),
  41. 'obtain_fee' => strip_tags($data['obtain_fee']),
  42. ];
  43. // dd($param);
  44. $order_no = $param['out_trade_no'] ?? '';
  45. $price = $param['total_fee'] ? $param['total_fee'] : 0;
  46. $real_price = $param['obtain_fee'] ? $param['obtain_fee'] : 0;
  47. $sign = strip_tags(trim($data['sign']));
  48. $this->checkSign($param, $sign, $order_no, $price, $real_price, $is_bill_no = 0);
  49. }
  50. /**
  51. * 同步跳转
  52. * @param array $data
  53. * @return void [type] [description]
  54. */
  55. function redirect(array $data)
  56. {
  57. $html = <<<EOT
  58. <script>setTimeout(function() {
  59. window.history.go(-2);
  60. },3000);</script>
  61. EOT;
  62. echo '支付已受理。如有疑问请联系客服!3秒后返回支付页,请稍候...';
  63. echo $html;
  64. }
  65. /**
  66. * 检查支付信息
  67. * @return void [type] 0=失败,1=成功
  68. */
  69. function check()
  70. {
  71. // TODO: Implement check() method.
  72. }
  73. /**
  74. * 返回支付类型的数组
  75. * @return void [type] [description]
  76. */
  77. function getPaymentType()
  78. {
  79. // TODO: Implement getPaymentType() method.
  80. }
  81. /**
  82. * 构建订单提交数组
  83. * @return array
  84. */
  85. function buildOrder(): array
  86. {
  87. $orderInfo = [
  88. 'merchant_no' => $this->paymentConfig['merchant_id'],
  89. 'version' => '1.0',
  90. 'out_trade_no' => $this->dataAccess->orderSn,
  91. 'payment_type' => $this->dataAccess->payType,
  92. 'notify_url' => $this->notifyUrl,
  93. 'page_url' => $this->redirectUrl,
  94. 'total_fee' => number_format($this->dataAccess->money, 2, '.', ''),
  95. 'trade_time' => date('YmdHis'),
  96. 'user_account' => 'UID' . time(),
  97. 'body' => $this->dataAccess->goodsName ?? 'testGoods',
  98. ];
  99. $sign = $this->buildSign($orderInfo, $this->paymentConfig['merchant_md5_secret']);
  100. $orderInfo['sign'] = $sign;
  101. return $orderInfo;
  102. }
  103. /**
  104. * 生成签名函数
  105. * @param array $param
  106. * @param string $merchantSecret
  107. * @return mixed
  108. */
  109. function buildSign(array $param, $merchantSecret)
  110. {
  111. if (!is_array($param)) {
  112. return false;
  113. }
  114. ksort($param);
  115. $signStr = '';
  116. foreach ($param as $k => $v) {
  117. // if (!$v) continue;
  118. $signStr .= "{$k}={$v}&";
  119. }
  120. $signStr = trim($signStr, '&') . $merchantSecret;
  121. return (md5($signStr));
  122. }
  123. /**
  124. * 设置返回类型
  125. * @param string $type
  126. */
  127. function setReturnType($type = 'HTML')
  128. {
  129. // TODO: Implement setReturnType() method.
  130. $this->returnType = $type;
  131. }
  132. /**
  133. * 发起支付函数
  134. */
  135. function goPay()
  136. {
  137. $this->debug = 0;
  138. $this->method = "POST";
  139. $this->prePay();
  140. }
  141. }