WeishaoPayment.php 3.5 KB

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