YijiuPayment.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 YijiuPayment extends NewBasePayment
  12. {
  13. /**
  14. * 基础配置
  15. * @return void
  16. */
  17. function config()
  18. {
  19. $this->apiUrl = 'http://www.xsyzf8.com/apikey.do/';
  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. 'myid' =>'644089',
  32. 'mykey' =>'4C3BFF6F72D887A51FA11A4962BF91F8',
  33. 'out_trade_no' => strip_tags($data['out_trade_no']),
  34. 'money' => strip_tags($data['money']),
  35. 'coodkey' => strip_tags($data['coodkey']),
  36. 'oktime' => strip_tags($data['oktime']),
  37. 'zt' => strip_tags($data['zt']),
  38. );
  39. $order_no = $param['out_trade_no'] ?? '';
  40. $price = $param['money'] ? $param['money'] : 0;
  41. $sign = strip_tags(trim($data['sign']));
  42. $this->checkSign($param, $sign, $order_no, $price);
  43. }
  44. /**
  45. * 同步跳转
  46. * @param array $data
  47. * @return void [type] [description]
  48. */
  49. function redirect(array $data)
  50. {
  51. echo 'success';
  52. // TODO: Implement redirect() method.
  53. }
  54. /**
  55. * 检查支付信息
  56. * @return void [type] 0=失败,1=成功
  57. */
  58. function check()
  59. {
  60. // TODO: Implement check() method.
  61. }
  62. /**
  63. * 返回支付类型的数组
  64. * @return void [type] [description]
  65. */
  66. function getPaymentType()
  67. {
  68. // TODO: Implement getPaymentType() method.
  69. }
  70. /**
  71. * 构建订单提交数组
  72. * @return array
  73. */
  74. function buildOrder(): array
  75. {
  76. $orderInfo = [
  77. 'myid' =>$this->paymentConfig['merchant_id'],
  78. 'mykey' =>$this->paymentConfig['merchant_md5_secret'],
  79. 'dingdan' =>$this->dataAccess->orderSn,
  80. 'money' => number_format($this->dataAccess->money, 2, '.', ''),
  81. 'time' => time(),
  82. ];
  83. $sign = $this->buildSign($orderInfo, $this->paymentConfig['merchant_md5_secret']);
  84. $orderInfo['sign'] = $sign;
  85. $orderInfo['cmd']='data501pay';
  86. $orderInfo['qudao']=$this->dataAccess->payType;
  87. $orderInfo['name']='d';
  88. $orderInfo['returl']=$this->redirectUrl;
  89. $orderInfo['notifyurl']=$this->notifyUrl;
  90. return $orderInfo;
  91. }
  92. /**
  93. * 生成签名函数
  94. * @param array $param
  95. * @param string $merchantSecret
  96. * @return mixed
  97. */
  98. function buildSign(array $postData, $key)
  99. {
  100. if (!is_array($postData)) {
  101. return false;
  102. }
  103. //ksort($postData);
  104. $signStr = '';
  105. foreach ($postData as $k => $v) {
  106. // if (!$v) continue;
  107. $signStr .= "{$k}={$v}&";
  108. }
  109. $signStr = trim($signStr, '&');
  110. return (md5($signStr));
  111. }
  112. /**
  113. * 设置返回类型
  114. * @param string $type
  115. */
  116. function setReturnType($type = 'HTML')
  117. {
  118. // TODO: Implement setReturnType() method.
  119. $this->returnType = $type;
  120. }
  121. /**
  122. * 发起支付函数
  123. */
  124. function goPay()
  125. {
  126. /* $this->debug = 0;
  127. $this->method = "POST";
  128. $this->prePay();*/
  129. $orderInfo = $this->buildOrder();
  130. $json = $this->goPayCurl($this->apiUrl, $orderInfo);
  131. $ret = json_decode($json, 1);
  132. if (!$ret || $ret['data1'] !== 1) {
  133. Render('', -5989, $ret['msg'] ?? '');
  134. }
  135. $this->apiUrl = $ret['data2'];
  136. $this->method = 'GET';
  137. $this->prePay(0);
  138. }
  139. }