order_no = $order_no; $this->money = $money; $this->remark = $remark; $this->notify_url = $notify_url; try { $result = $this->addOrder('wechatLiteH5'); $code_url = $result['payurl']; } catch (\Exception $e) { return $this->error('微信支付下单失败!' . $e->getMessage()); } return $this->success('微信支付下单成功!', [ 'type' => 'qrcode', 'page' => 'wxpay_h5', 'url' => $code_url ]); } /** * 统一下单 * @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); } }