223 lines
11 KiB
PHP
223 lines
11 KiB
PHP
<?php
|
|
|
|
namespace app\home\controller;
|
|
|
|
use api\Httpcurl;
|
|
use think\facade\Cookie;
|
|
use think\facade\Request;
|
|
use think\facade\Session;
|
|
use think\facade\View;
|
|
use think\facade\Log;
|
|
|
|
class Esta extends Base
|
|
{
|
|
|
|
public function index()
|
|
{
|
|
$methods = (new \app\service\PaymentSelectionService((array) config('app.payment_methods', [])))
|
|
->methods((string) ($_SERVER['HTTP_USER_AGENT'] ?? ''));
|
|
View::assign('payment_methods', $methods);
|
|
View::assign('payment_methods_configured', (bool) config('app.payment_methods_configured', false));
|
|
View::assign('payment_english', \think\facade\Lang::getLangSet() === 'en-us');
|
|
View::assign('country_list', json_decode(file_get_contents('./json/country.json'), true));
|
|
View::assign('phone_prefix', json_decode(file_get_contents('./json/phone_prefix.json'), true));
|
|
View::assign('us', json_decode(file_get_contents('./json/us.json'), true));
|
|
View::assign('goods', config('app.ESTA_GOODS'));
|
|
View::assign('ismobile', isMobile() ? 1 : 0);
|
|
View::assign('ppt_sample_url', BASE_PATH . '/new/assets/images/shili.jpg');
|
|
View::assign('per_sample_url', BASE_PATH . '/new/assets/images/persion2.png');
|
|
return View::fetch();
|
|
}
|
|
|
|
public function do_apply()
|
|
{
|
|
$paymentConfigured = (bool) config('app.payment_methods_configured', false);
|
|
$paymentMethod = '';
|
|
if ($paymentConfigured) {
|
|
try {
|
|
$paymentMethod = (new \app\service\PaymentSelectionService((array) config('app.payment_methods', [])))
|
|
->select($_REQUEST['payment_method'] ?? '', (string) ($_SERVER['HTTP_USER_AGENT'] ?? ''));
|
|
} catch (\InvalidArgumentException $e) {
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
unset($_REQUEST['payment_method']);
|
|
unset($_REQUEST['s']);
|
|
unset($_REQUEST['file']);
|
|
$order_sn = $_REQUEST['order_sn'] = getOrderNumber();
|
|
$total_price = $_REQUEST['total_price'];
|
|
/*判断价格是否正确*/
|
|
$config_price = array_map(function($item) {
|
|
return $item['value'];
|
|
}, config('app.ESTA_GOODS'));
|
|
if (!in_array($total_price, $config_price)) {
|
|
return $this->error('价格错误');
|
|
}
|
|
/*判断价格是否正确*/
|
|
|
|
$_REQUEST['birth_date_day'] = (string)date_parse($_REQUEST['birth_date'])['day'] ?:'0';
|
|
$_REQUEST['birth_date_month'] = (string)date_parse($_REQUEST['birth_date'])['month'] ?:'0';
|
|
$_REQUEST['birth_date_year'] = (string)date_parse($_REQUEST['birth_date'])['year'] ?:'0';
|
|
|
|
$_REQUEST['passport_expedition_date_day'] = (string)date_parse($_REQUEST['passport_expedition_date'])['day'] ?:'';
|
|
$_REQUEST['passport_expedition_date_month'] = (string)date_parse($_REQUEST['passport_expedition_date'])['month'] ?:'';
|
|
$_REQUEST['passport_expedition_date_year'] = (string)date_parse($_REQUEST['passport_expedition_date'])['year'] ?:'';
|
|
|
|
$_REQUEST['passport_expiration_date_day'] = (string)date_parse($_REQUEST['passport_expiration_date'])['day'] ?:'';
|
|
$_REQUEST['passport_expiration_date_month'] = (string)date_parse($_REQUEST['passport_expiration_date'])['month'] ?:'';
|
|
$_REQUEST['passport_expiration_date_year'] = (string)date_parse($_REQUEST['passport_expiration_date'])['year'] ?:'';
|
|
|
|
$_REQUEST['other_country_date_day'] = (string)date_parse($_REQUEST['other_country_date'])['day'] ?:'';
|
|
$_REQUEST['other_country_date_month'] = (string)date_parse($_REQUEST['other_country_date'])['month'] ?:'';
|
|
$_REQUEST['other_country_date_year'] = (string)date_parse($_REQUEST['other_country_date'])['year'] ?:'';
|
|
unset($_REQUEST['other_country_date']);
|
|
|
|
$_REQUEST['other_country_edate_day'] = (string)date_parse($_REQUEST['other_country_edate'])['day'] ?:'';
|
|
$_REQUEST['other_country_edate_month'] = (string)date_parse($_REQUEST['other_country_edate'])['month'] ?:'';
|
|
$_REQUEST['other_country_edate_year'] = (string)date_parse($_REQUEST['other_country_edate'])['year'] ?:'';
|
|
unset($_REQUEST['other_country_edate']);
|
|
|
|
$_REQUEST['ip'] = getIP();
|
|
$_REQUEST['source'] = Session::get('source' );
|
|
$_REQUEST['total_price'] = $total_price;
|
|
$_REQUEST['model'] = ESTA_MODEL;
|
|
$_REQUEST['token'] = md5(ESTA_MODEL);
|
|
$_REQUEST['other_country_acquired_other'] = isset($_REQUEST['other_country_acquired_other']) ? $_REQUEST['other_country_acquired_other'] : '';
|
|
|
|
|
|
$order_res = Httpcurl::request(CREATE_ORDER_URL, 'post', $_REQUEST);
|
|
Log::info(json_encode($order_res));
|
|
$order = json_decode($order_res[0], true);
|
|
if (!$order['code']) {
|
|
return $this->error("提交失败,请联系管理员!");
|
|
}
|
|
if (!$paymentConfigured) {
|
|
return $this->success('操作成功', url('home/payesta/index', ['order_sn' => $order_sn])->build());
|
|
}
|
|
return $this->success('操作成功', url('home/payesta/checkout', ['order_sn' => $order_sn, 'payment_method' => $paymentMethod])->build(), [
|
|
'open_new_tab' => !isMobile() && $paymentMethod === 'alipay',
|
|
]);
|
|
}
|
|
public function wxmini()
|
|
{
|
|
$openid = input('openid');
|
|
if (empty($openid)) {
|
|
return $this->error('请先授权登录');
|
|
}
|
|
$user_id = input('user_id');
|
|
if (empty($user_id)) {
|
|
return $this->error('请先授权登录');
|
|
}
|
|
$price = input('price');
|
|
$price = $price * 100;
|
|
/*判断价格是否正确*/
|
|
$config_price = array_map(function($item) {
|
|
return $item['value'];
|
|
}, config('app.ESTA_GOODS'));
|
|
if (!in_array($price, $config_price)) {
|
|
return $this->error('价格错误');
|
|
}
|
|
View::assign('openid', $openid);
|
|
View::assign('user_id', $user_id);
|
|
View::assign('price', $price);
|
|
View::assign('country_list', json_decode(file_get_contents('./json/country.json'), true));
|
|
View::assign('phone_prefix', json_decode(file_get_contents('./json/phone_prefix.json'), true));
|
|
View::assign('us', json_decode(file_get_contents('./json/us.json'), true));
|
|
View::assign('goods', config('app.ESTA_GOODS'));
|
|
View::assign('ismobile', isMobile() ? 1 : 0);
|
|
View::assign('ppt_sample_url', BASE_PATH . '/new/assets/images/shili.jpg');
|
|
View::assign('per_sample_url', BASE_PATH . '/new/assets/images/persion2.png');
|
|
return View::fetch();
|
|
|
|
}
|
|
public function applymini()
|
|
{
|
|
$openid = input('openid');
|
|
if (empty($openid)) {
|
|
return $this->error('请先授权登录');
|
|
}
|
|
$user_id = input('user_id');
|
|
if (empty($user_id)) {
|
|
return $this->error('请先授权登录');
|
|
}
|
|
$user_id = authcode($user_id);
|
|
if (!is_numeric($user_id)) {
|
|
return $this->error('请先授权登录');
|
|
}
|
|
unset($_REQUEST['s']);
|
|
unset($_REQUEST['openid']);
|
|
unset($_REQUEST['file']);
|
|
$order_sn = $_REQUEST['order_sn'] = getOrderNumber();
|
|
$total_price = $_REQUEST['total_price'];
|
|
/*判断价格是否正确*/
|
|
$config_price = array_map(function($item) {
|
|
return $item['value'];
|
|
}, config('app.ESTA_GOODS'));
|
|
if (!in_array($total_price, $config_price)) {
|
|
return $this->error('价格错误');
|
|
}
|
|
$_REQUEST['birth_date_day'] = (string)date_parse($_REQUEST['birth_date'])['day'] ?:'0';
|
|
$_REQUEST['birth_date_month'] = (string)date_parse($_REQUEST['birth_date'])['month'] ?:'0';
|
|
$_REQUEST['birth_date_year'] = (string)date_parse($_REQUEST['birth_date'])['year'] ?:'0';
|
|
|
|
$_REQUEST['passport_expedition_date_day'] = (string)date_parse($_REQUEST['passport_expedition_date'])['day'] ?:'';
|
|
$_REQUEST['passport_expedition_date_month'] = (string)date_parse($_REQUEST['passport_expedition_date'])['month'] ?:'';
|
|
$_REQUEST['passport_expedition_date_year'] = (string)date_parse($_REQUEST['passport_expedition_date'])['year'] ?:'';
|
|
|
|
$_REQUEST['passport_expiration_date_day'] = (string)date_parse($_REQUEST['passport_expiration_date'])['day'] ?:'';
|
|
$_REQUEST['passport_expiration_date_month'] = (string)date_parse($_REQUEST['passport_expiration_date'])['month'] ?:'';
|
|
$_REQUEST['passport_expiration_date_year'] = (string)date_parse($_REQUEST['passport_expiration_date'])['year'] ?:'';
|
|
|
|
$_REQUEST['other_country_date_day'] = (string)date_parse($_REQUEST['other_country_date'])['day'] ?:'';
|
|
$_REQUEST['other_country_date_month'] = (string)date_parse($_REQUEST['other_country_date'])['month'] ?:'';
|
|
$_REQUEST['other_country_date_year'] = (string)date_parse($_REQUEST['other_country_date'])['year'] ?:'';
|
|
unset($_REQUEST['other_country_date']);
|
|
|
|
$_REQUEST['other_country_edate_day'] = (string)date_parse($_REQUEST['other_country_edate'])['day'] ?:'';
|
|
$_REQUEST['other_country_edate_month'] = (string)date_parse($_REQUEST['other_country_edate'])['month'] ?:'';
|
|
$_REQUEST['other_country_edate_year'] = (string)date_parse($_REQUEST['other_country_edate'])['year'] ?:'';
|
|
unset($_REQUEST['other_country_edate']);
|
|
|
|
$_REQUEST['ip'] = getIP();
|
|
$_REQUEST['source'] = 'qlwxmini';
|
|
$_REQUEST['total_price'] = $total_price;
|
|
$_REQUEST['model'] = ESTA_MODEL;
|
|
$_REQUEST['token'] = md5(ESTA_MODEL);
|
|
$_REQUEST['other_country_acquired_other'] = isset($_REQUEST['other_country_acquired_other']) ? $_REQUEST['other_country_acquired_other'] : '';
|
|
|
|
|
|
$order_res = Httpcurl::request(CREATE_ORDER_URL, 'post', $_REQUEST);
|
|
$order = json_decode($order_res[0], true);
|
|
if (!$order['code']) {
|
|
return $this->error("提交失败,请联系管理员!");
|
|
}
|
|
$order_url = 'https://pay.qlevisa.com/home/pay/miniwxevuspay';
|
|
$response = Httpcurl::request($order_url, 'post', ['order_sn' => $order_sn, 'body' => 'esta登记签证服务费', 'money' => $total_price, 'openid' => $openid, 'attach' => 'esta']);
|
|
if ($response[3]) {
|
|
return json([
|
|
'code' => 0,
|
|
'msg' => '异常错误,请重新提交',
|
|
]);
|
|
}
|
|
$pay_result = json_decode($response[0], true);
|
|
if (empty($pay_result)) {
|
|
return json([
|
|
'code' => 0,
|
|
'msg' => '异常错误,请重新提交',
|
|
]);
|
|
}
|
|
if ($pay_result['code'] !== 200) {
|
|
return json([
|
|
'code' => 0,
|
|
'msg' => $pay_result['msg'],
|
|
]);
|
|
}
|
|
$pay_result['data']['package'] = urlencode($pay_result['data']['package']);
|
|
return json([
|
|
'code' => 1,
|
|
'msg' => '提交成功',
|
|
'data' => $pay_result['data']
|
|
]);
|
|
}
|
|
}
|