$config['token_endtime'])) { AlibabaCloud::accessKeyClient($config['appkey'], $config['appsecret'])->regionId($region)->asDefaultClient(); //设置参数,发起请求。 try { $result = AlibabaCloud::rpc() ->product('Sts') ->scheme('https') // https | http ->version('2015-04-01') ->action('AssumeRole') ->method('POST') ->host('sts.aliyuncs.com') ->options([ 'query' => [ 'RegionId' => $region, 'RoleArn' => "acs:ram::1118875946432366:role/api", 'RoleArn' => $config['role_arn'], 'RoleSessionName' => "upload", ], ]) ->request(); $data = $result->toArray(); if (isset($data['Credentials']['SecurityToken'])) { $token = $data['Credentials']['SecurityToken']; $endtime = $data['Credentials']['Expiration']; $appkey = $data['Credentials']['AccessKeyId']; $appsecret = $data['Credentials']['AccessKeySecret']; $token = $token . '||' . $appkey . '||' . $appsecret; $up['token'] = $token; $up['token_endtime'] = Dever::maketime($endtime) - 60; $up['where_id'] = $config['id']; Dever::db('upload/yun')->update($up); } else { echo 'oss token获取失败,请检查配置';die; } } catch (ClientException $e) { echo $e->getErrorMessage() . PHP_EOL;die; } catch (ServerException $e) { echo $e->getErrorMessage() . PHP_EOL;die; } } else { $token = $config['token']; } return array('oss', $token, $region, $upload['bucket']); } # 连接 public function connect($config, $upload, $file = '') { $accessKey = $config['appkey']; $secretKey = $config['appsecret']; $endpoint = "http://oss-cn-".$config['region_id'].".aliyuncs.com"; list($type, $token, $domain, $bucket) = $this->token($config, $upload, $file); $data = explode('||', $token); if ($data[0]) { $token = $data[0]; $accessKey = $data[1]; $secretKey = $data[2]; } else { $token = false; } $this->client = new OssClient($accessKey, $secretKey, $endpoint, false, $token); return $this; } # 上传文件 public function upload($bucket, $file, $source_file, $options = array(), $base64 = false) { if (!$this->client) { return array(); } $method = 'uploadFile'; if ($base64) { $method = 'putObject'; } $ret = $this->client->$method($bucket, $file, $source_file, $options); return $ret; } # 删除文件 public function delete($bucket, $file) { $this->client = new \Qiniu\Storage\BucketManager($this->auth); $result = $this->client->delete($bucket, $file); return $result; } # 下载文件 public function download($bucket, $file, $local = false) { if (!$this->client) { return false; } if ($local) { $options = array( OssClient::OSS_FILE_DOWNLOAD => $local ); } else { $options = array(); } $content = $this->client->getObject($bucket, $file, $options); return $content; } public function callback() { $body = file_get_contents('php://input'); Dever::log($body, 'oss_callback'); $body = json_decode($body, true); return $body; } # 视频转码 public function convert($key, $file, $config, $upload) { //?x-oss-process=video/snapshot,t_7000,f_jpg,w_800,h_600,m_fast //t以后是毫秒 } # 视频截图 public function cover($key, $video, $num = 1) { $num = $num * 1000; $file = $video . '?x-oss-process=video/snapshot,t_'.$num.',f_jpg,m_fast'; if ($local == 1) { $data = Dever::load('upload/save')->copy($file, 7, false, false, 'jpg'); return $data['url'] . '?time=' . time(); } else { return $file; } //x-oss-process=video/snapshot,t_1000,f_jpg,m_fast } }