|
|
|
@ -1,12 +1,11 @@ |
|
|
|
<?php |
|
|
|
|
|
|
|
namespace App\Admin\Extensions\Grid; |
|
|
|
use App\Models\AdminSetting; |
|
|
|
use App\Models\Agent; |
|
|
|
use App\Models\MiniProgramTemplate; |
|
|
|
use App\Models\MiniProgramUploadLog; |
|
|
|
use App\Service\OpenPlatform; |
|
|
|
use Dcat\Admin\Grid\RowAction; |
|
|
|
use EasyWeChat\Factory; |
|
|
|
use EasyWeChat\Kernel\Exceptions\InvalidConfigException; |
|
|
|
use EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Code\Client; |
|
|
|
use GuzzleHttp\Exception\GuzzleException; |
|
|
|
@ -44,30 +43,22 @@ class MiniProgramAuditStatus extends RowAction |
|
|
|
return $this->response()->error('该代理商未注册过小程序,请先注册'); |
|
|
|
} |
|
|
|
|
|
|
|
$template_id = MiniProgramTemplate::max('template_id'); |
|
|
|
$log = MiniProgramUploadLog::where(['agent_id' => $agent->id, 'template_id' => $template_id])->orderBy('id', 'desc')->first(); |
|
|
|
// $template_id = MiniProgramTemplate::max('template_id');
|
|
|
|
$log = MiniProgramUploadLog::where(['agent_id' => $agent->id])->orderBy('id', 'desc')->first(); |
|
|
|
if (!$log) { |
|
|
|
return $this->response()->error('该代理商未上传及发布过最新版本的小程序'); |
|
|
|
} else if (!$log->audit_id){ |
|
|
|
} else if (!$log->audit_id) { |
|
|
|
return $this->response()->error('未找到审核记录audit_id'); |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
$setting = AdminSetting::val(['service_appid', 'service_appsecret', 'service_token', 'service_aeskey']); |
|
|
|
$config = [ |
|
|
|
'app_id' => $setting['service_appid'], |
|
|
|
'secret' => $setting['service_appsecret'], |
|
|
|
'token' => $setting['service_token'], |
|
|
|
'aes_key' => $setting['service_aeskey'], |
|
|
|
]; |
|
|
|
|
|
|
|
$openPlatform = Factory::openPlatform($config); |
|
|
|
$refreshToken = $openPlatform->getAuthorizer($agent->appid)['authorization_info']['authorizer_refresh_token'] ?? null; |
|
|
|
$openPlatform = new OpenPlatform(); |
|
|
|
$refreshToken = $openPlatform->refreshToken($agent->appid); |
|
|
|
if (!$refreshToken) { |
|
|
|
return $this->response()->error('获取refresh_token失败'); |
|
|
|
} |
|
|
|
/** @var Client $code */ |
|
|
|
$code = $openPlatform->miniProgram($agent->appid, $refreshToken)['code'] ?? null; |
|
|
|
$code = $openPlatform->code($agent->appid, $refreshToken); |
|
|
|
if (!$code) { |
|
|
|
return $this->response()->error('获取code失败'); |
|
|
|
} |
|
|
|
@ -85,14 +76,14 @@ class MiniProgramAuditStatus extends RowAction |
|
|
|
//发布结果处理
|
|
|
|
$releaseArr = [-1 => '系统繁忙', 85019 => '没有审核版本', 85020 => '审核状态未满足发布']; |
|
|
|
if (isset($res_release['errcode'], $res_release['errmsg']) && $res_release['errcode'] == 0 && $res_release['errmsg'] == 'ok') { |
|
|
|
return $this->response()->success('审核成功且已发布')->refresh(); |
|
|
|
return $this->response()->success("模板ID {$log->template_id} 的小程序已审核成功且发布")->refresh(); |
|
|
|
} else if (isset($releaseArr[$res_release['errcode']])) { |
|
|
|
return $this->response()->success('审核成功,发布结果为:' . $releaseArr[$res_release['errcode']])->refresh(); |
|
|
|
return $this->response()->warning('审核成功,发布结果为:' . $releaseArr[$res_release['errcode']])->refresh(); |
|
|
|
} else { |
|
|
|
return $this->response()->success('审核成功,失败出错:' . join(',', $res_release))->refresh(); |
|
|
|
return $this->response()->warning('审核成功,但发布出错:' . join(',', $res_release))->refresh(); |
|
|
|
} |
|
|
|
} else if (isset($statusArr[$res['status']])) { |
|
|
|
return $this->response()->success($statusArr[$res['status']])->refresh(); |
|
|
|
return $this->response()->warning($statusArr[$res['status']])->refresh(); |
|
|
|
} else { |
|
|
|
return $this->response()->error($res['reason'] ?? join(',', $res)); |
|
|
|
} |
|
|
|
|