@@ -104,10 +104,12 @@ discard block |
||
| 104 | 104 | ); |
| 105 | 105 | $client->putObjectByContent($args); |
| 106 | 106 | |
| 107 | - if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy"))) |
|
| 108 | - $client->deleteObject(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy")); |
|
| 109 | - if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction"))) |
|
| 110 | - $client->deleteObject(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction")); |
|
| 107 | + if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy"))) { |
|
| 108 | + $client->deleteObject(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy")); |
|
| 109 | + } |
|
| 110 | + if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction"))) { |
|
| 111 | + $client->deleteObject(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction")); |
|
| 112 | + } |
|
| 111 | 113 | |
| 112 | 114 | $copyReq = array( |
| 113 | 115 | "Bucket"=>$bucket, |
@@ -119,18 +121,22 @@ discard block |
||
| 119 | 121 | ); |
| 120 | 122 | $client->copyObject($copyReq); |
| 121 | 123 | |
| 122 | - if(!$client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy"))) |
|
| 123 | - throw new Exception("not found ".$keyprefix."EOFileCopy"); |
|
| 124 | - if(!$client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction"))) |
|
| 125 | - throw new Exception("not found ".$keyprefix."EOFileCopy.instruction"); |
|
| 124 | + if(!$client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy"))) { |
|
| 125 | + throw new Exception("not found ".$keyprefix."EOFileCopy"); |
|
| 126 | + } |
|
| 127 | + if(!$client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction"))) { |
|
| 128 | + throw new Exception("not found ".$keyprefix."EOFileCopy.instruction"); |
|
| 129 | + } |
|
| 126 | 130 | |
| 127 | 131 | $client->deleteObject(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy")); |
| 128 | 132 | |
| 129 | - if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy"))) |
|
| 130 | - throw new Exception("found ".$keyprefix."EOFileCopy"); |
|
| 131 | - if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction"))) |
|
| 132 | - throw new Exception("found ".$keyprefix."EOFileCopy.instruction"); |
|
| 133 | -} |
|
| 133 | + if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy"))) { |
|
| 134 | + throw new Exception("found ".$keyprefix."EOFileCopy"); |
|
| 135 | + } |
|
| 136 | + if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction"))) { |
|
| 137 | + throw new Exception("found ".$keyprefix."EOFileCopy.instruction"); |
|
| 138 | + } |
|
| 139 | + } |
|
| 134 | 140 | function rangeGetAndCheckMd5($client,$bucket,$key,$file,$expectedMd5){ |
| 135 | 141 | $args = array("Bucket"=>$bucket,"Key"=>$key); |
| 136 | 142 | $meta = $client->getObjectMeta($args); |
@@ -164,7 +170,8 @@ discard block |
||
| 164 | 170 | @unlink($value); |
| 165 | 171 | } |
| 166 | 172 | $md5 = base64_encode(md5_file($file)); |
| 167 | - if($md5 != $expectedMd5) |
|
| 168 | - throw new Exception("file md5 check error expected ".$expectedMd5." ,actual ".$md5, 1); |
|
| 173 | + if($md5 != $expectedMd5) { |
|
| 174 | + throw new Exception("file md5 check error expected ".$expectedMd5." ,actual ".$md5, 1); |
|
| 175 | + } |
|
| 169 | 176 | @unlink($file); |
| 170 | 177 | } |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | public static function getKeyEncryptionAlgm($encryptionMaterials){ |
| 40 | 40 | if(is_array($encryptionMaterials)){ |
| 41 | 41 | return "RSA"; |
| 42 | - }else{ |
|
| 42 | + } else{ |
|
| 43 | 43 | return "AES"; |
| 44 | 44 | } |
| 45 | 45 | } |
@@ -47,8 +47,9 @@ discard block |
||
| 47 | 47 | $a = $range["start"]; |
| 48 | 48 | $b = $range["end"]; |
| 49 | 49 | $a = $a - ($a%$blocksize)-$blocksize; |
| 50 | - if($a < 0) |
|
| 51 | - $a = 0; |
|
| 50 | + if($a < 0) { |
|
| 51 | + $a = 0; |
|
| 52 | + } |
|
| 52 | 53 | |
| 53 | 54 | $b = $b+$blocksize-$b%$blocksize+$blocksize; |
| 54 | 55 | |
@@ -59,13 +60,15 @@ discard block |
||
| 59 | 60 | if($encrypKeyAlg === "AES"){ |
| 60 | 61 | $secretKey = $encryptionMaterials; |
| 61 | 62 | $encryptedSek = EncryptionUtil::encode_AES_ECB($cek,$secretKey); |
| 62 | - if(empty($encryptedSek)) |
|
| 63 | - throw new Ks3ClientException("can not encode cek useing AES"); |
|
| 64 | - }else if($encrypKeyAlg === "RSA"){ |
|
| 63 | + if(empty($encryptedSek)) { |
|
| 64 | + throw new Ks3ClientException("can not encode cek useing AES"); |
|
| 65 | + } |
|
| 66 | + } else if($encrypKeyAlg === "RSA"){ |
|
| 65 | 67 | $encryptedSek = ""; |
| 66 | 68 | openssl_public_encrypt($cek,$encryptedSek, $encryptionMaterials[0]); |
| 67 | - if(empty($encryptedSek)) |
|
| 68 | - throw new Ks3ClientException("can not encode cek useing RSA"); |
|
| 69 | + if(empty($encryptedSek)) { |
|
| 70 | + throw new Ks3ClientException("can not encode cek useing RSA"); |
|
| 71 | + } |
|
| 69 | 72 | } |
| 70 | 73 | return $encryptedSek; |
| 71 | 74 | } |
@@ -74,13 +77,15 @@ discard block |
||
| 74 | 77 | if($encrypKeyAlg === "AES"){ |
| 75 | 78 | $secretKey = $encryptionMaterials; |
| 76 | 79 | $cek = EncryptionUtil::decode_AES_ECB($cekEncrypted,$secretKey); |
| 77 | - if(empty($cek)) |
|
| 78 | - throw new Ks3ClientException("can not decode cek useing AES,secret key maybe not correct"); |
|
| 79 | - }else if($encrypKeyAlg === "RSA"){ |
|
| 80 | + if(empty($cek)) { |
|
| 81 | + throw new Ks3ClientException("can not decode cek useing AES,secret key maybe not correct"); |
|
| 82 | + } |
|
| 83 | + } else if($encrypKeyAlg === "RSA"){ |
|
| 80 | 84 | $cek = ""; |
| 81 | 85 | openssl_private_decrypt($cekEncrypted,$cek, $encryptionMaterials[1]); |
| 82 | - if(empty($cek)) |
|
| 83 | - throw new Ks3ClientException("can not decode cek useing RSA,public/private key pair maybe not correct"); |
|
| 86 | + if(empty($cek)) { |
|
| 87 | + throw new Ks3ClientException("can not decode cek useing RSA,public/private key pair maybe not correct"); |
|
| 88 | + } |
|
| 84 | 89 | } |
| 85 | 90 | return $cek; |
| 86 | 91 | } |
@@ -97,39 +102,42 @@ discard block |
||
| 97 | 102 | return $data; |
| 98 | 103 | } |
| 99 | 104 | public static function updateContentMD5Header($req){ |
| 100 | - if(!is_array($req)) |
|
| 101 | - return $req; |
|
| 105 | + if(!is_array($req)) { |
|
| 106 | + return $req; |
|
| 107 | + } |
|
| 102 | 108 | if(isset($req["ObjectMeta"])){ |
| 103 | 109 | $meta = $req["ObjectMeta"]; |
| 104 | - }else{ |
|
| 110 | + } else{ |
|
| 105 | 111 | return $req; |
| 106 | 112 | } |
| 107 | 113 | if(is_array($meta) && isset($meta["Content-MD5"])){ |
| 108 | 114 | $md5 = $meta["Content-MD5"]; |
| 109 | - }else{ |
|
| 115 | + } else{ |
|
| 110 | 116 | return $req; |
| 111 | 117 | } |
| 112 | 118 | if(empty($md5)){ |
| 113 | 119 | return $req; |
| 114 | - }else{ |
|
| 120 | + } else{ |
|
| 115 | 121 | $req["ObjectMeta"]["Content-MD5"] = NULL; |
| 116 | 122 | $req["UserMeta"]["x-kss-meta-x-kss-unencrypted-content-md5"] = $md5; |
| 117 | 123 | } |
| 118 | 124 | return $req; |
| 119 | 125 | } |
| 120 | 126 | public static function metaTextLength($req){ |
| 121 | - if(!is_array($req)) |
|
| 122 | - return -1; |
|
| 127 | + if(!is_array($req)) { |
|
| 128 | + return -1; |
|
| 129 | + } |
|
| 123 | 130 | if(isset($req["ObjectMeta"])){ |
| 124 | 131 | $meta = $req["ObjectMeta"]; |
| 125 | - }else{ |
|
| 132 | + } else{ |
|
| 126 | 133 | return -1; |
| 127 | 134 | } |
| 128 | 135 | if(is_array($meta) && isset($meta["Content-Length"])){ |
| 129 | 136 | $length = $meta["Content-Length"]; |
| 130 | 137 | return $length; |
| 131 | - }else |
|
| 132 | - return -1; |
|
| 138 | + } else { |
|
| 139 | + return -1; |
|
| 140 | + } |
|
| 133 | 141 | } |
| 134 | 142 | public static function plainTextLength($args){ |
| 135 | 143 | if(isset($args["Content"])){ |
@@ -146,11 +154,12 @@ discard block |
||
| 146 | 154 | if(Utils::chk_chinese($content)&&!Utils::check_char($content)){ |
| 147 | 155 | $content = iconv('utf-8','gbk',$content); |
| 148 | 156 | } |
| 149 | - if(!file_exists($content)) |
|
| 150 | - throw new Ks3ClientException("the specified file does not exist "); |
|
| 157 | + if(!file_exists($content)) { |
|
| 158 | + throw new Ks3ClientException("the specified file does not exist "); |
|
| 159 | + } |
|
| 151 | 160 | $length = Utils::getFileSize($content); |
| 152 | 161 | $content = fopen($content,"r"); |
| 153 | - }else{ |
|
| 162 | + } else{ |
|
| 154 | 163 | $stats = fstat($content); |
| 155 | 164 | if ($stats && $stats["size"] >= 0){ |
| 156 | 165 | $length = $stats["size"]; |
@@ -160,10 +169,11 @@ discard block |
||
| 160 | 169 | //优先取用户设置seek_position,没有的话取ftell |
| 161 | 170 | if(isset($args["Content"]["seek_position"])&&$args["Content"]["seek_position"]>0){ |
| 162 | 171 | $seek_position = $args["Content"]["seek_position"]; |
| 163 | - }else if(!$isFile){ |
|
| 172 | + } else if(!$isFile){ |
|
| 164 | 173 | $seek_position = ftell($content); |
| 165 | - if($seek_position<0) |
|
| 166 | - $seek_position = 0; |
|
| 174 | + if($seek_position<0) { |
|
| 175 | + $seek_position = 0; |
|
| 176 | + } |
|
| 167 | 177 | fseek($content,0); |
| 168 | 178 | } |
| 169 | 179 | |
@@ -173,21 +183,23 @@ discard block |
||
| 173 | 183 | } |
| 174 | 184 | if($lengthInMeta > 0){ |
| 175 | 185 | $length = $lengthInMeta; |
| 176 | - }else if($resourceLength > 0){ |
|
| 186 | + } else if($resourceLength > 0){ |
|
| 177 | 187 | //根据seek_position计算实际长度 |
| 178 | 188 | $length = $resourceLength - $seek_position; |
| 179 | 189 | } |
| 180 | - if($length <= 0) |
|
| 181 | - throw new Ks3ClientException("calculate content length failed,unexpected contetn length ".$length); |
|
| 190 | + if($length <= 0) { |
|
| 191 | + throw new Ks3ClientException("calculate content length failed,unexpected contetn length ".$length); |
|
| 192 | + } |
|
| 182 | 193 | return $length; |
| 183 | - }else{ |
|
| 194 | + } else{ |
|
| 184 | 195 | $content = $args["Content"]; |
| 185 | 196 | $lengthInMeta = EncryptionUtil::metaTextLength($args); |
| 186 | 197 | $length = strlen($content); |
| 187 | - if($length<$lengthInMeta||$lengthInMeta <= 0) |
|
| 188 | - return $length; |
|
| 189 | - else |
|
| 190 | - return $lengthInMeta; |
|
| 198 | + if($length<$lengthInMeta||$lengthInMeta <= 0) { |
|
| 199 | + return $length; |
|
| 200 | + } else { |
|
| 201 | + return $lengthInMeta; |
|
| 202 | + } |
|
| 191 | 203 | } |
| 192 | 204 | } |
| 193 | 205 | return -1; |
@@ -195,10 +207,12 @@ discard block |
||
| 195 | 207 | public static function initMultipartUploadContext($initResult,$iv,$cek,$encryptedCek,$matdesc="{}"){ |
| 196 | 208 | $cacheDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR; |
| 197 | 209 | $encryptionDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR; |
| 198 | - if(!is_dir($cacheDir)) |
|
| 199 | - mkdir($cacheDir); |
|
| 200 | - if(!is_dir($encryptionDir)) |
|
| 201 | - mkdir($encryptionDir); |
|
| 210 | + if(!is_dir($cacheDir)) { |
|
| 211 | + mkdir($cacheDir); |
|
| 212 | + } |
|
| 213 | + if(!is_dir($encryptionDir)) { |
|
| 214 | + mkdir($encryptionDir); |
|
| 215 | + } |
|
| 202 | 216 | if(is_array($matdesc)){ |
| 203 | 217 | $matdesc = json_encode($matdesc); |
| 204 | 218 | } |
@@ -225,8 +239,9 @@ discard block |
||
| 225 | 239 | } |
| 226 | 240 | public static function getMultipartUploadContext($UploadId){ |
| 227 | 241 | $encryptionDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR; |
| 228 | - if(!EncryptionUtil::multipartUploadContextExists($UploadId)) |
|
| 229 | - throw new Ks3ClientException("can not found multipart upload context in cache dir"); |
|
| 242 | + if(!EncryptionUtil::multipartUploadContextExists($UploadId)) { |
|
| 243 | + throw new Ks3ClientException("can not found multipart upload context in cache dir"); |
|
| 244 | + } |
|
| 230 | 245 | $jsonString = file_get_contents($encryptionDir.$UploadId); |
| 231 | 246 | $arry = json_decode($jsonString,TRUE); |
| 232 | 247 | return $arry; |
@@ -241,10 +256,11 @@ discard block |
||
| 241 | 256 | } |
| 242 | 257 | public static function openfile($path,$mode){ |
| 243 | 258 | $file = fopen($path, $mode); |
| 244 | - if($file) |
|
| 245 | - return $file; |
|
| 246 | - else |
|
| 247 | - throw new Ks3ClientException("open file ".$path." error"); |
|
| 259 | + if($file) { |
|
| 260 | + return $file; |
|
| 261 | + } else { |
|
| 262 | + throw new Ks3ClientException("open file ".$path." error"); |
|
| 263 | + } |
|
| 248 | 264 | } |
| 249 | 265 | //matdesc为字符串或array数据类型。 |
| 250 | 266 | public static function createInstructionFile($bucket,$key,$cek,$iv,$matdesc="{}"){ |
@@ -271,8 +287,9 @@ discard block |
||
| 271 | 287 | } |
| 272 | 288 | public static function isInstructionFile($s3Object){ |
| 273 | 289 | $meta = $s3Object["Meta"]; |
| 274 | - if(isset($meta["UserMeta"]["x-kss-meta-x-kss-crypto-instr-file"])) |
|
| 275 | - return TRUE; |
|
| 290 | + if(isset($meta["UserMeta"]["x-kss-meta-x-kss-crypto-instr-file"])) { |
|
| 291 | + return TRUE; |
|
| 292 | + } |
|
| 276 | 293 | return FALSE; |
| 277 | 294 | } |
| 278 | 295 | } |
@@ -22,17 +22,19 @@ discard block |
||
| 22 | 22 | $sek = EncryptionUtil::genereateOnceUsedKey(); |
| 23 | 23 | $encryptedSek = EncryptionUtil::encodeCek($this->encryptionMaterials,$sek); |
| 24 | 24 | $content = $args["Content"]; |
| 25 | - if(empty($content)) |
|
| 26 | - throw new Ks3ClientException("please specifie Content in request args"); |
|
| 25 | + if(empty($content)) { |
|
| 26 | + throw new Ks3ClientException("please specifie Content in request args"); |
|
| 27 | + } |
|
| 27 | 28 | $metaContentLength = EncryptionUtil::metaTextLength($args); |
| 28 | 29 | $plainTextLength = strlen($content); |
| 29 | 30 | if($metaContentLength > 0 && $metaContentLength < $plainTextLength){ |
| 30 | 31 | $plainTextLength = $metaContentLength; |
| 31 | 32 | } |
| 32 | - if($plainTextLength > 0) |
|
| 33 | - $args["UserMeta"]["x-kss-meta-x-kss-unencrypted-content-length"] = $plainTextLength; |
|
| 34 | - else |
|
| 35 | - throw new Ks3ClientException("unexpected content length ".$plainTextLength); |
|
| 33 | + if($plainTextLength > 0) { |
|
| 34 | + $args["UserMeta"]["x-kss-meta-x-kss-unencrypted-content-length"] = $plainTextLength; |
|
| 35 | + } else { |
|
| 36 | + throw new Ks3ClientException("unexpected content length ".$plainTextLength); |
|
| 37 | + } |
|
| 36 | 38 | |
| 37 | 39 | $content = substr($content, 0,$plainTextLength); |
| 38 | 40 | |
@@ -73,8 +75,9 @@ discard block |
||
| 73 | 75 | $encryptedSek = EncryptionUtil::encodeCek($this->encryptionMaterials,$sek); |
| 74 | 76 | if(!isset($args["Content"])||!is_array($args["Content"]) |
| 75 | 77 | ||!isset($args["Content"]["content"]) |
| 76 | - ||empty($args["Content"]["content"])) |
|
| 77 | - throw new Ks3ClientException("please specifie file content in request args"); |
|
| 78 | + ||empty($args["Content"]["content"])) { |
|
| 79 | + throw new Ks3ClientException("please specifie file content in request args"); |
|
| 80 | + } |
|
| 78 | 81 | $content = $args["Content"]; |
| 79 | 82 | $plainTextLength = EncryptionUtil::plainTextLength($args); |
| 80 | 83 | if($plainTextLength <= 0){ |
@@ -117,7 +120,7 @@ discard block |
||
| 117 | 120 | $meta = $this->ks3client->getObjectMeta($args); |
| 118 | 121 | if(isset($meta["UserMeta"]["x-kss-meta-x-kss-key"])&&isset($meta["UserMeta"]["x-kss-meta-x-kss-iv"])){ |
| 119 | 122 | $encryptedInMeta = TRUE; |
| 120 | - }else{ |
|
| 123 | + } else{ |
|
| 121 | 124 | $encryptedInMeta = FALSE; |
| 122 | 125 | } |
| 123 | 126 | $encrypted = TRUE; |
@@ -128,7 +131,7 @@ discard block |
||
| 128 | 131 | $encryptionInfo["matdesc"] = $matdesc; |
| 129 | 132 | $cekEncrypted = base64_decode($meta["UserMeta"]["x-kss-meta-x-kss-key"]); |
| 130 | 133 | $encryptionInfo["cek"] = $cek = EncryptionUtil::decodeCek($this->encryptionMaterials,$cekEncrypted); |
| 131 | - }else{ |
|
| 134 | + } else{ |
|
| 132 | 135 | if($this->ks3client->objectExists(array( |
| 133 | 136 | "Bucket"=>$args["Bucket"], |
| 134 | 137 | "Key"=>$args["Key"].EncryptionUtil::$INSTRUCTION_SUFFIX) |
@@ -140,8 +143,9 @@ discard block |
||
| 140 | 143 | "Key"=>$insKey, |
| 141 | 144 | ); |
| 142 | 145 | $s3Object = $this->ks3client->getObject($getIns); |
| 143 | - if(!EncryptionUtil::isInstructionFile($s3Object)) |
|
| 144 | - throw new Ks3ClientException($insKey." is not an InstructionFile"); |
|
| 146 | + if(!EncryptionUtil::isInstructionFile($s3Object)) { |
|
| 147 | + throw new Ks3ClientException($insKey." is not an InstructionFile"); |
|
| 148 | + } |
|
| 145 | 149 | |
| 146 | 150 | $content = $s3Object["Content"]; |
| 147 | 151 | $content = json_decode($content,TRUE); |
@@ -150,7 +154,7 @@ discard block |
||
| 150 | 154 | $encryptionInfo["matdesc"] = $matdesc; |
| 151 | 155 | $cekEncrypted = base64_decode($content["x-kss-key"]); |
| 152 | 156 | $encryptionInfo["cek"] = $cek = EncryptionUtil::decodeCek($this->encryptionMaterials,$cekEncrypted); |
| 153 | - }else{ |
|
| 157 | + } else{ |
|
| 154 | 158 | $encrypted =FALSE; |
| 155 | 159 | } |
| 156 | 160 | } |
@@ -161,10 +165,12 @@ discard block |
||
| 161 | 165 | $iv = $encryptionInfo["iv"]; |
| 162 | 166 | $cek = $encryptionInfo["cek"]; |
| 163 | 167 | |
| 164 | - if(empty($iv)) |
|
| 165 | - throw new Ks3ClientException("can not find iv in UserMeta or InstructionFile"); |
|
| 166 | - if(empty($cek)) |
|
| 167 | - throw new Ks3ClientException("can not find cek in UserMeta or InstructionFile"); |
|
| 168 | + if(empty($iv)) { |
|
| 169 | + throw new Ks3ClientException("can not find iv in UserMeta or InstructionFile"); |
|
| 170 | + } |
|
| 171 | + if(empty($cek)) { |
|
| 172 | + throw new Ks3ClientException("can not find cek in UserMeta or InstructionFile"); |
|
| 173 | + } |
|
| 168 | 174 | |
| 169 | 175 | if(isset($args["Range"])){ |
| 170 | 176 | $range = $args["Range"]; |
@@ -177,10 +183,10 @@ discard block |
||
| 177 | 183 | throw new Ks3ClientException("Invalid range ".$range); |
| 178 | 184 | } |
| 179 | 185 | $range = array("start"=>$a,"end"=>$b); |
| 180 | - }else{ |
|
| 186 | + } else{ |
|
| 181 | 187 | throw new Ks3ClientException("Invalid range ".$range); |
| 182 | 188 | } |
| 183 | - }else{ |
|
| 189 | + } else{ |
|
| 184 | 190 | if(!isset($range["start"])||!isset($range["end"])){ |
| 185 | 191 | throw new Ks3ClientException("Invalid range ".serialize($range)); |
| 186 | 192 | } |
@@ -206,7 +212,7 @@ discard block |
||
| 206 | 212 | } |
| 207 | 213 | $args["writeCallBack"] = $writeCallBack; |
| 208 | 214 | return $this->ks3client->getObject($args); |
| 209 | - }else{ |
|
| 215 | + } else{ |
|
| 210 | 216 | $offset = 0; |
| 211 | 217 | $blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC); |
| 212 | 218 | if(isset($range)){ |
@@ -229,7 +235,7 @@ discard block |
||
| 229 | 235 | $decoded = mdecrypt_generic($td,$content); |
| 230 | 236 | mcrypt_generic_deinit($td); |
| 231 | 237 | mcrypt_module_close($td); |
| 232 | - }else{ |
|
| 238 | + } else{ |
|
| 233 | 239 | $decoded = ""; |
| 234 | 240 | } |
| 235 | 241 | |
@@ -263,15 +269,17 @@ discard block |
||
| 263 | 269 | if($needRemovePad){ |
| 264 | 270 | $padOffset = $pad-$endOffset; |
| 265 | 271 | $actualWriteCount = strlen($decoded)-$padOffset; |
| 266 | - if($actualWriteCount <= 0)//负数的情况就是用户期望的range里全是填充的 |
|
| 272 | + if($actualWriteCount <= 0) { |
|
| 273 | + //负数的情况就是用户期望的range里全是填充的 |
|
| 267 | 274 | $decoded = ""; |
| 268 | - else |
|
| 269 | - $decoded = substr($decoded,0,strlen($decoded)-$padOffset); |
|
| 275 | + } else { |
|
| 276 | + $decoded = substr($decoded,0,strlen($decoded)-$padOffset); |
|
| 277 | + } |
|
| 270 | 278 | } |
| 271 | 279 | $s3Object["Content"] = $decoded; |
| 272 | 280 | return $s3Object; |
| 273 | 281 | } |
| 274 | - }else{ |
|
| 282 | + } else{ |
|
| 275 | 283 | return $this->ks3client->getObject($args); |
| 276 | 284 | } |
| 277 | 285 | } |
@@ -298,8 +306,9 @@ discard block |
||
| 298 | 306 | $uploadId = $args["Options"]["uploadId"]; |
| 299 | 307 | $isLastPart = FALSE; |
| 300 | 308 | $blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC); |
| 301 | - if(isset($args["LastPart"])) |
|
| 302 | - $isLastPart = $args["LastPart"]; |
|
| 309 | + if(isset($args["LastPart"])) { |
|
| 310 | + $isLastPart = $args["LastPart"]; |
|
| 311 | + } |
|
| 303 | 312 | $exists = EncryptionUtil::multipartUploadContextExists($uploadId); |
| 304 | 313 | if(!$exists){ |
| 305 | 314 | throw new Ks3ClientException("no such upload in cache/encryption/"); |
@@ -313,9 +322,10 @@ discard block |
||
| 313 | 322 | throw new Ks3ClientException("get content length failed ,unexpected content length ".$plainTextLength); |
| 314 | 323 | } |
| 315 | 324 | if(!$isLastPart){ |
| 316 | - if($plainTextLength % $blocksize != 0) |
|
| 317 | - throw new Ks3ClientException("Invalid part size,part size (".$plainTextLength.") must be multiples of the block size ".$blocksize); |
|
| 318 | - }else{ |
|
| 325 | + if($plainTextLength % $blocksize != 0) { |
|
| 326 | + throw new Ks3ClientException("Invalid part size,part size (".$plainTextLength.") must be multiples of the block size ".$blocksize); |
|
| 327 | + } |
|
| 328 | + } else{ |
|
| 319 | 329 | $args["ObjectMeta"]["Content-Length"] = $plainTextLength + ($blocksize - $plainTextLength%$blocksize); |
| 320 | 330 | } |
| 321 | 331 | $readCallBack = new AESCBCStreamReadCallBack(); |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | if(isset($this->$property_name)) |
| 21 | 21 | { |
| 22 | 22 | return($this->$property_name); |
| 23 | - }else |
|
| 23 | + } else |
|
| 24 | 24 | { |
| 25 | 25 | return(NULL); |
| 26 | 26 | } |
@@ -33,9 +33,9 @@ discard block |
||
| 33 | 33 | //不能把上次的没读完的长度算在这次里,应该算在上次 |
| 34 | 34 | $written_total = 0-strlen($this->buffer); |
| 35 | 35 | $blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC); |
| 36 | - if($length<$blocksize) |
|
| 37 | - $this->buffer = $data; |
|
| 38 | - else{ |
|
| 36 | + if($length<$blocksize) { |
|
| 37 | + $this->buffer = $data; |
|
| 38 | + } else{ |
|
| 39 | 39 | //如果期望的范围之后还有数据,则认为数据已经接收完毕。不做任何处理 |
| 40 | 40 | if($this->expectedRange["end"] < $this->expectedRange["start"]){ |
| 41 | 41 | return $written_total+strlen($data); |
@@ -53,16 +53,17 @@ discard block |
||
| 53 | 53 | $ivoffset = $blocksize; |
| 54 | 54 | } |
| 55 | 55 | //初始化当前位置 |
| 56 | - if(isset($this->adjustedRange)) |
|
| 57 | - $this->currentIndex = $ivoffset+$this->adjustedRange["start"]; |
|
| 58 | - else |
|
| 59 | - $this->currentIndex = $ivoffset; |
|
| 56 | + if(isset($this->adjustedRange)) { |
|
| 57 | + $this->currentIndex = $ivoffset+$this->adjustedRange["start"]; |
|
| 58 | + } else { |
|
| 59 | + $this->currentIndex = $ivoffset; |
|
| 60 | + } |
|
| 60 | 61 | } |
| 61 | 62 | $written_total+=$ivoffset; |
| 62 | 63 | if(strlen($data) == 0){ |
| 63 | 64 | $decoded = ""; |
| 64 | 65 | return $written_total; |
| 65 | - }else{ |
|
| 66 | + } else{ |
|
| 66 | 67 | $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_CBC,''); |
| 67 | 68 | mcrypt_generic_init($td,$this->cek,$this->iv); |
| 68 | 69 | $decoded = mdecrypt_generic($td,$data); |
@@ -95,7 +96,7 @@ discard block |
||
| 95 | 96 | $preLength = strlen($decoded); |
| 96 | 97 | $decoded = substr($decoded, 0,$expectedEnd-$this->currentIndex+1); |
| 97 | 98 | $endOffset = $preLength-strlen($decoded); |
| 98 | - }else{ |
|
| 99 | + } else{ |
|
| 99 | 100 | //因为range是开始结束都计算的,range=1-2。currentIndex=1,长度是2,end=currentIndex+2-1 |
| 100 | 101 | $trueEnd = $this->currentIndex+strlen($decoded)-1; |
| 101 | 102 | } |
@@ -117,14 +118,17 @@ discard block |
||
| 117 | 118 | if($needRemovePad){ |
| 118 | 119 | $padOffset = $pad-$endOffset; |
| 119 | 120 | $actualWriteCount = strlen($decoded)-$padOffset; |
| 120 | - if($actualWriteCount <= 0)//负数的情况就是用户期望的range里全是填充的 |
|
| 121 | + if($actualWriteCount <= 0) { |
|
| 122 | + //负数的情况就是用户期望的range里全是填充的 |
|
| 121 | 123 | $decoded = ""; |
| 122 | - else |
|
| 123 | - $decoded = substr($decoded,0,strlen($decoded)-$padOffset); |
|
| 124 | + } else { |
|
| 125 | + $decoded = substr($decoded,0,strlen($decoded)-$padOffset); |
|
| 126 | + } |
|
| 124 | 127 | } |
| 125 | 128 | $count = fwrite($write_stream, $decoded); |
| 126 | - if($count == 0) |
|
| 127 | - $count = $actualWriteCount; |
|
| 129 | + if($count == 0) { |
|
| 130 | + $count = $actualWriteCount; |
|
| 131 | + } |
|
| 128 | 132 | $count += $padOffset; |
| 129 | 133 | $count += $startOffset; |
| 130 | 134 | $count += $endOffset; |
@@ -138,12 +142,14 @@ discard block |
||
| 138 | 142 | //是的话则使用初始化IV |
| 139 | 143 | private function isBegin(){ |
| 140 | 144 | $beginIndex = 0; |
| 141 | - if(isset($this->adjustedRange["start"])) |
|
| 142 | - $beginIndex = $this->adjustedRange["start"]; |
|
| 143 | - if($beginIndex == 0) |
|
| 144 | - return TRUE; |
|
| 145 | - else |
|
| 146 | - return FALSE; |
|
| 145 | + if(isset($this->adjustedRange["start"])) { |
|
| 146 | + $beginIndex = $this->adjustedRange["start"]; |
|
| 147 | + } |
|
| 148 | + if($beginIndex == 0) { |
|
| 149 | + return TRUE; |
|
| 150 | + } else { |
|
| 151 | + return FALSE; |
|
| 152 | + } |
|
| 147 | 153 | } |
| 148 | 154 | } |
| 149 | 155 | //上传 |
@@ -162,7 +168,7 @@ discard block |
||
| 162 | 168 | if(isset($this->$property_name)) |
| 163 | 169 | { |
| 164 | 170 | return($this->$property_name); |
| 165 | - }else |
|
| 171 | + } else |
|
| 166 | 172 | { |
| 167 | 173 | return(NULL); |
| 168 | 174 | } |
@@ -199,16 +205,16 @@ discard block |
||
| 199 | 205 | if(!$isLast){ |
| 200 | 206 | $this->buffer = substr($data,$dataLength-$dataLength%$blocksize); |
| 201 | 207 | $data = substr($data, 0,$dataLength-$dataLength%$blocksize); |
| 202 | - }else{ |
|
| 208 | + } else{ |
|
| 203 | 209 | //分块上传除最后一块外肯定是blocksize大小的倍数,所以不需要填充。 |
| 204 | 210 | if($this->mutipartUpload){ |
| 205 | 211 | if($this->isLastPart){ |
| 206 | 212 | $this->buffer = NULL; |
| 207 | 213 | $data = EncryptionUtil::PKCS5Padding($data,$blocksize); |
| 208 | - }else{ |
|
| 214 | + } else{ |
|
| 209 | 215 | //donothing |
| 210 | 216 | } |
| 211 | - }else{ |
|
| 217 | + } else{ |
|
| 212 | 218 | $this->buffer = NULL; |
| 213 | 219 | $data = EncryptionUtil::PKCS5Padding($data,$blocksize); |
| 214 | 220 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | array_push($keys, $object["Key"]); |
| 35 | 35 | } |
| 36 | 36 | $this->client->deleteObjects(array("Bucket"=>$this->bucket,"DeleteKeys"=>$keys)); |
| 37 | - }else{ |
|
| 37 | + } else{ |
|
| 38 | 38 | $this->client->createBucket(array("Bucket"=>$this->bucket)); |
| 39 | 39 | } |
| 40 | 40 | } |
@@ -42,11 +42,13 @@ discard block |
||
| 42 | 42 | $buckets = $this->client->listBuckets(); |
| 43 | 43 | $found = FALSE; |
| 44 | 44 | foreach ($buckets as $bucket) { |
| 45 | - if($bucket["Name"] == $this->bucket) |
|
| 46 | - $found = TRUE; |
|
| 45 | + if($bucket["Name"] == $this->bucket) { |
|
| 46 | + $found = TRUE; |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | + if(!$found) { |
|
| 50 | + throw new Exception("list buckets expected found ".$this->bucket.",but not found"); |
|
| 47 | 51 | } |
| 48 | - if(!$found) |
|
| 49 | - throw new Exception("list buckets expected found ".$this->bucket.",but not found"); |
|
| 50 | 52 | |
| 51 | 53 | } |
| 52 | 54 | public function testDeleteBucket(){ |
@@ -54,7 +56,7 @@ discard block |
||
| 54 | 56 | $ex = NULL; |
| 55 | 57 | try{ |
| 56 | 58 | $this->client->deleteBucket(array("Bucket"=>$this->bucket)); |
| 57 | - }catch(Exception $e){ |
|
| 59 | + } catch(Exception $e){ |
|
| 58 | 60 | $ex = $e; |
| 59 | 61 | } |
| 60 | 62 | if($ex == NULL||!($ex->errorCode === "BucketNotEmpty")){ |
@@ -90,7 +92,7 @@ discard block |
||
| 90 | 92 | $ex = NULL; |
| 91 | 93 | try{ |
| 92 | 94 | $this->client->createBucket(array("Bucket"=>$this->bucket)); |
| 93 | - }catch(Exception $e){ |
|
| 95 | + } catch(Exception $e){ |
|
| 94 | 96 | $ex = $e; |
| 95 | 97 | } |
| 96 | 98 | if($ex == NULL||!($ex->errorCode === "BucketAlreadyExists")){ |
@@ -256,7 +258,7 @@ discard block |
||
| 256 | 258 | $ex = NULL; |
| 257 | 259 | try{ |
| 258 | 260 | $this->client->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uid))); |
| 259 | - }catch(Exception $e){ |
|
| 261 | + } catch(Exception $e){ |
|
| 260 | 262 | $ex = $e; |
| 261 | 263 | } |
| 262 | 264 | if($ex == NULL||!($ex->errorCode === "NoSuchUpload")){ |
@@ -33,8 +33,9 @@ |
||
| 33 | 33 | } |
| 34 | 34 | $md5 = md5_file($file); |
| 35 | 35 | //@unlink($file); |
| 36 | - if($md5 != $expectedMd5) |
|
| 37 | - throw new Exception("file md5 check error expected ".$expectedMd5." ,actual ".$md5, 1); |
|
| 36 | + if($md5 != $expectedMd5) { |
|
| 37 | + throw new Exception("file md5 check error expected ".$expectedMd5." ,actual ".$md5, 1); |
|
| 38 | + } |
|
| 38 | 39 | foreach ($filelist as $key => $value) { |
| 39 | 40 | @unlink($value); |
| 40 | 41 | } |
@@ -9,12 +9,13 @@ discard block |
||
| 9 | 9 | function run($torun = NULL){ |
| 10 | 10 | $r = new ReflectionClass($this); |
| 11 | 11 | foreach($r->getMethods() as $key=>$methodObj){ |
| 12 | - if($methodObj->isPrivate()) |
|
| 13 | - $methods[$key]['type'] = 'private'; |
|
| 14 | - elseif($methodObj->isProtected()) |
|
| 15 | - $methods[$key]['type'] = 'protected'; |
|
| 16 | - else |
|
| 17 | - $methods[$key]['type'] = 'public'; |
|
| 12 | + if($methodObj->isPrivate()) { |
|
| 13 | + $methods[$key]['type'] = 'private'; |
|
| 14 | + } elseif($methodObj->isProtected()) { |
|
| 15 | + $methods[$key]['type'] = 'protected'; |
|
| 16 | + } else { |
|
| 17 | + $methods[$key]['type'] = 'public'; |
|
| 18 | + } |
|
| 18 | 19 | $methods[$key]['name'] = $methodObj->name; |
| 19 | 20 | $methods[$key]['class'] = $methodObj->class; |
| 20 | 21 | } |
@@ -33,19 +34,21 @@ discard block |
||
| 33 | 34 | foreach ($methods as $method) { |
| 34 | 35 | if($method["class"] != "PUnit"&&substr($method["name"],0,4) == "test"){ |
| 35 | 36 | if($torun !== NULL){ |
| 36 | - if(!in_array($method["name"],$torun)) |
|
| 37 | - continue; |
|
| 37 | + if(!in_array($method["name"],$torun)) { |
|
| 38 | + continue; |
|
| 39 | + } |
|
| 38 | 40 | } |
| 39 | 41 | try{ |
| 40 | 42 | if($method["type"] == "public"){ |
| 41 | 43 | $log = new Logger(); |
| 42 | 44 | $log->info("Run unit --->".$method["name"]); |
| 43 | - if($before!=NULL) |
|
| 44 | - $this->$before["name"](); |
|
| 45 | + if($before!=NULL) { |
|
| 46 | + $this->$before["name"](); |
|
| 47 | + } |
|
| 45 | 48 | $this->$method["name"](); |
| 46 | 49 | array_push($success,$method["name"]); |
| 47 | 50 | } |
| 48 | - }catch(Exception $e){ |
|
| 51 | + } catch(Exception $e){ |
|
| 49 | 52 | $error[$method["name"]]="".$e; |
| 50 | 53 | } |
| 51 | 54 | } |
@@ -54,11 +54,12 @@ discard block |
||
| 54 | 54 | $postMultipart = false; |
| 55 | 55 | foreach ($postFields as $k => $v) |
| 56 | 56 | { |
| 57 | - if("@" != substr($v, 0, 1))//判断是不是文件上传 |
|
| 57 | + if("@" != substr($v, 0, 1)) { |
|
| 58 | + //判断是不是文件上传 |
|
| 58 | 59 | { |
| 59 | - $postBodyString .= "$k=" . urlencode($v) . "&"; |
|
| 60 | + $postBodyString .= "$k=" . urlencode($v) . "&"; |
|
| 60 | 61 | } |
| 61 | - else//文件上传用multipart/form-data,否则用www-form-urlencoded |
|
| 62 | + } else//文件上传用multipart/form-data,否则用www-form-urlencoded |
|
| 62 | 63 | { |
| 63 | 64 | $postMultipart = true; |
| 64 | 65 | if(class_exists('\CURLFile')){ |
@@ -78,8 +79,7 @@ discard block |
||
| 78 | 79 | } |
| 79 | 80 | } |
| 80 | 81 | curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); |
| 81 | - } |
|
| 82 | - else |
|
| 82 | + } else |
|
| 83 | 83 | { |
| 84 | 84 | $header = array("content-type: application/x-www-form-urlencoded; charset=UTF-8"); |
| 85 | 85 | curl_setopt($ch,CURLOPT_HTTPHEADER,$header); |
@@ -91,8 +91,7 @@ discard block |
||
| 91 | 91 | if (curl_errno($ch)) |
| 92 | 92 | { |
| 93 | 93 | throw new Exception(curl_error($ch),0); |
| 94 | - } |
|
| 95 | - else |
|
| 94 | + } else |
|
| 96 | 95 | { |
| 97 | 96 | $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
| 98 | 97 | if (200 !== $httpStatusCode) |
@@ -144,8 +143,7 @@ discard block |
||
| 144 | 143 | if (curl_errno($ch)) |
| 145 | 144 | { |
| 146 | 145 | throw new Exception(curl_error($ch),0); |
| 147 | - } |
|
| 148 | - else |
|
| 146 | + } else |
|
| 149 | 147 | { |
| 150 | 148 | $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
| 151 | 149 | if (200 !== $httpStatusCode) |
@@ -185,11 +183,12 @@ discard block |
||
| 185 | 183 | if(!is_string($v)){ |
| 186 | 184 | $v = json_encode($v); |
| 187 | 185 | } |
| 188 | - if("@" != substr($v, 0, 1))//判断是不是文件上传 |
|
| 186 | + if("@" != substr($v, 0, 1)) { |
|
| 187 | + //判断是不是文件上传 |
|
| 189 | 188 | { |
| 190 | 189 | $postBodyString .= "$k=" . urlencode($v) . "&"; |
| 191 | 190 | } |
| 192 | - else//文件上传用multipart/form-data,否则用www-form-urlencoded |
|
| 191 | + } else//文件上传用multipart/form-data,否则用www-form-urlencoded |
|
| 193 | 192 | { |
| 194 | 193 | $postMultipart = true; |
| 195 | 194 | if(class_exists('\CURLFile')){ |
@@ -209,8 +208,7 @@ discard block |
||
| 209 | 208 | } |
| 210 | 209 | } |
| 211 | 210 | curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); |
| 212 | - } |
|
| 213 | - else { |
|
| 211 | + } else { |
|
| 214 | 212 | $header = array("Content-Type: application/json; charset=utf-8", "Content-Length:".strlen(json_encode($postFields))); |
| 215 | 213 | curl_setopt($ch,CURLOPT_HTTPHEADER,$header); |
| 216 | 214 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postFields)); |
@@ -221,8 +219,7 @@ discard block |
||
| 221 | 219 | if (curl_errno($ch)) |
| 222 | 220 | { |
| 223 | 221 | throw new Exception(curl_error($ch),0); |
| 224 | - } |
|
| 225 | - else |
|
| 222 | + } else |
|
| 226 | 223 | { |
| 227 | 224 | $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
| 228 | 225 | if (200 !== $httpStatusCode) |
@@ -294,8 +291,7 @@ discard block |
||
| 294 | 291 | if (curl_errno($ch)) |
| 295 | 292 | { |
| 296 | 293 | throw new Exception(curl_error($ch),0); |
| 297 | - } |
|
| 298 | - else |
|
| 294 | + } else |
|
| 299 | 295 | { |
| 300 | 296 | $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
| 301 | 297 | if (200 !== $httpStatusCode) |
@@ -329,7 +325,7 @@ discard block |
||
| 329 | 325 | public function execute($request, $session = null,$bestUrl = null){ |
| 330 | 326 | if(DingTalkConstant::$CALL_TYPE_OAPI == $this->apiCallType){ |
| 331 | 327 | return $this->_executeOapi($request, $session, $bestUrl, null, null, null, null); |
| 332 | - }else{ |
|
| 328 | + } else{ |
|
| 333 | 329 | return $this->_execute($request, $session, $bestUrl); |
| 334 | 330 | } |
| 335 | 331 | } |
@@ -345,7 +341,7 @@ discard block |
||
| 345 | 341 | public function executeWithCorpId($request, $bestUrl = null, $accessKey, $accessSecret, $suiteTicket, $corpId) { |
| 346 | 342 | if(DingTalkConstant::$CALL_TYPE_OAPI == $this->apiCallType){ |
| 347 | 343 | return $this->_executeOapi($request, null, $bestUrl,$accessKey, $accessSecret, $suiteTicket, $corpId); |
| 348 | - }else{ |
|
| 344 | + } else{ |
|
| 349 | 345 | return $this->_execute($request, null, $bestUrl); |
| 350 | 346 | } |
| 351 | 347 | } |
@@ -368,10 +364,10 @@ discard block |
||
| 368 | 364 | if($bestUrl){ |
| 369 | 365 | if(strpos($bestUrl,'?') === false){ |
| 370 | 366 | $requestUrl = $bestUrl."?"; |
| 371 | - }else{ |
|
| 367 | + } else{ |
|
| 372 | 368 | $requestUrl = $bestUrl; |
| 373 | 369 | } |
| 374 | - }else{ |
|
| 370 | + } else{ |
|
| 375 | 371 | $requestUrl = $this->gatewayUrl."?"; |
| 376 | 372 | } |
| 377 | 373 | if(null != $accessKey){ |
@@ -392,7 +388,7 @@ discard block |
||
| 392 | 388 | foreach ($queryParams as $queryParamKey => $queryParamValue) { |
| 393 | 389 | $requestUrl .= "$queryParamKey=" . urlencode($queryParamValue) . "&"; |
| 394 | 390 | } |
| 395 | - }else{ |
|
| 391 | + } else{ |
|
| 396 | 392 | $requestUrl .= "access_token=" . urlencode($session) . "&"; |
| 397 | 393 | } |
| 398 | 394 | |
@@ -416,15 +412,14 @@ discard block |
||
| 416 | 412 | { |
| 417 | 413 | if(count($fileFields) > 0){ |
| 418 | 414 | $resp = $this->curl_with_memory_file($requestUrl, $apiParams, $fileFields); |
| 419 | - }else{ |
|
| 415 | + } else{ |
|
| 420 | 416 | if(DingTalkConstant::$METHOD_POST == $this->httpMethod){ |
| 421 | 417 | $resp = $this->curl_json($requestUrl, $apiParams); |
| 422 | - }else{ |
|
| 418 | + } else{ |
|
| 423 | 419 | $resp = $this->curl_get($requestUrl, $apiParams); |
| 424 | 420 | } |
| 425 | 421 | } |
| 426 | - } |
|
| 427 | - catch (Exception $e) |
|
| 422 | + } catch (Exception $e) |
|
| 428 | 423 | { |
| 429 | 424 | $this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_ERROR_" . $e->getCode(),$e->getMessage()); |
| 430 | 425 | $result->code = $e->getCode(); |
@@ -443,8 +438,7 @@ discard block |
||
| 443 | 438 | { |
| 444 | 439 | $respWellFormed = true; |
| 445 | 440 | } |
| 446 | - } |
|
| 447 | - else if("xml" == $this->format) |
|
| 441 | + } else if("xml" == $this->format) |
|
| 448 | 442 | { |
| 449 | 443 | $respObject = @simplexml_load_string($resp); |
| 450 | 444 | if (false !== $respObject) |
@@ -524,11 +518,11 @@ discard block |
||
| 524 | 518 | if($bestUrl){ |
| 525 | 519 | if(strpos($bestUrl,'?') === false){ |
| 526 | 520 | $requestUrl = $bestUrl."?"; |
| 527 | - }else{ |
|
| 521 | + } else{ |
|
| 528 | 522 | $requestUrl = $bestUrl; |
| 529 | 523 | } |
| 530 | 524 | $sysParams["partner_id"] = $this->getClusterTag(); |
| 531 | - }else{ |
|
| 525 | + } else{ |
|
| 532 | 526 | $requestUrl = $this->gatewayUrl."?"; |
| 533 | 527 | $sysParams["partner_id"] = $this->sdkVersion; |
| 534 | 528 | } |
@@ -556,11 +550,10 @@ discard block |
||
| 556 | 550 | { |
| 557 | 551 | if(count($fileFields) > 0){ |
| 558 | 552 | $resp = $this->curl_with_memory_file($requestUrl, $apiParams, $fileFields); |
| 559 | - }else{ |
|
| 553 | + } else{ |
|
| 560 | 554 | $resp = $this->curl($requestUrl, $apiParams); |
| 561 | 555 | } |
| 562 | - } |
|
| 563 | - catch (Exception $e) |
|
| 556 | + } catch (Exception $e) |
|
| 564 | 557 | { |
| 565 | 558 | $this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_ERROR_" . $e->getCode(),$e->getMessage()); |
| 566 | 559 | $result->code = $e->getCode(); |
@@ -583,8 +576,7 @@ discard block |
||
| 583 | 576 | $respObject = $propValue; |
| 584 | 577 | } |
| 585 | 578 | } |
| 586 | - } |
|
| 587 | - else if("xml" == $this->format) |
|
| 579 | + } else if("xml" == $this->format) |
|
| 588 | 580 | { |
| 589 | 581 | $respObject = @simplexml_load_string($resp); |
| 590 | 582 | if (false !== $respObject) |
@@ -77,11 +77,12 @@ discard block |
||
| 77 | 77 | $postMultipart = false; |
| 78 | 78 | foreach ($postFields as $k => $v) |
| 79 | 79 | { |
| 80 | - if("@" != substr($v, 0, 1))//判断是不是文件上传 |
|
| 80 | + if("@" != substr($v, 0, 1)) { |
|
| 81 | + //判断是不是文件上传 |
|
| 81 | 82 | { |
| 82 | - $postBodyString .= "$k=" . urlencode($v) . "&"; |
|
| 83 | + $postBodyString .= "$k=" . urlencode($v) . "&"; |
|
| 83 | 84 | } |
| 84 | - else//文件上传用multipart/form-data,否则用www-form-urlencoded |
|
| 85 | + } else//文件上传用multipart/form-data,否则用www-form-urlencoded |
|
| 85 | 86 | { |
| 86 | 87 | $postMultipart = true; |
| 87 | 88 | if(class_exists('\CURLFile')){ |
@@ -101,8 +102,7 @@ discard block |
||
| 101 | 102 | } |
| 102 | 103 | } |
| 103 | 104 | curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); |
| 104 | - } |
|
| 105 | - else |
|
| 105 | + } else |
|
| 106 | 106 | { |
| 107 | 107 | $header = array("content-type: application/x-www-form-urlencoded; charset=UTF-8"); |
| 108 | 108 | curl_setopt($ch,CURLOPT_HTTPHEADER,$header); |
@@ -114,8 +114,7 @@ discard block |
||
| 114 | 114 | if (curl_errno($ch)) |
| 115 | 115 | { |
| 116 | 116 | throw new Exception(curl_error($ch),0); |
| 117 | - } |
|
| 118 | - else |
|
| 117 | + } else |
|
| 119 | 118 | { |
| 120 | 119 | $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
| 121 | 120 | if (200 !== $httpStatusCode) |
@@ -186,8 +185,7 @@ discard block |
||
| 186 | 185 | if (curl_errno($ch)) |
| 187 | 186 | { |
| 188 | 187 | throw new Exception(curl_error($ch),0); |
| 189 | - } |
|
| 190 | - else |
|
| 188 | + } else |
|
| 191 | 189 | { |
| 192 | 190 | $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
| 193 | 191 | if (200 !== $httpStatusCode) |
@@ -257,7 +255,7 @@ discard block |
||
| 257 | 255 | if($bestUrl){ |
| 258 | 256 | $requestUrl = $bestUrl."?"; |
| 259 | 257 | $sysParams["partner_id"] = $this->getClusterTag(); |
| 260 | - }else{ |
|
| 258 | + } else{ |
|
| 261 | 259 | $requestUrl = $this->gatewayUrl."?"; |
| 262 | 260 | $sysParams["partner_id"] = $this->sdkVersion; |
| 263 | 261 | } |
@@ -287,11 +285,10 @@ discard block |
||
| 287 | 285 | { |
| 288 | 286 | if(count($fileFields) > 0){ |
| 289 | 287 | $resp = $this->curl_with_memory_file($requestUrl, $apiParams, $fileFields); |
| 290 | - }else{ |
|
| 288 | + } else{ |
|
| 291 | 289 | $resp = $this->curl($requestUrl, $apiParams); |
| 292 | 290 | } |
| 293 | - } |
|
| 294 | - catch (Exception $e) |
|
| 291 | + } catch (Exception $e) |
|
| 295 | 292 | { |
| 296 | 293 | $this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_ERROR_" . $e->getCode(),$e->getMessage()); |
| 297 | 294 | $result->code = $e->getCode(); |
@@ -314,8 +311,7 @@ discard block |
||
| 314 | 311 | $respObject = $propValue; |
| 315 | 312 | } |
| 316 | 313 | } |
| 317 | - } |
|
| 318 | - else if("xml" == $this->format) |
|
| 314 | + } else if("xml" == $this->format) |
|
| 319 | 315 | { |
| 320 | 316 | $respObject = @simplexml_load_string($resp); |
| 321 | 317 | if (false !== $respObject) |