123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
- namespace app\utils\JingXiu;
- use app\utils\CurlUtil;
- use think\Request;
- class JingXiuPayUtil extends Module
- {
- private $host = 'https://gateway.jxpays.com/';
- private $mch_id = '880857099650860';
- 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/qaNe2QU7wYI/rgkQWklPy2VGVSQ30369eJEDenwDSL4Qv5Xav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by0HNMmcvbl6fbm+z5jXLcK++RNJQZoiTtvej6S19eH38ihll0cdUqtibO5oi9xzLyjEJq/bTexdQQIDAQAB';
- private $order_no = '';
- private $money = 0.01;
- private $remark = '';
- private $notify_url = '/api/jx_pay/pay_notify';
- /**
- * 微信手机支付
- * @param $order_no
- * @param $money
- * @param $remark
- * @param $notify_url
- * @return bool
- */
- public function wxWapPay($order_no, $money, $remark = '', $notify_url = '',$pay_type)
- {
- $this->order_no = $order_no;
- $this->money = $money;
- // $this->money = 0.01;
- $this->remark = $remark;
- $this->notify_url = $notify_url;
- $payment = [
- 'wechat' => 'wechatLiteH5',
- 'alipay' => 'alipayApp',
- // 'alipay' => 'alipaуWаp',
- // 'alipay' => 'alipayLite',
- ];
- try {
- $result = $this->addOrder($payment[$pay_type]);
- $code_url = $result['payurl'];
- //跳转地址
- $jumpurl = [
- 'wechat' => "/index/index/pay?url={$code_url}",
- 'alipay' => "/index/index/alipay?url={$code_url}",
- ];
- $jumpurl = $jumpurl[$pay_type];
- } catch (\Exception $e) {
- return $this->error('支付下单失败!' . $e->getMessage());
- }
- return $this->success('支付下单成功!', [
- 'out_trade_no' => $result['out_trade_no'],
- 'total_amount' => $result['total_amount'],
- 'trade_no' => $result['trade_no'],
- 'trade_type' => $result['trade_type'],
- 'url' => CurlUtil::getHttp($jumpurl)
- ]);
- }
- /**
- * 获取订单信息
- * @param $out_trade_no
- * @return mixed
- * @throws \Exception
- */
- public function getOrder($out_trade_no)
- {
- $client = new PasspayClient($this->host, $this->mch_id, $this->merchant_private_key, $this->platform_public_key);
- $param = [
- 'out_trade_no' => $out_trade_no,
- ];
- try {
- $result = $client->execute('pay.order/query', $param);
- } catch (\Exception $e) {
- return $this->error('获取失败!' . $e->getMessage());
- }
- return $this->success('获取成功!', $result);
- }
- /**
- * 校验通知签名
- * @param $params
- * @return bool
- */
- public function checkSign($params)
- {
- $client = new PasspayClient($this->host, $this->mch_id, $this->merchant_private_key, $this->platform_public_key);
- return $client->verifySign($params);
- }
- /**
- * 统一下单
- * @param string $trade_type
- * @param $sub_appid
- * @param $sub_openid
- * @return mixed
- */
- private function addOrder(string $trade_type, $sub_appid = null, $sub_openid = null)
- {
- // 客户端IP 防风控
- $client_ip = Request::instance()->ip();
- $client = new PasspayClient($this->host, $this->mch_id, $this->merchant_private_key, $this->platform_public_key);
- $notify_url = CurlUtil::getHttp($this->notify_url, false);
- $param = [
- 'trade_type' => $trade_type,
- 'out_trade_no' => $this->order_no,
- 'total_amount' => $this->money,
- "subject" => $this->remark,
- 'notify_url' => $notify_url,
- 'return_url' => '',//支付完成跳转地址,仅支持非原生支付,快捷支付,网银等支持同步跳转的支付类型
- 'client_ip' => $client_ip,
- ];
- if ($sub_appid && $sub_openid) {
- $param += [
- 'sub_appid' => $sub_appid,
- 'user_id' => $sub_openid,
- 'channe_expend' => json_encode(['is_raw' => 1])
- ];
- }
- return $client->execute('pay.order/create', $param);
- }
- }
|