Browse Source

oss upload

git 5 years ago
parent
commit
c73339284c
3 changed files with 42 additions and 28 deletions
  1. 41 27
      Home/Lib/Action/CronAction.class.php
  2. 1 1
      czapp
  3. BIN
      uploadimage/gravatar_resize.jpg

+ 41 - 27
Home/Lib/Action/CronAction.class.php

@@ -42,8 +42,8 @@ class CronAction extends Action {
 				}
 			}
 			//生成的本地电子车牌,加入到待上传oss队列
-			$up2ossWait = json_encode(array('LicensePlate' => $licensPlate, 'localPath' => $localPath));
-			$reslut = $plateLocalPath->add($up2ossWait);//push方法没有返回值,用add代替
+			$up2ossWait = json_encode(array('licensePlate' => $licensPlate, 'localPath' => $localPath));
+			$result = $plateLocalPath->add($up2ossWait);//push方法没有返回值,用add代替
 			if(!$result){
 				echo 'plateLocalPath->add() failed,$licensPlate = '.$licensPlate .PHP_EOL;
 				continue;
@@ -56,19 +56,18 @@ class CronAction extends Action {
 	private  function uploadElectronicPlate2Oss(  ){
 		$config = array(
 			'OssDsn' => C('OSS_DSN'),
-			'filePathDir' => '/data/wwwroot/czapp.rltest.cn/1.0.0//uploadimage/',
 			"SaveRule" => "/electronic_plate/{Y}{m}{d}/{uid}.{ext}",
 			"AllowExts" => array('jpg', 'png', 'jpeg'), // 允许上传的文件后缀(留空为不限制)
-			"ResizeImage" => true,   // 是否自动压缩
+			"ResizeImage" => false,   // 是否自动压缩
 			"MaxImageWidth" => 1024,
 			"MaxImageHeight" => 1024,
-			"IsCheckRgb" => true,
+			"IsCheckRgb" => false,
 			"MinImgAverageRgb" => 70
 		);
 		$upload = new \Jms\File\Oss2($config);
 		
 		$start = time();
-		$plateLocalPath = Redis('jyzl_wait_upload2oss_eplate');
+		$plateLocalPath = Redis('jyzl_wait_upload2oss_eplate', 'queue');
 		while( (time() - $start) < 60 ){
 			$data = $plateLocalPath->pop();
 			if(!$data){
@@ -76,51 +75,66 @@ class CronAction extends Action {
 				sleep(1);
 				continue;
 			}
-			
-			$data = json_decode($data, true);
-			
-			if(!$data){
-				echo 'json_decode failed, please check the format of the json data';
-				continue;
-			}
-			
-			$fileName = 'gravatar.jpg';//TEST
-			//$fileName = $data['localPath'];
-			if(!$fileName){
-				echo 'cant get loacl file';
+		
+			//$data = json_decode($data, true);
+			//$fileName = 'gravatar.jpg';//TEST
+			$fileName = $data['localPath'];
+			$licensPlate = $data['licensePlate'];
+			if(!$licensPlate || !$fileName){
+				echo 'cant get right licensPlate or fileName'.PHP_EOL;
+				echo 'fileName:'.$fileName.PHP_EOL;
+				echo 'licensPlate:'.$licensPlate.PHP_EOL;
+				echo '---------------delimiter----------------'.PHP_EOL;
+				
+				$result = $plateLocalPath->add($data);
+				if(!$result){
+					echo 'plateLocalPath->add() failed,$licensPlate = '. $data['licensPlate'] .PHP_EOL;
+					continue;
+				}
+				sleep(1);
 				continue;
 			}
-			
+			//上传至oss
 			$uploadRes = $upload->localFileUpload($fileName);
+			//失败重回队列
 			if(!$uploadRes['success']){
 				echo $uploadRes['message'].PHP_EOL;
-				continue;
+				$result = $plateLocalPath->add($data);
+				if(!$result){
+					echo 'plateLocalPath->add() failed,$licensPlate = '. $data['licensPlate'] .PHP_EOL;
+					continue;
+				}
+			}else{
+				echo 'upload success!'.PHP_EOL;
 			}
+			
 			$frontImageUrl = $uploadRes['objectname'];
 			if(!$frontImageUrl){
 				echo 'cant get img_oss_url';
 				continue;
+			}else{
+				echo 'return oss-url:'.$frontImageUrl.PHP_EOL;
 			}
 			
-			$licensPlate = $data['licensPlate'];
-			if(!$licensPlate)
 		
 			$updateRes = M('jms_vehicle')->where(array('LicensePlate' => $licensPlate))->setField('FrontElectronicPlateUrl',$frontImageUrl);
 			if(!$updateRes){
-				echo 'update failed'.PHP_EOL;
+				echo 'save electricPlate in mysql failed'.PHP_EOL;
 				continue;
+			}else{
+				echo 'save electricPlate in mysql success'.PHP_EOL;
 			}
 			
 			//删除本地图片
-			$filePath = $config['filePathDir'].$filename;
+			$filePath = $filename;
 			if(file_exists(!$filePath)){
 				$flag = unlink($filePath);
 				if(!$flag){
-					echo 'delete localImg failed'.PHP;
+					echo 'delete localImg failed'.PHP_EOL;
+				}else{
+					echo 'delete localImg success'.PHP_EOL;
 				}
 			}
-			
-			
 			sleep(1);
 		}
 		

+ 1 - 1
czapp

@@ -1 +1 @@
-Subproject commit 194cb9269a2c526e5f45e8d2ff16a76a8374b3b5
+Subproject commit a52fb3525b37dfd744aada41834c775dfa3c7200

BIN
uploadimage/gravatar_resize.jpg