QianshouPayment.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/2/28
  6. * Time: 14:06
  7. */
  8. namespace Biz\Pay\Payment;
  9. //牵手支付
  10. use Biz\Pay\NewBasePayment;
  11. class QianshouPayment extends NewBasePayment
  12. {
  13. /**
  14. * 基础配置
  15. * @return void
  16. */
  17. function config()
  18. {
  19. $this->apiUrl = 'https://get.yichigo.com/online/gateway';
  20. $this->setReturnType();//根据客户端类型返回支付接口类型
  21. }
  22. /**
  23. * 接收通知
  24. * @param array $data
  25. * @return void [type] [description] 返回为1或success视接口而定
  26. */
  27. function notify(array $data)
  28. {
  29. //验证签名后返回对端服务器需要的响应内容
  30. $param = array(
  31. 'partner' => strip_tags($data['partner']),
  32. 'ordernumber' => strip_tags($data['ordernumber']),
  33. 'orderstatus' => strip_tags($data['orderstatus']),
  34. 'paymoney' => strip_tags($data['paymoney']),
  35. );
  36. $order_no = $param['ordernumber'] ?? '';
  37. $price = $param['paymoney'] ? $param['paymoney'] : 0;
  38. $sign = strip_tags(trim($data['sign']));
  39. $this->checkSign($param, $sign, $order_no, $price);
  40. }
  41. /**
  42. * 同步跳转
  43. * @param array $data
  44. * @return void [type] [description]
  45. */
  46. function redirect(array $data)
  47. {
  48. echo 'success';
  49. // TODO: Implement redirect() method.
  50. }
  51. /**
  52. * 检查支付信息
  53. * @return void [type] 0=失败,1=成功
  54. */
  55. function check()
  56. {
  57. // TODO: Implement check() method.
  58. }
  59. /**
  60. * 返回支付类型的数组
  61. * @return void [type] [description]
  62. */
  63. function getPaymentType()
  64. {
  65. // TODO: Implement getPaymentType() method.
  66. }
  67. /**
  68. * 构建订单提交数组
  69. * @return array
  70. */
  71. function buildOrder(): array
  72. {
  73. $orderInfo = [
  74. 'version' => '3.0',
  75. 'method' =>'Qs.online.interface',
  76. 'partner' =>$this->paymentConfig['merchant_id'],
  77. 'banktype' => $this->dataAccess->payType,
  78. 'paymoney' => number_format($this->dataAccess->money, 2, '.', ''),
  79. 'ordernumber' =>$this->dataAccess->orderSn,
  80. 'callbackurl'=>$this->notifyUrl,
  81. ];
  82. $sign = $this->buildSign($orderInfo, $this->paymentConfig['merchant_md5_secret']);
  83. $orderInfo['sign'] = $sign;
  84. $orderInfo['hrefbackurl'] = $this->redirectUrl;
  85. $orderInfo['attach'] =$this->dataAccess->goodsName ?? 'testGoods';
  86. return $orderInfo;
  87. }
  88. /**
  89. * 生成签名函数
  90. * @param array $param
  91. * @param string $merchantSecret
  92. * @return mixed
  93. */
  94. function buildSign(array $postData, $key)
  95. {
  96. if (!is_array($postData)) {
  97. return false;
  98. }
  99. $signStr = '';
  100. foreach ($postData as $k => $v) {
  101. // if (!$v) continue;
  102. $signStr .= "{$k}={$v}&";
  103. }
  104. $signStr = trim($signStr, '&') . $key;
  105. return (md5($signStr));
  106. }
  107. /**
  108. * 设置返回类型
  109. * @param string $type
  110. */
  111. function setReturnType($type = 'HTML')
  112. {
  113. // TODO: Implement setReturnType() method.
  114. $this->returnType = $type;
  115. }
  116. /**
  117. * 发起支付函数
  118. */
  119. function goPay()
  120. {
  121. $orderInfo = $this->buildOrder();
  122. $this->payInfo->orderInfo = $orderInfo;
  123. $this->payInfo->apiUrl = $this->apiUrl;
  124. $this->payInfo->method = 'POST';
  125. //跳转对方网关时直接订单入库
  126. $sysOrderInfo = $this->buildOrderInfo();
  127. $this->addOrder($sysOrderInfo);
  128. Render($this->payInfo, 1);
  129. }
  130. }