QuanyinPayment.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/3/9
  6. * Time: 13:13
  7. */
  8. namespace Biz\Pay\Payment;
  9. use Biz\Pay\NewBasePayment;
  10. class QuanyinPayment extends NewBasePayment
  11. {
  12. /**
  13. * 接收通知
  14. * @param array $data
  15. * @return void
  16. */
  17. function notify(array $data)
  18. {
  19. $arr['payKey'] = strip_tags(trim($data['payKey']));
  20. $arr['productName'] = strip_tags(trim($data['productName']));
  21. $arr['orderNo'] = strip_tags(trim($data['orderNo']));
  22. $arr['orderPrice'] = strip_tags(trim($data['orderPrice']));
  23. $arr['payWayCode'] = strip_tags(trim($data['payWayCode']));
  24. $arr['payPayCode'] = strip_tags(trim($data['payPayCode']));
  25. $arr['orderDate'] = strip_tags(trim($data['orderDate']));
  26. $arr['orderTime'] = strip_tags(trim($data['orderTime']));
  27. $arr['remark'] = strip_tags(trim($data['remark']));
  28. $arr['trxNo'] = strip_tags(trim($data['trxNo']));
  29. $arr['field1'] = strip_tags(trim($data['field1']));
  30. $arr['tradeStatus'] = strip_tags(trim($data['tradeStatus']));
  31. $sign = $data['sign'];
  32. $order_no = $arr['orderNo'];
  33. $price = $real_price = $arr['orderPrice'];
  34. $bill_no = $arr['trxNo'];
  35. if (!$arr['tradeStatus'] == 'SUCCESS') die('ERROR');
  36. $this->checkSign($arr, $sign, $order_no, $price, $real_price, $is_bill_no = 0, $bill_no);
  37. }
  38. /**
  39. * 返回跳转
  40. * @param array $data
  41. * @return void [type] [description]
  42. */
  43. function redirect(array $data)
  44. {
  45. // TODO: Implement redirect() method.
  46. }
  47. /**
  48. * 检查支付信息
  49. * @return void [type] 0=失败,1=成功
  50. */
  51. function check()
  52. {
  53. // TODO: Implement check() method.
  54. }
  55. /**
  56. * 构建订单提交数组
  57. * @return array
  58. */
  59. function buildOrder(): array
  60. {
  61. $arr['payKey'] = $this->paymentConfig['merchant_id'];
  62. $arr['payWayCode'] = 'ZITOPAY';
  63. $arr['orderNo'] = $this->dataAccess->orderSn;
  64. $arr['orderPrice'] = $this->dataAccess->money;
  65. $arr['productName'] = $this->dataAccess->goodsName ?? 'GoodsName';
  66. $arr['payTypeCode'] = $this->dataAccess->payType;
  67. $arr['notifyUrl'] = $this->notifyUrl;
  68. $arr['returnUrl'] = $this->redirectUrl;
  69. $arr['orderIp'] = $this->getRealIp();
  70. $arr['orderDate'] = date('Ymd', time());
  71. $arr['orderTime'] = date('YmdHis', time());
  72. $arr['orderPeriod'] = 30;
  73. $arr['remark'] = $this->dataAccess->goodsName ?? 'GoodsName';
  74. $arr['field1'] = $this->dataAccess->goodsName ?? 'GoodsName';
  75. $arr['sign'] = $this->buildSign($arr, $this->paymentConfig['merchant_md5_secret']);
  76. return $arr;
  77. }
  78. /**
  79. * 生成签名函数
  80. * @param array $param
  81. * @param string $merchantSecret
  82. * @return mixed
  83. */
  84. function buildSign(array $param, $merchantSecret)
  85. {
  86. ksort($param);
  87. $a = '';
  88. foreach ($param as $x => $x_value) {
  89. if ($x_value) {
  90. $a = $a . $x . '=' . $x_value . '&';
  91. }
  92. }
  93. return strtoupper(md5($a . 'paySecret=' . $merchantSecret));
  94. }
  95. /**
  96. * 基础配置
  97. * @return void
  98. */
  99. function config()
  100. {
  101. $this->apiUrl = "http://api.quanyinzf.com:8050/rb-pay-web-gateway/scanPay/initPayIntf";
  102. }
  103. /**
  104. * 设置返回类型
  105. * @param string $type
  106. */
  107. function setReturnType($type = 'HTML')
  108. {
  109. // TODO: Implement setReturnType() method.
  110. }
  111. /**
  112. * 发起支付函数
  113. * @return mixed
  114. */
  115. function goPay()
  116. {
  117. $order_info = $this->buildOrder();
  118. $json = $this->goPayCurl($this->apiUrl, $order_info);
  119. $ret = json_decode($json, 1);
  120. if (!$ret || $ret['result'] !== 'success' || !$ret['code_url']) {
  121. Render('', -5989);
  122. }
  123. $this->apiUrl = $ret['code_url'];
  124. $dpgateName = '';
  125. switch ($this->dataAccess->payType) {
  126. case 'ZITOPAY_ALI_SCAN':
  127. $dpgateName = '支付宝';
  128. break;
  129. case 'ZITOPAY_WX_SCAN':
  130. $dpgateName = '微信';
  131. break;
  132. case 'ZITOPAY_QQ_SCAN':
  133. $dpgateName = 'QQ';
  134. break;
  135. case 'JPAY_JDPAY':
  136. $dpgateName = '京东钱包';
  137. break;
  138. case 'ZITOPAY_UNION_SCAN':
  139. $dpgateName = '银联';
  140. break;
  141. default:
  142. $this->prePay(1);
  143. }
  144. $this->prePay(1, $this->apiUrl, $dpgateName);
  145. }
  146. }