$this->oWxPay->appid, 'mch_id' => $this->oWxPay->mcid, 'key' => $this->oWxPay->apikey, 'notify_url' => Config::get('site.scheme') . '://' . $this->oWxPay->pay_host . '/api/wechat/wxh5pay', ]; $config = array_merge(PayConstants::getH5DefaultConfig(), $config); $this->weChatPay = Pay::wechat($config); return $this->weChatPay; } /** * 调用第三方服务创建订单 * @return \app\main\model\object\ReturnObject */ public function createOrder() { try { $this->initPay(); $out_trade_no = $this->getOutTradeNo($this->oOrder->user_id)->data; $order = [ 'out_trade_no' => $out_trade_no, 'total_fee' => $this->oOrder->money * 100, 'body' => $this->oOrder->type == 2 ? '充值VIP' : '充值书币', 'time_start' => date('YmdHis'), 'time_expire' => date('YmdHis', time() + PayConstants::getPayTimeoutSeconds()), ]; $url = $this->weChatPay->wap($order)->getTargetUrl(); $this->oOrder->payid = $this->getPrePayId($url)->data; $this->oOrder->out_trade_no = $out_trade_no; $this->oOrder->pdorderid = ''; $referral = parse_url($_SERVER['HTTP_REFERER']??''); $redirect = $this->getRedirectUrl()->data; if (empty($referral['query'])) { $url .= '&redirect_url=' . urlencode($redirect); } else { $url .= '?redirect_url=' . urlencode($redirect); } $this->oOrder->pay_json = $url; LogService::debug("wechath5payurl:" . $url); } catch (\Exception $e) { return $this->getExceptionReturn($e); } return $this->setData(['redirect' => $url])->getReturn(); } /** * @param $target * @return \app\main\model\object\ReturnObject */ private function getPrePayId($target) { $url = parse_url($target); $params = \GuzzleHttp\Psr7\parse_query($url['query']); return $this->setData($params['prepay_id'] ?? '')->getReturn(); } }