180 lines
5.8 KiB
PHP
Executable File
180 lines
5.8 KiB
PHP
Executable File
<?php
|
||
|
||
namespace App\Http\Controllers;
|
||
|
||
|
||
use App\Enums\AppType;
|
||
use App\Enums\ClientIOSState;
|
||
use App\Enums\ClientIOSType;
|
||
use App\Jobs\IOSGenerateIpa;
|
||
use App\Model\Apps;
|
||
use App\Model\ClientIos;
|
||
use App\Utils\Helps;
|
||
use Illuminate\Http\Request;
|
||
use Illuminate\Support\Facades\Log;
|
||
|
||
class ClientController extends Controller
|
||
{
|
||
|
||
public function iosInstall(Request $request)
|
||
{
|
||
$install = $request->input('install');
|
||
header('Location: ' . $install, true, 302);
|
||
}
|
||
public function appDownload(Request $request)
|
||
{
|
||
Log::error('appdowload:', [
|
||
'all' => $request->all(),
|
||
'ua' => $request->userAgent()
|
||
]);
|
||
$type = $request->input('type');
|
||
$download = $request->input('download');
|
||
$custom = $request->input('custom');
|
||
if ($type == ClientIOSType::SELLER) {
|
||
$version = Apps::sellerAndroidVersion();
|
||
$android = Helps::appSellerUrl($version,AppType::ANDROID);
|
||
|
||
// $ios = 'https://file.daxiangzj.com/client/mobileconfig_seller';
|
||
$iosUrl = Helps::appIOSSellerUrl();
|
||
$ios = $iosUrl;
|
||
// $ios = 'itms-services://?action=download-manifest&url='.urlencode($iosUrl);
|
||
// $ios = 'https://seller.daxiangzj.com/#/login';
|
||
} else {
|
||
$version = Apps::buyerAndroidVersion();
|
||
$android = Helps::appBuyerUrl($version,AppType::ANDROID);
|
||
// $ios = 'https://file.daxiangzj.com/client/mobileconfig_buyer';
|
||
|
||
$iosUrl = Helps::appIOSBuyerUrl();
|
||
$ios = $iosUrl;
|
||
// $ios = 'itms-services://?action=download-manifest&url='.urlencode($iosUrl);
|
||
// $ios = 'https://buyer.daxiangzj.com/#/login';
|
||
}
|
||
|
||
if ($custom) {
|
||
return view('client.custom_iosdownload', [
|
||
'android_link' => $android,
|
||
'ios_link' => $ios,
|
||
]);
|
||
}
|
||
|
||
return view('client.app_download', [
|
||
'android_link' => $android,
|
||
'ios_link' => $ios,
|
||
]);
|
||
}
|
||
|
||
public function mobileconfigBuyer(Request $request)
|
||
{
|
||
$config = public_path('apps/ios/plist/buyer/udid.sign.mobileconfig');
|
||
|
||
$content = file_get_contents($config);
|
||
return response($content)
|
||
->withHeaders([
|
||
'Content-type' => 'application/x-apple-aspen-config; chatset=utf-8',
|
||
'Content-Disposition' => 'attachment; filename="buyer.sign.udid.mobileconfig"'
|
||
]);
|
||
}
|
||
|
||
public function mobileconfigSeller(Request $request)
|
||
{
|
||
$config = public_path('apps/ios/plist/seller/udid.sign.mobileconfig');
|
||
|
||
$content = file_get_contents($config);
|
||
return response($content)
|
||
->withHeaders([
|
||
'Content-type' => 'application/x-apple-aspen-config; chatset=utf-8',
|
||
'Content-Disposition' => 'attachment; filename="buyer.sign.udid.mobileconfig"'
|
||
]);
|
||
}
|
||
|
||
/**
|
||
* 获取设备的udid,并等待ipa生成,下载ipa
|
||
* @param Request $request
|
||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||
*/
|
||
public function udidBuyer(Request $request)
|
||
{
|
||
$udid = $request->input('UDID');
|
||
if (!$udid) {
|
||
return view('client.ios_buyer_down', [
|
||
'openid' => ''
|
||
]);
|
||
}
|
||
$ios = ClientIos::where('type', ClientIOSType::BUYER)
|
||
->where('udid', $udid)
|
||
->first();
|
||
|
||
if (!$ios) {
|
||
$ios = new ClientIos();
|
||
$ios->udid = $udid;
|
||
$ios->type = ClientIOSType::BUYER;
|
||
$ios->state = ClientIOSState::RECEIVED;
|
||
$ios->created_date = date('Ymd');
|
||
$ios->openid = md5($udid. '-' . $ios->type);
|
||
$ios->save();
|
||
IOSGenerateIpa::dispatch($ios->id);
|
||
}
|
||
return view('client.ios_buyer_down', [
|
||
'openid' => $ios->openid
|
||
]);
|
||
}
|
||
|
||
public function udidSeller(Request $request)
|
||
{
|
||
$udid = $request->input('UDID');
|
||
if (!$udid) {
|
||
return view('client.ios_seller_down', [
|
||
'openid' => ''
|
||
]);
|
||
}
|
||
$ios = ClientIos::where('type', ClientIOSType::SELLER)
|
||
->where('udid', $udid)
|
||
->first();
|
||
if (!$ios) {
|
||
$ios = new ClientIos();
|
||
$ios->udid = $udid;
|
||
$ios->state = ClientIOSState::RECEIVED;
|
||
$ios->created_date = date('Ymd');
|
||
$ios->type = ClientIOSType::SELLER;
|
||
$ios->openid = md5($udid. '-' . $ios->type);
|
||
$ios->save();
|
||
IOSGenerateIpa::dispatch($ios->id);
|
||
}
|
||
return view('client.ios_seller_down', [
|
||
'openid' => $ios->openid
|
||
]);
|
||
}
|
||
|
||
public function ipaBuild(Request $request)
|
||
{
|
||
$openId = $request->input('openid');
|
||
$client = ClientIos::where('openid', $openId)->first();
|
||
if (!$client) {
|
||
return $this->jsonFailed('设备不存在');
|
||
}
|
||
|
||
if ($client->state == ClientIOSState::SUCCESS) {
|
||
|
||
if ($client->type == ClientIOSType::BUYER) {
|
||
$ios = Helps::appIOSBuyerUrl();
|
||
$url = 'itms-services://?action=download-manifest&url='.urlencode($ios);
|
||
} else {
|
||
$ios = Helps::appIOSSellerUrl();
|
||
$url = 'itms-services://?action=download-manifest&url='.urlencode($ios);
|
||
}
|
||
return $this->jsonSuccess([
|
||
'url' => $url,
|
||
'message' => '',
|
||
]);
|
||
}
|
||
|
||
if ($client->state != ClientIOSState::PENDING) {
|
||
Log::error('安装ipa失败', $client->toArray());
|
||
}
|
||
return $this->jsonSuccess([
|
||
'url' => '',
|
||
'message' => '正在为您准备安装包,请稍后!',
|
||
]);
|
||
}
|
||
}
|