order_sn = Request::instance()->param('order_sn', ''); if (empty($this->order_sn)) { throw new HttpResponseException(Response::create($this->error('缺少订单号,请重新填写', url('esta/index')))); } } public function index() { if (isMobile()) { if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) { return redirect(url('payesta/wxpay', ['order_sn' => $this->order_sn])->build()); } return redirect(url('payesta/h5pay', ['order_sn' => $this->order_sn])->build()); } return redirect(url('payesta/pcpay', ['order_sn' => $this->order_sn])->build()); } /** * 跳到微信支付 */ public function wxpay() { $wechaturl = config('app.wechatpay'); $wechaturl .= '?order_sn=' . $this->order_sn . '&mark=' . PAY_ESTA_MARK . '&body=' . urlencode(ESTA_COUNTRY . '服务费'); header('location:' . $wechaturl); // 跳转到 user/profile exit; } /** * 跳转到pc支付 */ public function pcpay() { $order_sn = $this->order_sn; //判断支付是否已完成 $order_url = config('app.get_order_detail_url'); $response = Httpcurl::request($order_url, 'post', ['order_sn' => $order_sn, 'model' => ESTA_MODEL]); if ($response[3]) { return $this->error("异常错误,请重新提交", url('detail/index')); } $pay_result = json_decode($response[0], true); Log::info(json_encode($pay_result)); if (empty($pay_result)) { return $this->error("异常错误,请重新提交", url('detail/index')); } if (!$pay_result['code']) { return $this->error($pay_result['msg'], url('detail/index')); } $pay_result = $pay_result['data']; if ($pay_result['pay_status']) { return $this->success('您已支付成功,请勿重复支付', url('detail/index')); } //微信pc $cfg = config('app.wechatpcpay'); $res = Httpcurl::request($cfg, 'get', array('order_sn' => $order_sn, 'mark' => PAY_ESTA_MARK, 'body' => ESTA_COUNTRY . '服务费')); $wxurl = ""; if (!$res[3]) { $result = json_decode($res[0], true); $wxurl = $result['url']; } Log::info(json_encode($res)); //支付宝pc $cfg = config('app.alipcpay'); $res = Httpcurl::request($cfg, 'get', array('order_sn' => $order_sn, 'mark' => PAY_ESTA_MARK, 'body' => urlencode(ESTA_COUNTRY . '服务费'))); $aliurl = ""; if (!$res[3]) { $result = json_decode($res[0], true); $aliurl = $result['url']; } Log::info(json_encode($res)); View::assign('url', $wxurl); View::assign('aliurl', $aliurl); View::assign('order_sn', $order_sn); View::assign('total_fee', number_format($pay_result['total_price'] / 100, 2)); return View::fetch(); } /** * 跳转到H5支付 */ public function h5pay() { $wechaturl = config('app.wechath5pay'); $wechaturl .= '?order_sn=' . $this->order_sn . '&mark=' . PAY_ESTA_MARK . '&body=' . urlencode(ESTA_COUNTRY . '服务费'); header('location:' . $wechaturl); // 跳转到 user/profile exit; } public function succ() { $order_sn = $this->order_sn; View::assign('order_sn', $order_sn); return View::fetch(); } /** * h5支付结果页面 */ public function h5result() { if (Request::instance()->isAjax()) { $order_sn = $this->order_sn; if (!$order_sn) { return json([ 'status' => 0, 'msg' => '订单号不存在,请重新支付', 'url' => url('payesta/index', ['order_sn' => $order_sn])->build() ]); } $order_url = config('app.get_order_detail_url'); $response = Httpcurl::request($order_url, 'post', ['order_sn' => $order_sn, 'model' => ESTA_MODEL]); if ($response[3]) { return json([ 'status' => 0, 'msg' => '异常错误,请重新提交', 'url' => url('payesta/index', ['order_sn' => $order_sn])->build() ]); } $pay_result = json_decode($response[0], true); Log::info(json_encode($pay_result)); if (empty($pay_result)) { return json([ 'status' => 0, 'msg' => '异常错误,请重新提交', 'url' => url('payesta/index', ['order_sn' => $order_sn])->build() ]); } if (!$pay_result['code']) { return json([ 'status' => 0, 'msg' => $pay_result['msg'], 'url' => url('payesta/index', ['order_sn' => $order_sn])->build() ]); } $pay_result = $pay_result['data']; if ($pay_result['pay_status']) { return json([ 'status' => 1, 'msg' => '支付成功', 'url' => url('payesta/succ', ['order_sn' => $order_sn])->build() ]); } return json([ 'status' => 0, 'msg' => '您还未支付,请重新支付', 'url' => url('payesta/h5pay', ['order_sn' => $order_sn])->build() ]); } return View::fetch(); } /** * pc支付结果页面 */ public function pcresult() { if (Request::instance()->isAjax()) { $order_sn = $this->order_sn; if (!$order_sn) { return json([ 'status' => 0, 'msg' => '订单号不存在,请重新支付', 'url' => url('payesta/index', ['order_sn' => $order_sn])->build() ]); } $order_url = config('app.get_order_detail_url'); $response = Httpcurl::request($order_url, 'post', ['order_sn' => $order_sn, 'model' => ESTA_MODEL]); if ($response[3]) { return json([ 'status' => 0, 'msg' => '异常错误,请重新提交', 'url' => url('payesta/index', ['order_sn' => $order_sn])->build() ]); } $pay_result = json_decode($response[0], true); Log::info(json_encode($pay_result)); if (empty($pay_result)) { return json([ 'status' => 0, 'msg' => '异常错误,请重新提交', 'url' => url('payesta/index', ['order_sn' => $order_sn])->build() ]); } if (!$pay_result['code']) { return json([ 'status' => 0, 'msg' => $pay_result['msg'], 'url' => url('payesta/index', ['order_sn' => $order_sn])->build() ]); } $pay_result = $pay_result['data']; if ($pay_result['pay_status']) { return json([ 'status' => 1, 'msg' => '支付成功', 'url' => url('payesta/succ', ['order_sn' => $order_sn])->build() ]); } return json([ 'status' => 0, 'msg' => '您还未支付,请重新支付', 'url' => url('payesta/pcpay', ['order_sn' => $order_sn])->build() ]); } } }