LvbaoPayment.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/2/21
  6. * Time: 18:24
  7. */
  8. namespace Biz\Pay\Payment;
  9. use Biz\Pay\NewBasePayment;
  10. class LvbaoPayment extends NewBasePayment
  11. {
  12. /**
  13. * 基础配置
  14. * @return void
  15. */
  16. function config()
  17. {
  18. switch ($this->paymentConfig['gateway_code']) {
  19. case 'alipay':
  20. default:
  21. $this->apiUrl = 'http://pay.teamoe.cn/pay/pay/htmlalipaysubmit';
  22. break;
  23. case 'wxpay':
  24. $this->apiUrl = 'http://pay.teamoe.cn/pay/pay/htmlweixinsubmit';
  25. break;
  26. }
  27. $this->setReturnType();//根据客户端类型返回支付接口类型
  28. }
  29. /**
  30. * 接收通知
  31. * @param array $data
  32. * @return void [type] [description] 返回为1或success视接口而定
  33. */
  34. function notify(array $data)
  35. {
  36. //验证签名后返回对端服务器需要的响应内容
  37. $param = array(
  38. 'out_trade_no' => strip_tags(trim($data['out_trade_no'])),
  39. 'total_fee' => strip_tags(trim($data['total_fee'])),
  40. 'trade_status' => strip_tags(trim($data['trade_status'])),
  41. 'custom' => strip_tags(trim($data['custom'])),
  42. );
  43. $order_no = $param['out_trade_no'] ?? '';
  44. $price = $param['total_fee'] ? $param['total_fee'] : 0;
  45. $real_price = $param['total_fee'] ? $param['total_fee'] : 0;
  46. $sign = strip_tags(trim($data['sign']));
  47. $this->checkSign($param, $sign, $order_no, $price, $real_price, false);
  48. }
  49. /**
  50. * 同步跳转
  51. * @param array $data
  52. * @return void [type] [description]
  53. */
  54. function redirect(array $data)
  55. {
  56. echo 'success';
  57. }
  58. /**
  59. * 检查支付信息
  60. * @return void [type] 0=失败,1=成功
  61. */
  62. function check()
  63. {
  64. // TODO: Implement check() method.
  65. }
  66. /**
  67. * 构建订单提交数组
  68. * @return array
  69. */
  70. function buildOrder(): array
  71. {
  72. $orderInfo = [
  73. 'partner' => $this->paymentConfig['merchant_id'],
  74. 'out_trade_no' => $this->dataAccess->orderSn,
  75. 'exter_invoke_ip' => $this->getRealIp(),
  76. 'total_fee' => $this->dataAccess->money,
  77. 'custom' => $this->dataAccess->remark,
  78. 'notify_url' => $this->notifyUrl,
  79. 'return_url' => $this->redirectUrl,
  80. ];
  81. $sign = $this->buildSign($orderInfo, $this->paymentConfig['merchant_md5_secret']);
  82. $orderInfo['sign'] = $sign;
  83. // dd(var_export($orderInfo),$this->apiUrl);
  84. return $orderInfo;
  85. }
  86. /**
  87. * 生成签名函数
  88. * @param array $param
  89. * @param string $merchantSecret
  90. * @return mixed
  91. */
  92. function buildSign(array $param, $merchantSecret)
  93. {
  94. if (!is_array($param)) {
  95. return false;
  96. }
  97. ksort($param);
  98. $signStr = '';
  99. foreach ($param as $k => $v) {
  100. if (!$v) continue;
  101. $signStr .= "{$k}={$v}&";
  102. }
  103. $signStr = trim($signStr, '&') . $merchantSecret;
  104. return (md5($signStr));
  105. }
  106. /**
  107. * 设置返回类型
  108. * @param string $type
  109. */
  110. function setReturnType($type = 'HTML')
  111. {
  112. $this->returnType = $type;
  113. }
  114. /**
  115. * 发起支付函数
  116. */
  117. function goPay()
  118. {
  119. $this->debug = 0;
  120. $this->method = "POST";
  121. $this->prePay();
  122. }
  123. }