合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
``` 安装 composer require aliyuncs/oss-sdk-php ``` 上传: ``` <?php namespace lib; use OSS\OssClient; use OSS\Core\OssException; class Oss{ public function __construct(){ //阿里云oss文件存储器的key值 $this->accessKeyId= "LTAI4FjYKDcDG2SAfV57mByp"; //阿里云oss文件存储器的Secret密匙 $this->accessKeySecret= "7nqUiC36Zm2FDQxhN6EbkMzApjYkKV"; //阿里云oss文件存储器存储空间名称。 //$this->bucket= "faka-info"; //阿里云oss文件存储器存网址。 $this->endpoint= "http://oss-cn-beijing.aliyuncs.com"; } public function upload($object,$filePath,$type){ // $object 文件名称; // $filePath php中的图片缓存路径 if($type==1){ $this->bucket= "faka-app"; }else{ $this->bucket= "faka-img"; } $ossClient = new OssClient($this->accessKeyId, $this->accessKeySecret, $this->endpoint); try{ $result=$ossClient->uploadFile($this->bucket,$object,$filePath); return $result['info']['url']; } catch(OssException $e) { return $e->getMessage(); } } } ``` 单文件查询与删除 ``` //公共阿里oss public function my_oss(){ $accessKeyId = ""; $accessKeySecret = ""; $endpoint = "http://oss-cn-beijing.aliyuncs.com"; return new \OSS\OssClient($accessKeyId,$accessKeySecret,$endpoint); } //私签oss清除 public function private_oss_one_clear(){ $appid=input('appid'); $udid = openssl_decrypt(input('udid'), 'des-ecb', 'bailitys'); $private_supersign=db('private_supersign')->where('id',$appid)->field('uid,shorturl')->find(); $iosid=db('private_udid')->where(['udid'=>$udid,'appid'=>$appid,'userid'=>$private_supersign['uid']])->order('id DESC')->value('iosid'); if(empty($appid) || empty($udid)){ return myjson(0,'参数错误',$private_supersign['shorturl']); } if(empty($iosid)){ return myjson(0,'未安装过',$private_supersign['shorturl']); } $ossClient = $this->my_oss(); $bucket_ipa="private-vipsignipa"; $bucket_plist="private-vipsignplist"; $object_find='copy/'.$private_supersign['uid'].'/'.$iosid.'/'.$appid.$iosid.$udid; $exist_ipa= $ossClient->doesObjectExist($bucket_ipa,$object_find.'sign.ipa'); $exist_plist= $ossClient->doesObjectExist($bucket_plist,$object_find.'.plist'); if($exist_ipa==false || $exist_plist==false){ return myjson(0,'无需修复',$private_supersign['shorturl']); } try{ $ossClient->deleteObject($bucket_ipa,$object_find.'sign.ipa'); $ossClient->deleteObject($bucket_plist,$object_find.'.plist'); } catch(OssException $e){ return myjson(0,'oss删除失败',$private_supersign['shorturl']); } return myjson(200,'修复成功',$private_supersign['shorturl']); } ``` 多文件查询与删除 ``` public function supersign_oss($appid){ $ossClient = $this->my_oss(); $bucket_ipa="private-vipsignipa-1"; $bucket_plist="private-vipsignplist-1"; $object_find='supersign/'.$appid.'/'; $object_ipa=$this->oss_list_file($object_find,$bucket_ipa,$ossClient); $object_plist=$this->oss_list_file($object_find,$bucket_plist,$ossClient); if(empty($object_ipa) || empty($object_plist)){ echo myjson(0,'修复失败,请联系管理员2');die; } try{ $ossClient->deleteObjects($bucket_ipa,$object_ipa); $ossClient->deleteObjects($bucket_plist,$object_plist); } catch(OssException $e){ echo myjson(0,'修复失败,请联系管理员3');die; } return true; } //公共阿里oss public function my_oss(){ $accessKeyId = ""; $accessKeySecret = ""; $endpoint = "http://oss-cn-beijing.aliyuncs.com"; return new \OSS\OssClient($accessKeyId,$accessKeySecret,$endpoint); } //查询oss是否存在该文件--列表 public function oss_list_file($object,$bucket,$ossClient){ $options =['marker' => $object,'prefix' => $object]; try{ $listObjectInfo = $ossClient->listObjects($bucket,$options); }catch (OssException $e){ echo myjson(0,'修复失败,请联系管理员4');die; } $listObject = $listObjectInfo->getObjectList(); $array=[]; if (!empty($listObject)) { foreach ($listObject as $objectInfo) { array_push($array,$objectInfo->getKey()) ; } } return $array; } ``` 3.其他 有公开和私有两种模式,选择公开; 浏览器打开会直接下载,html标签中会正常显示