| 
					
				 | 
			
			
				@@ -11,45 +11,69 @@ use AlibabaCloud\Client\Exception\ClientException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 use AlibabaCloud\Client\Exception\ServerException;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 class Oss
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	public function token($config, $upload)
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public function token($config, $upload)
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    	//构建一个阿里云客户端,用于发起请求。
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		//构建阿里云客户端时需要设置AccessKey ID和AccessKey Secret。
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		AlibabaCloud::accessKeyClient($config['appkey'], $config['appsecret'])->regionId('cn-beijing')->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' => "cn-beijing",
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                              'RoleArn' => "acs:ram::1118875946432366:role/api",
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                              'RoleSessionName' => "upload",
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            ],
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        ])
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-              ->request();
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		    print_r($result->toArray());die;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		} catch (ClientException $e) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		    echo $e->getErrorMessage() . PHP_EOL;die;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		} catch (ServerException $e) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		    echo $e->getErrorMessage() . PHP_EOL;die;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		}
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return array('oss', '', '');
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $region = 'cn-' . $config['region_id'];
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (!$config['role_arn']) {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return array('oss', '||' . $config['appkey'] . '||' . $config['appsecret'], $region);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $cur = time();
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (!$config['token'] || ($config['token_endtime'] && $cur > $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);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public function callback()
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	{
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		$body = file_get_contents('php://input');
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		Dever::log($body, 'oss_callback');
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		$body = json_decode($body, true);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  	{
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  		$body = file_get_contents('php://input');
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  		Dever::log($body, 'oss_callback');
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  		$body = json_decode($body, true);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		return $body;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	}
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  		return $body;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  	}
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	# 视频转码
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public function convert($key, $file, $config, $upload)
 
			 |