JingXiuPayUtil.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace app\utils\JingXiu;
  3. use app\utils\CurlUtil;
  4. use think\Request;
  5. class JingXiuPayUtil extends Module
  6. {
  7. private $host = 'https://gateway.jxpays.com/';
  8. private $mch_id = '880857099650860';
  9. private $merchant_private_key = 'MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCrqU2nld9LWTHobwBg0eCmg+ldR9CfAHpvJflxRgJ1H0wYjA+F2QNmY0najZP6G9a6MXOz+L5J2osKu53om1+nABXlcIX/oNV1y4XkgyN4AY2c7j3oAc4XWvJktIsjaosa7Jcj4Lq80oWW7rctBRLwa+n4WKehZ+1WTEYJQ7W1vcmmA3V3TYkQRUiAkgm68IAeen5Atg6A2SGD04AwxAIijSR+Wz2gK0AjzuD34++2tbgrlZN9rPp26AUzny1mcIeSIlpgTojGrwXLMK4mWqHbfG+B00uLQfEapXInGiJMID0Lo9rhyWF8iejVidmWkUni0VNJKEMYT1CoamA27tkFAgMBAAECggEAYdNl8a8zRVlbW76GVKbGg56BCyu19CbtnxHhCXCATga78vE+l2SIz3ydxfMQ9WOQByPPcCy9JJFq038ACmMhK6ac09hAROF/RFXrw8IIIIeiEGCk3ubIb/7gTAunj1NUWs+hgky7nofKoa0ArqNJm8Gj4GeFgDIdyyREdVsk3qCOiL1iI2WnNh0qAPkeQCx77b7x4qFgWhfyqumvhqiytc0HVZH10uaSKGU706Ejx3/NrAh8nqeT3Nlw0zM/EIZumDGM/Y3+wMZxuiD8niv3VnPL6Bc5wTdW7Jcdh/FQteV04SbfPldkgt51YQ63voVHnltyhg95bBtjMBQE3tyDAQKBgQDZPDh5kWL34zebvajVNs/yxL70BAb3Z4m6TpgQkNRwAD8ES4s/uH6OrmPansKwxULxqHDz2VGQ/qaNe2QU7w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6AowKEwyBDEvVnburdDo7ZL7FL0ntglA2NfUF2Viyby0HNMmcvbl6fbm+z5jXLcK++RNJQZoiTtvej6S19eH38ihll0cdUqtibO5oi9xzLyjEJq/bTexdQQIDAQAB';
  11. private $order_no = '';
  12. private $money = 0.01;
  13. private $remark = '';
  14. private $notify_url = '/api/jx_pay/pay_notify';
  15. /**
  16. * 微信手机支付
  17. * @param $order_no
  18. * @param $money
  19. * @param $remark
  20. * @param $notify_url
  21. * @return bool
  22. */
  23. public function wxWapPay($order_no, $money, $remark = '', $notify_url = '',$pay_type)
  24. {
  25. $this->order_no = $order_no;
  26. $this->money = $money;
  27. // $this->money = 0.01;
  28. $this->remark = $remark;
  29. $this->notify_url = $notify_url;
  30. $payment = [
  31. 'wechat' => 'wechatLiteH5',
  32. 'alipay' => 'alipayApp',
  33. // 'alipay' => 'alipaуWаp',
  34. // 'alipay' => 'alipayLite',
  35. ];
  36. try {
  37. $result = $this->addOrder($payment[$pay_type]);
  38. $code_url = $result['payurl'];
  39. //跳转地址
  40. $jumpurl = [
  41. 'wechat' => "/index/index/pay?url={$code_url}",
  42. 'alipay' => "/index/index/alipay?url={$code_url}",
  43. ];
  44. $jumpurl = $jumpurl[$pay_type];
  45. } catch (\Exception $e) {
  46. return $this->error('支付下单失败!' . $e->getMessage());
  47. }
  48. return $this->success('支付下单成功!', [
  49. 'out_trade_no' => $result['out_trade_no'],
  50. 'total_amount' => $result['total_amount'],
  51. 'trade_no' => $result['trade_no'],
  52. 'trade_type' => $result['trade_type'],
  53. 'url' => CurlUtil::getHttp($jumpurl)
  54. ]);
  55. }
  56. /**
  57. * 获取订单信息
  58. * @param $out_trade_no
  59. * @return mixed
  60. * @throws \Exception
  61. */
  62. public function getOrder($out_trade_no)
  63. {
  64. $client = new PasspayClient($this->host, $this->mch_id, $this->merchant_private_key, $this->platform_public_key);
  65. $param = [
  66. 'out_trade_no' => $out_trade_no,
  67. ];
  68. try {
  69. $result = $client->execute('pay.order/query', $param);
  70. } catch (\Exception $e) {
  71. return $this->error('获取失败!' . $e->getMessage());
  72. }
  73. return $this->success('获取成功!', $result);
  74. }
  75. /**
  76. * 校验通知签名
  77. * @param $params
  78. * @return bool
  79. */
  80. public function checkSign($params)
  81. {
  82. $client = new PasspayClient($this->host, $this->mch_id, $this->merchant_private_key, $this->platform_public_key);
  83. return $client->verifySign($params);
  84. }
  85. /**
  86. * 统一下单
  87. * @param string $trade_type
  88. * @param $sub_appid
  89. * @param $sub_openid
  90. * @return mixed
  91. */
  92. private function addOrder(string $trade_type, $sub_appid = null, $sub_openid = null)
  93. {
  94. // 客户端IP 防风控
  95. $client_ip = Request::instance()->ip();
  96. $client = new PasspayClient($this->host, $this->mch_id, $this->merchant_private_key, $this->platform_public_key);
  97. $notify_url = CurlUtil::getHttp($this->notify_url, false);
  98. $param = [
  99. 'trade_type' => $trade_type,
  100. 'out_trade_no' => $this->order_no,
  101. 'total_amount' => $this->money,
  102. "subject" => $this->remark,
  103. 'notify_url' => $notify_url,
  104. 'return_url' => '',//支付完成跳转地址,仅支持非原生支付,快捷支付,网银等支持同步跳转的支付类型
  105. 'client_ip' => $client_ip,
  106. ];
  107. if ($sub_appid && $sub_openid) {
  108. $param += [
  109. 'sub_appid' => $sub_appid,
  110. 'user_id' => $sub_openid,
  111. 'channe_expend' => json_encode(['is_raw' => 1])
  112. ];
  113. }
  114. return $client->execute('pay.order/create', $param);
  115. }
  116. }