<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## ***laravel5.5 使用三方支付擴展:```yansongda/laravel-pay```** ##### <blockquote class="danger"><p>如需了解更多,請訪問php專屬擴展庫鏈接:Packgist[鏈接](http://packagist.p2hp.com/packages/yansongda/laravel-pay) -------------------------------------------------------------------------------------------------------------------- 1. laravel5.5 使用 微信支付【事先引入擴展類:```use Yansongda\LaravelPay\Facades\Pay;```】 1.1:使用默認配置文件,發起微信支付 使用代碼【微信H5支付:返回支付鏈接地址】: ``` try { $response = Pay::wechat()->wap($data); if ($url = $response->getTargetUrl()) { $client = new Client([ 'timeout' => 5.0, 'headers' => [ 'Referer' => config('app.url') ] ]); $contents = $client->get($url)->getBody()->getContents(); Log::debug('微信H5支付返回:', ['data' => $data, 'response' => $contents]); $match = []; if (0 === preg_match('/var\surl="(.*?)"/', (string)$contents, $match) || empty($match[1])) { return failed('system.busy'); } Log::debug('微信H5支付url:', ['data' => $data, 'url' => $match[1]]); return success(['url' => $match[1]]); } return failed('system.busy'); } catch (\Exception $e) { Log::debug('微信H5支付出錯:' . $e->getMessage(), $data); return failed(); } ``` 1.2:使用自定義配置文件,發起微信支付 使用代碼【微信H5支付:返回支付鏈接地址】: ``` $data = [ 'out_trade_no' => $request->number, 'body' => $order->props_name ?? '', 'total_fee' => $money * 100 ]; try { $config = config('pay.wolf'); Log::info("北極狼新商戶號:".json_encode($config)); $wxPay = \Yansongda\Pay\Pay::wechat($config); $response = $wxPay->wap($data); if ($url = $response->getTargetUrl()) { $client = new Client([ 'timeout' => 5.0, 'headers' => [ 'Referer' => $config['url'] ] ]); $contents = $client->get($url)->getBody()->getContents(); Log::debug('北極狼微信H5支付返回:', ['data' => $data, 'response' => $contents]); $match = []; if (0 === preg_match('/var\surl="(.*?)"/', (string)$contents, $match) || empty($match[1])) { return failed('system.busy'); } Log::debug('北極狼微信H5url:', ['data' => $data, 'url' => $match[1]]); return success(['url' => $match[1]]); } return failed('system.busy'); } catch (\Exception $e) { Log::debug('北極狼微信H5支付出錯:' . $e->getMessage(), $data); return failed(); } ``` 1.3:異步回調通知代碼【使用默認配置,則不需要傳入config配置】: ``` $config = config('pay.wolf'); $wxPay = \Yansongda\Pay\Pay::wechat($config); try { $data = $wxPay->verify(); if (!$order = Order::unPayedByNumber($data->out_trade_no)) { throw new \Exception("訂單不存在或已完成支付"); } // ------折扣[根據是否有折扣判斷金額是否相同]Start------ if ($order->pay_currency_code != PayType::PAY_CNY_CURRENCY_CODE) { return failed('H5微信支付幣種有誤!!!'); } $discount = Game::checkDiscount($order->game_id); $order->real_order_money = !empty($discount) ? $order->real_order_money * ($discount / 100) : $order->real_order_money; $order->real_order_money = number_format($order->real_order_money, 2, '.', ''); // ------折扣[根據是否有折扣判斷金額是否相同]End-------- if ($order->real_order_money != floatval($data->total_fee / 100)) { throw new \Exception("訂單金額不符"); } $params = [ 'real_pay_currency_code' => 'CNY', 'real_pay_money' => floatval($data->total_fee / 100), 'pay_type_id' => PayType::WX_PAY_ID ]; if (!Order::orderPaySuccessWithOutMoney($data->out_trade_no, $data->transaction_id, $params)) { throw new \Exception("訂單狀態更新失敗"); } event(new PaySuccess($data->out_trade_no)); } catch (\Exception $e) { Log::error('微信支付成功通知出錯:' . $e->getMessage(), $request->all()); } return $wxPay->success(); ``` 2. laravel5.5 使用 支付寶支付【事先引入擴展類:```use Yansongda\LaravelPay\Facades\Pay;```】 2.1:使用默認配置文件,發起支付寶支付 使用代碼【支付寶H5支付:返回支付form表單】: ``` $this->validate($request, [ 'number' => 'string|required' ]); if (!$order = Order::unPayedByNumberUser($request->number, Member::id())) { return failed('order.non_existent'); } Order::orderPaying($order, PayType::Ali_PAY_H5); if (!($money = RmbContrastGoods::convertRmb($order->pay_currency_code, $order->money)) || ($money <= 0)) { return failed('system.busy'); } $data = [ 'out_trade_no' => $request->number, 'subject' => $order->props_name ?? '', 'total_amount' => $money ]; try { $response = Pay::alipay()->wap($data); return success(['form' => $response->getContent()]); } catch (\Exception $e) { Log::debug('支付寶H5支付出錯:' . $e->getMessage(), $data); return failed(); } ``` 2.2:使用自定義配置文件,發起支付寶支付 使用代碼【支付寶H5支付:返回支付form表單】: ``` $data = [ 'out_trade_no' => $request->number, 'subject' => $order->props_name ?? '', 'total_amount' => 0.01, 'product_code' => 'FAST_INSTANT_TRADE_PAY' ]; try { $response = \Yansongda\Pay\Pay::alipay(config('pay.alipay_sandbox'))->web($data); return success(['form' => $response->getContent()]); } catch (\Exception $e) { Log::error('Sandbox 支付寶web支付出錯:' . $e->getMessage(), $data); return failed(); } ``` 2.3:異步回調通知代碼【使用默認配置,則不需要傳入config配置】: ``` Log::debug('支付寶支付成功通知(同步)', $request->all()); $aliPay = Pay::alipay(); try { $data = $aliPay->verify(); if (!$order = Order::unPayedByNumber($data->out_trade_no)) { throw new \Exception("訂單不存在或已完成支付"); } if ((RmbContrastGoods::convertRmb($order->pay_currency_code, $order->real_order_money) != floatval($data->total_amount)) && floatval($data->total_amount) != 0.01) { throw new \Exception("訂單金額不符"); } $params = [ 'real_pay_currency_code' => 'CNY', 'real_pay_money' => $data->total_amount, 'pay_type_id' => \App\Models\PayType::ALI_PAY_ID ]; if (!Order::orderPaySuccessWithOutMoney($data->out_trade_no, $data->trade_no, $params)) { throw new \Exception("訂單狀態更新失敗"); } event(new PaySuccess($data->out_trade_no)); } catch (\Exception $e) { Log::error('支付寶支付成功通知出錯(同步):' . $e->getMessage(), $request->all()); } return $aliPay->success(); ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看