<?php namespace App\Admin\Forms; use Encore\Admin\Widgets\Form; use Illuminate\Http\Request; use AlibabaCloud\Client\AlibabaCloud; use AlibabaCloud\Client\Exception\ClientException; use AlibabaCloud\Client\Exception\ServerException; class RefreshCdn extends Form { /** * The form title. * * @var string */ public $title = '刷新CDN'; /** * Handle the form request. * * @param Request $request * * @return \Illuminate\Http\RedirectResponse */ public function handle(Request $request) { $cdnUrl = $request->post('urls'); if (!$cdnUrl) { admin_error('没有要刷新的CDN地址'); return back(); } $accessKey = 'xxxxx'; $secretKey = 'xxxxx'; // $cdnUrl = array_filter(explode("\n" , $cdnUrl)); AlibabaCloud::accessKeyClient($accessKey, $secretKey) ->regionId('cn-shanghai') // 根据您的地域进行修改 ->asDefaultClient(); try { $result = AlibabaCloud::rpc() ->product('Cdn') ->version('2018-05-10') //固定版本 ->action('RefreshObjectCaches') ->method('POST') ->options([ 'query' => [ 'ObjectPath' => $cdnUrl, ], ]) ->request(); $res = $result->toarray(); if(isset($res['RefreshTaskId'])){ admin_success('操作成功,一分钟后检查是否刷新成功'); }else{ admin_error('操作失败:' . $res['error']); } } catch (ClientException $e) { // 处理客户端异常 admin_error('客户端异常'); } catch (ServerException $e) { // 处理服务端异常 admin_error('服务端异常'); } return back(); } /** * Build a form here. */ public function form() { $this->textarea('urls', __('刷新的地址'))->help('一行一个地址'); } }
标签:cdnUrl,laravel8,admin,res,cdn,刷新,error,RefreshObjectCaches From: https://www.cnblogs.com/zdcblog/p/17750858.html