2019-09-06 23:53:10 +08:00

77 lines
2.5 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace wstmart\common\model;
/**
* ============================================================================
* 基础控业务处理
*/
use think\Model;
use think\Db;
vendor('oss-sdk.autoload');
use OSS\OssClient;
use OSS\Core\OssException;
const OSS_ACCESS_ID = 'LTAIfppBmzIHRPV0';
const OSS_ACCESS_KEY = 'OdsoQBa30zzPC38Jq9EmefbqSgFZnX';
const OSS_ENDPOINT = 'oss-cn-hongkong.aliyuncs.com';
const OSS_BUCKET = 'qlgmall';
const OSS_WEB_SITE = 'img.zgqlg.com.cn';
class Aliyunoss extends Model {
public $ossClient;
private $oss_access_id;
private $oss_access_key;
private $oss_endpoint;
private $oss_bucket;
private $oss_web_site;
public function __construct(){
parent::__construct();
$this->oss_access_id = OSS_ACCESS_ID;
$this->oss_access_key = OSS_ACCESS_KEY;
$this->oss_endpoint = OSS_ENDPOINT;
$this->oss_bucket = OSS_BUCKET;
$this->oss_web_site = OSS_WEB_SITE;
$this->ossClient = new OssClient($this->oss_access_id,$this->oss_access_key,$this->oss_endpoint);
}
/**
* [getInfo 获取图片信息]
* @param [type] $object [oss图片名]
* @return [type] [description]
*/
public function getInfo($object){
$options = array(
//不能 加入这个OssClient::OSS_FILE_DOWNLOAD如果加入会下载下来
// OssClient::OSS_FILE_DOWNLOAD =>'upload/image/2018-06/5b1b478de0a8123.jpg',
OssClient::OSS_PROCESS => "image/info", );
$rs = $this->ossClient->getObject($this->oss_bucket, $object,$options);
return json_decode($rs,true);
die;
}
/**
* [uploadFile 图片上传]
* @param [type] $object [上传后的文件名]
* @param [type] $file [上传前的文件路径]
* @return [type] [description]
*/
public function uploadFile($object,$file){
try{
$this->ossClient->uploadFile($this->oss_bucket, $object,$file);
return true;
}catch(OssException $e){
$e->getMessage();
return false;
}
}
/**
* [del 删除文件]
* @param [type] $object [oss文件名包含路径]
* @return [type] [description]
*/
public function del($object){
try{
$this->ossClient->deleteObject($this->oss_bucket,$object);
}catch(OssException $e){
return $e->getMessage();
}
}
}