|
|
|
@ -10,6 +10,7 @@ use Dcat\Admin\Grid\RowAction; |
|
|
|
use EasyWeChat\Factory; |
|
|
|
use EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Code\Client; |
|
|
|
use Illuminate\Http\Request; |
|
|
|
use Illuminate\Support\Facades\Redis; |
|
|
|
use Illuminate\Support\Facades\Storage; |
|
|
|
|
|
|
|
/** |
|
|
|
@ -63,24 +64,6 @@ class MiniProgramUpload extends RowAction |
|
|
|
} |
|
|
|
$miniProgram = $openPlatform->miniProgram($agent->appid, $refreshToken); |
|
|
|
|
|
|
|
//设置域名
|
|
|
|
/** @var \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Domain\Client $domain */ |
|
|
|
$domain = $miniProgram['domain']; |
|
|
|
|
|
|
|
$host = env('APP_URL'); |
|
|
|
$param = [ |
|
|
|
"action" => "add", |
|
|
|
"requestdomain" => [$host], |
|
|
|
"wsrequestdomain" => [str_replace('http', 'ws', $host)], |
|
|
|
"uploaddomain" => [$host], |
|
|
|
"downloaddomain" => [$host], |
|
|
|
]; |
|
|
|
$domain->modify($param); //服务器域名,服务器域名多次设置仅第一次成功,这里不校验返回结果正确性
|
|
|
|
$res = $domain->setWebviewDomain([$host]); //业务域名
|
|
|
|
if (!isset($res['errcode'], $res['errmsg']) || $res['errcode'] != 0 || $res['errmsg'] != 'ok') { |
|
|
|
throw new \Exception("设置业务域名{$host}失败,原因:" . $res['errmsg'] ?? (is_array($res) ? join(',', $res) : '未知')); |
|
|
|
} |
|
|
|
|
|
|
|
/** @var Client $code */ |
|
|
|
$code = $miniProgram['code'] ?? null; |
|
|
|
if (!$code) { |
|
|
|
@ -117,9 +100,34 @@ class MiniProgramUpload extends RowAction |
|
|
|
'created_at' => now(), |
|
|
|
]); |
|
|
|
|
|
|
|
//获取体验二维码并保存
|
|
|
|
//获取体验二维码并保存,30天内只获取一次
|
|
|
|
$qrcode_path = Storage::path("mini_program_qrcode/{$agent->id}-{$agent->appid}-demo.jpg"); |
|
|
|
if (!file_exists($qrcode_path) || time() - filemtime($qrcode_path) < 86400 * 30) { |
|
|
|
$qrcode = $code->getQrCode(); |
|
|
|
Storage::put("public/$filename", $qrcode); |
|
|
|
} |
|
|
|
|
|
|
|
//设置域名,如果之前已经设置过了将记录下来,不再设置
|
|
|
|
$host = env('APP_URL'); |
|
|
|
$redis_key = 'mini_program_set_host:' . $host; |
|
|
|
if (!Redis::hget($redis_key, $agent->appid)) { |
|
|
|
/** @var \EasyWeChat\OpenPlatform\Authorizer\MiniProgram\Domain\Client $domain */ |
|
|
|
$domain = $miniProgram['domain']; |
|
|
|
|
|
|
|
$param = [ |
|
|
|
"action" => "add", |
|
|
|
"requestdomain" => [$host], |
|
|
|
"wsrequestdomain" => [str_replace('http', 'ws', $host)], |
|
|
|
"uploaddomain" => [$host], |
|
|
|
"downloaddomain" => [$host], |
|
|
|
]; |
|
|
|
$domain->modify($param); //服务器域名,服务器域名多次设置仅第一次成功,这里不校验返回结果正确性
|
|
|
|
$res = $domain->setWebviewDomain([$host]); //业务域名
|
|
|
|
if (!isset($res['errcode'], $res['errmsg']) || $res['errcode'] != 0 || $res['errmsg'] != 'ok') { |
|
|
|
throw new \Exception("设置业务域名{$host}失败,原因:" . $res['errmsg'] ?? (is_array($res) ? join(',', $res) : '未知')); |
|
|
|
} |
|
|
|
Redis::hset($redis_key, 1); |
|
|
|
} |
|
|
|
|
|
|
|
return $this->response()->success("上传成功,并已提交审核")->refresh(); |
|
|
|
} else if (isset($audit_err_code[$res['errcode']])) { |
|
|
|
|