|  | @@ -11,6 +11,8 @@ use AlibabaCloud\Client\Exception\ClientException;
 | 
	
		
			
				|  |  |  use AlibabaCloud\Client\Exception\ServerException;
 | 
	
		
			
				|  |  |  class Oss
 | 
	
		
			
				|  |  |  {
 | 
	
		
			
				|  |  | +    private $client;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      public function token($config, $upload)
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  |          $region = 'cn-' . $config['region_id'];
 | 
	
	
		
			
				|  | @@ -66,6 +68,62 @@ class Oss
 | 
	
		
			
				|  |  |          return array('oss', $token, $region, $upload['bucket']);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    # 连接
 | 
	
		
			
				|  |  | +    public function connect($config, $upload)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        $accessKey = $config['appkey'];
 | 
	
		
			
				|  |  | +        $secretKey = $config['appsecret'];
 | 
	
		
			
				|  |  | +        $endpoint = "http://oss-cn-".$config['region_id'].".aliyuncs.com";
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        list($type, $token, $domain, $bucket) = $this->token($config, $upload);
 | 
	
		
			
				|  |  | +        $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 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');
 |