CypalPayment.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/3/4
  6. * Time: 16:47
  7. */
  8. namespace Biz\Pay\Payment;
  9. use Biz\Pay\NewBasePayment;
  10. class CypalPayment extends NewBasePayment
  11. {
  12. /**
  13. * 接收通知
  14. * @param array $data
  15. * @return void
  16. */
  17. function notify(array $data)
  18. {
  19. $param = [
  20. 'orderNo' => trim(strip_tags($data['orderNo'])),
  21. 'partnerOrderNo' => trim(strip_tags($data['partnerOrderNo'])),
  22. 'status' => trim(strip_tags($data['status'])),
  23. 'timestamp' => trim(strip_tags($data['timestamp'])),
  24. 'attach' => trim(strip_tags($data['attach'])),
  25. 'money' => trim(strip_tags($data['money'])),
  26. 'sign' => trim(strip_tags($data['signature'])),
  27. ];
  28. $sign = $param['sign'];
  29. unset($param['sign']);
  30. $order_no = $param['partnerOrderNo'];
  31. $price = $param['money'];
  32. $real_price = $param['money'];
  33. $bill_no = $param['orderNo'];
  34. $this->checkSign($param, $sign, $order_no, $price, $real_price, $is_bill_no = 0, $bill_no);
  35. }
  36. /**
  37. * 返回跳转
  38. * @param array $data
  39. * @return void [type] [description]
  40. */
  41. function redirect(array $data)
  42. {
  43. // TODO: Implement redirect() method.
  44. }
  45. /**
  46. * 检查支付信息
  47. * @return void [type] 0=失败,1=成功
  48. */
  49. function check()
  50. {
  51. // TODO: Implement check() method.
  52. }
  53. /**
  54. * 构建订单提交数组
  55. * @return array
  56. */
  57. function buildOrder(): array
  58. {
  59. $orderInfo = array(
  60. 'amount' => number_format($this->dataAccess->money, 2, '.', ''),
  61. 'partnerOrderNo' => $this->dataAccess->orderSn,
  62. 'goodsDesc' => $this->dataAccess->goodsName ?? 'TestGoods',
  63. 'attach' => $this->dataAccess->extra ?? 'TestGoodsRemark',
  64. 'timestamp' => time() . '000',
  65. 'returnUrl' => $this->redirectUrl,
  66. 'notifyUrl' => $this->notifyUrl,
  67. 'partnerCode' => $this->paymentConfig['merchant_id'],
  68. 'payType' => $this->dataAccess->payType,
  69. 'userUnqueNo' => '' . time(),
  70. );
  71. $sign = $this->buildSign2($orderInfo, $this->paymentConfig['merchant_md5_secret']);
  72. $orderInfo['signature'] = $sign;
  73. return $orderInfo;
  74. }
  75. /**
  76. * 生成签名函数
  77. * @param array $param
  78. * @param string $merchantSecret
  79. * @return mixed
  80. */
  81. function buildSign(array $param, $merchantSecret)
  82. {
  83. if (!is_array($param)) {
  84. return false;
  85. }
  86. $signStr = md5($param['userid'] . $param['timestamp']) . $merchantSecret;
  87. return strtoupper(md5($signStr));
  88. }
  89. /**
  90. * 发起支付签名函数
  91. * @param array $param
  92. * @param $merchantSecret
  93. * @return bool|string
  94. */
  95. function buildSign2(array $param, $merchantSecret)
  96. {
  97. if (!is_array($param)) {
  98. return false;
  99. }
  100. $signStr = md5($param['partnerCode'] . $param['timestamp']) . $merchantSecret;
  101. return strtoupper(md5($signStr));
  102. }
  103. /**
  104. * 基础配置
  105. * @return void
  106. */
  107. function config()
  108. {
  109. $this->apiUrl = 'http://www.cypal.cn/open/otc/unify_order';
  110. $this->setReturnType();//根据客户端类型返回支付接口类型
  111. $this->success = 'SUCCESS';
  112. }
  113. /**
  114. * 设置返回类型
  115. * @param string $type
  116. */
  117. function setReturnType($type = 'HTML')
  118. {
  119. // TODO: Implement setReturnType() method.
  120. }
  121. /**
  122. * 发起支付函数
  123. * @return mixed
  124. */
  125. function goPay()
  126. {
  127. $this->debug = 0;
  128. $this->method = "GET";
  129. $this->prePay();
  130. }
  131. }