This commit is contained in:
gaofeng
2026-09-01 11:07:13 +08:00
parent f6f37310ce
commit e0aeff2af7
18 changed files with 577 additions and 6 deletions

View File

@@ -5,6 +5,7 @@ namespace app\miniapi\controller;
use app\miniapi\service\Product\AppCatalogService;
use app\miniapi\service\Product\ProductService;
use app\miniapi\service\AppUpdateService;
use think\facade\Config;
class AppCatalog extends Base
@@ -13,6 +14,7 @@ class AppCatalog extends Base
{
$site = (array)Config::get('app.miniapi_site', []);
$config = (array)Config::get('mini_app_catalog', []);
$updateService = new AppUpdateService();
return $this->ok([
'brand' => [
@@ -32,9 +34,27 @@ class AppCatalog extends Base
],
'features' => ['visa_catalog' => true],
'upload_limits' => (array)($config['upload_limits'] ?? []),
'android_update' => $updateService->bootstrap(
(array)($config['android_update'] ?? []),
(string)$this->request->get('channel', 'official'),
),
]);
}
public function update()
{
$config = (array)Config::get('mini_app_catalog.android_update', []);
$target = (new AppUpdateService())->storeTarget(
$config,
(string)$this->request->get('channel', 'official'),
);
if ($target === '') {
return $this->fail('该渠道更新地址尚未配置', 404);
}
return redirect($target);
}
public function home()
{
$catalog = $this->catalog();

View File

@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace app\miniapi\controller;
use app\miniapi\service\EvusCorrection\EvusCorrectionService;
final class EvusCorrection extends Base
{
public function detail()
{
$userId = $this->requireLogin();
if (!is_int($userId)) {
return $userId;
}
$orderSn = trim((string)$this->request->param('order_sn', ''));
if ($orderSn === '') {
return $this->fail('参数错误');
}
$result = (new EvusCorrectionService())->detail($userId, $orderSn);
if ((int)($result['code'] ?? 0) !== 1) {
return $this->fail((string)($result['msg'] ?? '服务异常,请稍后重试'));
}
return $this->ok((array)($result['data'] ?? []));
}
public function submit()
{
$userId = $this->requireLogin();
if (!is_int($userId)) {
return $userId;
}
$params = $this->postData();
if (trim((string)($params['order_sn'] ?? '')) === '') {
return $this->fail('参数错误');
}
$result = (new EvusCorrectionService())->submit($userId, $params);
if ((int)($result['code'] ?? 0) !== 1) {
return $this->fail((string)($result['msg'] ?? '提交失败,请稍后重试'));
}
return $this->ok((array)($result['data'] ?? []), '提交成功');
}
}

View File

@@ -11,7 +11,7 @@ class Upload extends Base
{
$scene = strtolower(trim((string)$this->request->post('scene', '')));
$contactUserId = 0;
if (in_array($scene, ['passport', 'id_card'], true)) {
if (in_array($scene, ['passport', 'id_card', 'evus_correction'], true)) {
$login = $this->requireLogin();
if (!is_int($login)) {
return $login;
@@ -55,9 +55,13 @@ class Upload extends Base
}
$fileName = date('YmdHis') . uniqid('', true) . '.' . $ext;
$objectKey = $contactUserId > 0
? 'contact/' . $contactUserId . '/' . $fileName
: $fileName;
if ($scene === 'evus_correction') {
$objectKey = 'evus-correction/' . $contactUserId . '/' . $fileName;
} elseif ($contactUserId > 0) {
$objectKey = 'contact/' . $contactUserId . '/' . $fileName;
} else {
$objectKey = $fileName;
}
try {
$client = SwooleService::getInstance();

View File

@@ -6,6 +6,7 @@ Route::pattern(['product_id' => '[A-Za-z0-9_-]+']);
Route::group('app', function () {
Route::get('bootstrap', 'AppCatalog/bootstrap');
Route::get('update', 'AppCatalog/update');
Route::get('home', 'AppCatalog/home');
Route::get('visas/:product_id/schema', 'AppCatalog/schema');
Route::get('visas/:product_id', 'AppCatalog/detail');

View File

@@ -0,0 +1,60 @@
<?php
declare(strict_types=1);
namespace app\miniapi\service;
final class AppUpdateService
{
private const CHANNELS = ['official', 'huawei', 'xiaomi', 'oppo', 'vivo', 'tencent'];
public function normalizeChannel(string $value): string
{
$channel = strtolower(trim($value));
return in_array($channel, self::CHANNELS, true) ? $channel : 'official';
}
public function bootstrap(array $config, string $requestedChannel): array
{
$channel = $this->normalizeChannel($requestedChannel);
$gateway = $this->safeHttpsUrl((string)($config['gateway_url'] ?? ''));
return [
'latest_version_code' => max(0, (int)($config['latest_version_code'] ?? 0)),
'latest_version_name' => trim((string)($config['latest_version_name'] ?? '')),
'minimum_version_code' => max(0, (int)($config['minimum_version_code'] ?? 0)),
'download_url' => $gateway === '' ? '' : $gateway . (str_contains($gateway, '?') ? '&' : '?') . http_build_query(
['channel' => $channel],
'',
'&',
PHP_QUERY_RFC3986,
),
'changelog' => trim((string)($config['changelog'] ?? '')),
'force_update' => filter_var($config['force_update'] ?? false, FILTER_VALIDATE_BOOLEAN),
];
}
public function storeTarget(array $config, string $requestedChannel): string
{
$channel = $this->normalizeChannel($requestedChannel);
$urls = (array)($config['store_urls'] ?? []);
$target = $this->safeHttpsUrl((string)($urls[$channel] ?? ''));
if ($target !== '') {
return $target;
}
return $this->safeHttpsUrl((string)($urls['official'] ?? $config['fallback_url'] ?? ''));
}
private function safeHttpsUrl(string $value): string
{
$url = trim($value);
if ($url === '' || filter_var($url, FILTER_VALIDATE_URL) === false) {
return '';
}
$parts = parse_url($url);
if (($parts['scheme'] ?? '') !== 'https' || empty($parts['host']) || isset($parts['user'])) {
return '';
}
return $url;
}
}

View File

@@ -0,0 +1,64 @@
<?php
declare(strict_types=1);
namespace app\miniapi\service\EvusCorrection;
use api\Httpcurl;
use think\facade\Log;
final class EvusCorrectionService
{
public function detail(int $userId, string $orderSn): array
{
return $this->request('detail', $userId, ['order_sn' => $orderSn]);
}
public function submit(int $userId, array $params): array
{
return $this->request('submit', $userId, $params);
}
public function payload(int $userId, array $params = []): array
{
unset($params['user_id']);
return ['user_id' => $userId] + $params;
}
public function endpoint(string $userUrl, string $action): string
{
if (!in_array($action, ['detail', 'submit'], true)) {
return '';
}
$userUrl = rtrim(trim($userUrl), '/');
$endpoint = preg_replace(
'#/users/[^/?]+(?:\?.*)?$#i',
'/evus_correction/' . $action,
$userUrl
);
return is_string($endpoint) && $endpoint !== $userUrl ? $endpoint : '';
}
private function request(string $action, int $userId, array $params): array
{
$url = $this->endpoint((string)config('app.user_url'), $action);
if ($url === '') {
return ['code' => 0, 'msg' => 'EVUS资料服务地址异常', 'data' => []];
}
$response = Httpcurl::request($url, 'post', $this->payload($userId, $params));
if (!is_array($response) || !isset($response[0]) || !empty($response[3])) {
Log::error('miniapi evus correction ' . $action . ' request failed');
return ['code' => 0, 'msg' => '服务异常,请稍后重试', 'data' => []];
}
$result = json_decode($response[0], true);
if (!is_array($result)) {
Log::error('miniapi evus correction ' . $action . ' response decode failed');
return ['code' => 0, 'msg' => '服务异常,请稍后重试', 'data' => []];
}
return $result;
}
}

View File

@@ -93,8 +93,9 @@ class LegalDocumentService
{
$companyName = $company['company_name'] ?: 'EVUS登记服务';
$siteUrl = $this->siteUrl((string)($company['site_domain'] ?? ''));
$phone = $company['phone'] ?: '请通过小程序客服入口联系我们';
$phone = $company['phone'] ?: '请通过应用内客服入口联系我们';
$intro = $this->replaceTokens((string)($document['intro_template'] ?? ''), $company, $siteUrl, $phone);
$append = $this->replaceTokens((string)($document['append_content'] ?? ''), $company, $siteUrl, $phone);
$subjectLabel = trim((string)($document['subject_label'] ?? '服务主体'));
$prefix = [
@@ -108,7 +109,7 @@ class LegalDocumentService
return trim((string)$line) !== '';
}));
return implode("\n", $prefix) . "\n\n" . $body;
return implode("\n", $prefix) . "\n\n" . $body . ($append !== '' ? "\n\n" . $append : '');
}
private function replaceTokens(string $text, array $company, string $siteUrl, string $phone): string