error(lang('wepay.missing_order_sn'), url('visa/index')))); } $this->order_sn = $order_sn; } public function wxpay() { $wechaturl = config('app.wechatpay'); $wechaturl .= '?order_sn=' . $this->order_sn . '&mark=' . PAY_MARK . '&body=' . urlencode(COUNTRY . lang('wepay.pay_body')); header('location:' . $wechaturl); exit; } public function pcpay() { $order_sn = $this->order_sn; $response = Httpcurl::request(config('app.GET_ORDER_DETAIL_URL'), 'post', ['order_sn' => $order_sn, 'model' => MODEL]); if ($response[3]) { return $this->error(lang('wepay.system_error'), url('visa/index')); } $pay_result = json_decode($response[0], true); Log::info(json_encode($pay_result)); if (empty($pay_result)) { return $this->error(lang('wepay.system_error'), url('visa/index')); } if (!$pay_result['code']) { return $this->error($pay_result['msg'], url('visa/index')); } $pay_result = $pay_result['data']; if ($pay_result['pay_status']) { return $this->success(lang('wepay.already_paid'), url('visa/index')); } $body = COUNTRY . lang('wepay.pay_body'); $wxurl = ''; $res = Httpcurl::request(config('app.wechatpcpay'), 'get', ['order_sn' => $order_sn, 'mark' => PAY_MARK, 'body' => $body]); if (!$res[3]) { $result = json_decode($res[0], true); $wxurl = $result['url'] ?? ''; } Log::info(json_encode($res)); $aliurl = ''; $res = Httpcurl::request(config('app.alipcpay'), 'get', ['order_sn' => $order_sn, 'mark' => PAY_MARK, 'body' => urlencode($body)]); 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'] ?? 0) / 100, 2)); return View::fetch(); } public function h5pay() { $wechaturl = config('app.wechath5pay'); $wechaturl .= '?order_sn=' . $this->order_sn . '&mark=' . PAY_MARK . '&body=' . urlencode(COUNTRY . lang('wepay.pay_body')); header('location:' . $wechaturl); exit; } public function succ() { /*判断订单状态*/ $order_info = Httpcurl::request(config('app.GET_ORDER_DETAIL_URL'), 'post', ['order_sn' => $this->order_sn, 'model' => MODEL]); $order_info = json_decode($order_info[0], true); if ($order_info['code'] == '0') { return $this->error(lang("controller.order_not_exist")); } $order_info = $order_info['data']; if ($order_info) { if ($order_info['pay_status'] == 0 ) { return $this->success(lang("controller.payment_not_completed"), url('visa/index')); } } /*判断订单状态*/ $arrive_date = $order_info['arrive_date'] ?? '2026-05-30'; $arrive_timestamp = $arrive_date ? strtotime($arrive_date) : false; $latest_submit_timestamp = strtotime(date('Y-m-d') . ' +' . ARRIVE_DATE_COUNT . ' days 23:59:59'); if ($arrive_timestamp === false || $arrive_timestamp < $latest_submit_timestamp) { View::assign('arrive_date_info', ''); } else { $arrive_date_info = sprintf(lang("pay.arrive_date_info"), $arrive_date, date('Y-m-d', $arrive_timestamp - ARRIVE_DATE_COUNT * 86400)); View::assign('arrive_date_info', $arrive_date_info); } View::assign('payment_confirmed', true); View::assign('poll_status_url', ''); View::assign('repay_url', ''); View::assign('order_sn', $this->order_sn); return View::fetch(); } public function h5result() { if (!Request::instance()->isAjax()) { return View::fetch(); } return $this->checkPayStatus('h5pay'); } public function pcresult() { if (!Request::instance()->isAjax()) { return null; } return $this->checkPayStatus('pcpay'); } private function checkPayStatus(string $retryAction) { $order_sn = $this->order_sn; $response = Httpcurl::request(config('app.GET_ORDER_DETAIL_URL'), 'post', ['order_sn' => $order_sn, 'model' => MODEL]); if ($response[3]) { return json([ 'status' => 0, 'msg' => lang('wepay.system_error'), 'url' => url('wepay/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' => lang('wepay.system_error'), 'url' => url('wepay/index', ['order_sn' => $order_sn])->build(), ]); } if (!$pay_result['code']) { return json([ 'status' => 0, 'msg' => $pay_result['msg'], 'url' => url('wepay/index', ['order_sn' => $order_sn])->build(), ]); } $pay_result = $pay_result['data']; if ($pay_result['pay_status']) { return json([ 'status' => 1, 'msg' => lang('wepay.payment_success'), 'url' => url('wepay/succ', ['order_sn' => $order_sn])->build(), ]); } return json([ 'status' => 0, 'msg' => lang('wepay.payment_not_completed'), 'url' => url('wepay/' . $retryAction, ['order_sn' => $order_sn])->build(), ]); } }