jingcai-php/app/Jobs/IOSGenerateIpa.php

127 lines
4.0 KiB
PHP
Executable File

<?php
namespace App\Jobs;
use App\Enums\ClientIOSState;
use App\Enums\ClientIOSType;
use App\Model\ClientIos;
use App\Utils\Helps;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
class IOSGenerateIpa implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $clientIOSId;
public function __construct($clientIOSId)
{
$this->clientIOSId = $clientIOSId;
$this->queue = config('queue.names.ios_generate_ipa');
}
public function handle()
{
Log::info('IOSGenerateIpa::start, clientIOSId:' . $this->clientIOSId);
$client = ClientIos::find($this->clientIOSId);
if (!$client) {
Log::error('IOSGenerateIpa id not exit', [
'client_ios_id' => $this->clientIOSId
]);
return;
}
if ($client->state == ClientIOSState::SUCCESS) {
Log::info('IOSGenerateIpa id is successed', [
'client_ios_id' => $this->clientIOSId
]);
return;
}
if ($client->state == ClientIOSState::PENDING) {
Log::info('IOSGenerateIpa id is pending', [
'client_ios_id' => $this->clientIOSId
]);
return;
}
$client->state = ClientIOSState::PENDING;
$client->save();
$udid = $client->udid;
$outIpaPemPath = base_path('scripts/sign/ipas/'.date('Ymd'));
if (!file_exists($outIpaPemPath)) {
mkdir($outIpaPemPath,0777, true);
}
$udidType = $udid . '-' . $client->type;
$provPath = $outIpaPemPath . '/'. $udidType . '.prov';
$certfPath = $outIpaPemPath . '/'. $udidType . '.certf';
if ($client->type == ClientIOSType::BUYER) {
$realIpaPath = Helps::ipaBuyerPath();
$appBundleId = 'com.pingco.daxiangzj';
} else {
$realIpaPath = Helps::ipaSellerPath();
$appBundleId = 'com.pingco.yunduoxd';
}
$shellPath = base_path('scripts/sign');
putenv('LANG=en_US.UTF-8');
$shell = "$shellPath/run.sh $appBundleId hanbin@pingco.com Zhang121748 2R4737WLD7 $udid $shellPath/CertificateSigningRequest.certSigningRequest $provPath $certfPath";
exec($shell,$output, $outcode);
if ($outcode != 0) {
Log::error('生成profile文件失败', [
'code' => $outcode,
'error' => $output,
'udid' => $udid,
'shell' => $shell,
]);
$client->state = ClientIOSState::FAIL_PROV;
$client->save();
return;
}
$shellOutIpaPath = $outIpaPemPath . '/' . $udidType. '.ipa';
$shellIpa = "/usr/bin/zsign -k $shellPath/kefen.pem -p yunduoxd -m $provPath -o $shellOutIpaPath -z 9 $realIpaPath 2>&1";
exec($shellIpa,$outputIpa, $outCodeIpa);
if ($outCodeIpa != 0) {
Log::error('签名ipa文件失败', [
'code' => $outCodeIpa,
'error' => $outputIpa,
'udid' => $udid,
'shell' => $shellIpa,
]);
$client->state = ClientIOSState::FAIL_IPA;
$client->save();
return;
}
$shellMv = "mv -f $shellOutIpaPath $realIpaPath";
exec($shellMv,$outputMv, $outCodeMv);
if ($outCodeMv != 0) {
Log::error('签名ipa文件失败', [
'code' => $outCodeMv,
'error' => $outputMv,
'udid' => $udid,
'shell' => $shellMv,
]);
$client->state = ClientIOSState::FAIL_MV;
$client->save();
return;
}
$client->state = ClientIOSState::SUCCESS;
$client->save();
Log::info('IOSGenerateIpa:: ipa build succeess~~~~~~~~~~~');
}
}