KuaibeiPayment.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 KuaibeiPayment extends NewBasePayment
  11. {
  12. /**
  13. * 基础配置
  14. * @return void
  15. */
  16. function config()
  17. {
  18. $this->apiUrl = 'http://pay.hpapi168.com/api.aspx';
  19. $this->setReturnType();//根据客户端类型返回支付接口类型
  20. $this->success = 'success';
  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. 'api_id' => strip_tags($data['api_id']),
  32. 'orderid' => strip_tags($data['orderid']),
  33. 'orderuid' => strip_tags($data['orderuid']),
  34. 'price' =>$data['price'],
  35. 'realprice' =>$data['price'],
  36. 'token' => '309990f0d5a24a5994b6ea72708272e7',
  37. );
  38. $order_no = $param['orderid'] ?? '';
  39. $price = $param['price'] ? $param['price'] : 0;
  40. $sign = strip_tags(trim($data['key']));
  41. $this->checkSign($param, $sign, $order_no, $price);
  42. }
  43. /**
  44. * 同步跳转
  45. * @param array $data
  46. * @return void [type] [description]
  47. */
  48. function redirect(array $data)
  49. {
  50. echo 'success';
  51. }
  52. /**
  53. * 检查支付信息
  54. * @return void [type] 0=失败,1=成功
  55. */
  56. function check()
  57. {
  58. // TODO: Implement check() method.
  59. }
  60. /**
  61. * 构建订单提交数组
  62. * @return array
  63. */
  64. function buildOrder(): array
  65. {
  66. $orderInfo = [
  67. 'istype' => $this->dataAccess->payType,
  68. 'notify_url' => $this->notifyUrl,
  69. 'orderid' => $this->dataAccess->orderSn,
  70. 'orderuid' =>$this->paymentConfig['merchant_id'],
  71. 'price' => number_format($this->dataAccess->money , 2, '.', ''),
  72. 'return_url' =>$this->redirectUrl,
  73. 'token'=>$this->paymentConfig['merchant_md5_secret'],
  74. 'uid'=>$this->paymentConfig['merchant_id'],
  75. ];
  76. $sign = $this->buildSign($orderInfo,true);
  77. $orderInfo['key'] = $sign;
  78. $orderInfo['custno'] = 'wns888';
  79. return $orderInfo;
  80. }
  81. /**
  82. * 生成签名函数
  83. * @param array $param
  84. * @param string $merchantSecret
  85. * @return mixed
  86. */
  87. function buildSign(array $param,$key)
  88. {
  89. if (!is_array($param)) {
  90. return false;
  91. }
  92. $signStr = '';
  93. foreach ($param as $k => $v) {
  94. $signStr .= "{$v}";
  95. }
  96. return (md5($signStr));
  97. }
  98. /**
  99. * 设置返回类型
  100. * @param string $type
  101. */
  102. function setReturnType($type = 'HTML')
  103. {
  104. $this->returnType = $type;
  105. }
  106. /**
  107. * 发起支付函数
  108. */
  109. function goPay()
  110. {
  111. $this->debug = 0;
  112. $this->method = "POST";
  113. $this->prePay();
  114. }
  115. }