YunanPayment.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/3/5
  6. * Time: 13:06
  7. */
  8. namespace Biz\Pay\Payment;
  9. use Biz\Pay\NewBasePayment;
  10. class YunanPayment extends NewBasePayment
  11. {
  12. private $paySign = false;
  13. /**
  14. * 接收通知
  15. * @param array $data
  16. * @return void
  17. */
  18. function notify(array $data)
  19. {
  20. $param = [
  21. 'orderstatus' => trim(strip_tags($data['orderstatus'])),
  22. 'ordernumber' => trim(strip_tags($data['ordernumber'])),
  23. 'paymoney' => trim(strip_tags($data['paymoney'])),
  24. ];
  25. $sign = trim(strip_tags($data['sign']));
  26. $order_no = $param['ordernumber'];
  27. $price = $param['paymoney'];
  28. $real_price = $param['paymoney'];
  29. $bill_no = $param['ordernumber'];
  30. $this->checkSign($param, $sign, $order_no, $price, $real_price, $is_bill_no = 0, $bill_no);
  31. }
  32. /**
  33. * 返回跳转
  34. * @param array $data
  35. * @return void [type] [description]
  36. */
  37. function redirect(array $data)
  38. {
  39. // TODO: Implement redirect() method.
  40. }
  41. /**
  42. * 检查支付信息
  43. * @return void [type] 0=失败,1=成功
  44. */
  45. function check()
  46. {
  47. // TODO: Implement check() method.
  48. }
  49. /**
  50. * 构建订单提交数组
  51. * @return array
  52. */
  53. function buildOrder(): array
  54. {
  55. $param = [
  56. 'banktype' => $this->dataAccess->payType,
  57. 'partner' => $this->paymentConfig['merchant_id'],
  58. 'paymoney' => $this->dataAccess->money,
  59. 'ordernumber' => $this->dataAccess->orderSn,
  60. // 'ordernumber' => date("YmdHis"),
  61. 'callbackurl' => $this->notifyUrl,
  62. 'hrefbackurl' => $this->redirectUrl,
  63. 'attach' => $this->dataAccess->goodsName ?? 'orderDetail',
  64. ];
  65. $param['sign'] = $this->buildSign($param, $this->paymentConfig['merchant_md5_secret']);
  66. return $param;
  67. }
  68. /**
  69. * 生成签名函数
  70. * @param array $param
  71. * @param string $merchantSecret
  72. * @return mixed
  73. */
  74. function buildSign(array $param, $merchantSecret)
  75. {
  76. $partner = $this->paymentConfig['merchant_id'];
  77. $ordernumber = $param['ordernumber'];
  78. $banktype = $param['banktype'];
  79. $paymoney = $param['paymoney'];
  80. $callbackurl = $param['callbackurl'];
  81. $n_ordernumber = $param['ordernumber'];
  82. $n_orderstatus = $param['txthrefbackurl'];
  83. $n_paymoney = $param['paymoney'];
  84. $n_partner = $this->merchant_id;
  85. $pay_sign_src = sprintf("partner=%s&banktype=%s&paymoney=%s&ordernumber=%s&callbackurl=%s%s", $partner, $banktype, $paymoney, $ordernumber, $callbackurl, $merchantSecret);
  86. $signSource = sprintf("partner=%s&ordernumber=%s&orderstatus=%s&paymoney=%s%s", $n_partner, $n_ordernumber, $n_orderstatus, $n_paymoney, $merchantSecret);
  87. // dd($this->paySign,$pay_sign_src);
  88. return $this->paySign ? md5($pay_sign_src) : md5($signSource);
  89. }
  90. /**
  91. * 基础配置
  92. * @return void
  93. */
  94. function config()
  95. {
  96. $this->apiUrl = 'https://pay.antopay.com/AntoPay.html';
  97. $this->setReturnType();//根据客户端类型返回支付接口类型
  98. $this->success = 'ok';
  99. }
  100. /**
  101. * 设置返回类型
  102. * @param string $type
  103. */
  104. function setReturnType($type = 'HTML')
  105. {
  106. // TODO: Implement setReturnType() method.
  107. }
  108. /**
  109. * 发起支付函数
  110. * @return mixed
  111. */
  112. function goPay()
  113. {
  114. $this->debug = 0;
  115. $this->method = "GET";
  116. $this->paySign = true;
  117. $this->prePay();
  118. }
  119. }