Passed
Push — v6 ( f71c30...fe03e1 )
by 光春
04:16
created
src/helper/Files.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 // | Packagist 地址 :https://packagist.org/packages/liguangchun/think-library
18 18
 // +----------------------------------------------------------------------
19 19
 
20
-declare (strict_types=1);
20
+declare(strict_types=1);
21 21
 
22 22
 namespace DtApp\ThinkLibrary\helper;
23 23
 
@@ -67,10 +67,10 @@  discard block
 block discarded – undo
67 67
         $dh = opendir($name);
68 68
         while ($file = readdir($dh)) {
69 69
             if ($file !== "." && $file !== "..") {
70
-                $fullpath = $name . "/" . $file;
70
+                $fullpath = $name."/".$file;
71 71
                 if (!is_dir($fullpath)) {
72 72
                     unlink($fullpath);
73
-                } else {
73
+                }else {
74 74
                     $this->deletes($fullpath);
75 75
                 }
76 76
             }
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
         if (empty($name)) {
98 98
             throw new DtaException('请检查需要打包的路径名称');
99 99
         }
100
-        $list = glob($name . "{$file_name}.{$suffix_name}");
100
+        $list = glob($name."{$file_name}.{$suffix_name}");
101 101
         $fileList = $list;
102 102
         $zip = new ZipArchive();
103 103
         // 打开压缩包
@@ -120,13 +120,13 @@  discard block
 block discarded – undo
120 120
     {
121 121
         $files = [];
122 122
         if (is_dir($path)) {
123
-            $path = dirname($path) . '/' . basename($path) . '/';
123
+            $path = dirname($path).'/'.basename($path).'/';
124 124
             $file = dir($path);
125 125
             while (false !== ($entry = $file->read())) {
126 126
                 if ($entry !== '.' && $entry !== '..') {
127
-                    $cur = $path . $entry;
127
+                    $cur = $path.$entry;
128 128
                     if (is_dir($cur)) {
129
-                        $subPath = $cur . '/';
129
+                        $subPath = $cur.'/';
130 130
                         $this->getFiles($subPath);
131 131
                     }
132 132
                     $files[] = $cur;
Please login to merge, or discard this patch.
src/helper/Randoms.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 // | Packagist 地址 :https://packagist.org/packages/liguangchun/think-library
18 18
 // +----------------------------------------------------------------------
19 19
 
20
-declare (strict_types=1);
20
+declare(strict_types=1);
21 21
 
22 22
 namespace DtApp\ThinkLibrary\helper;
23 23
 
@@ -58,13 +58,13 @@  discard block
 block discarded – undo
58 58
             $charset = array_merge($lowerLetter, $upperLetter);
59 59
         } elseif ($type === 7) {
60 60
             $charset = array_merge($number, $lowerLetter, $upperLetter);
61
-        } else {
61
+        }else {
62 62
             $charset = $number;
63 63
         }
64 64
         $str = '';
65 65
         // 生成字符串
66 66
         for ($i = 0; $i < $length; $i++) {
67
-            $str .= $charset[random_int(0, count($charset) - 1)];
67
+            $str .= $charset[random_int(0, count($charset)-1)];
68 68
             // 验证规则
69 69
             if ($type === 4 && strlen($str) >= 2) {
70 70
                 if (!preg_match('/\d+/', $str) || !preg_match('/[a-z]+/', $str)) {
Please login to merge, or discard this patch.
src/service/tencent/LbsService.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
     {
244 244
         //组织参数
245 245
         $strParam = $this->createStrParam();
246
-        $result = file_get_contents($this->api_url . "?{$strParam}");
246
+        $result = file_get_contents($this->api_url."?{$strParam}");
247 247
         $result = json_decode($result, true);
248 248
         $this->output = $result;
249 249
     }
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
         $strParam = '';
258 258
         foreach ($this->param as $key => $val) {
259 259
             if ($key !== '' && $val !== '') {
260
-                $strParam .= $key . '=' . urlencode($val) . '&';
260
+                $strParam .= $key.'='.urlencode($val).'&';
261 261
             }
262 262
         }
263 263
         return $strParam;
Please login to merge, or discard this patch.
src/service/decent/EJiAoFei.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -210,8 +210,8 @@
 block discarded – undo
210 210
         //生成签名
211 211
         $sign = $this->createSign();
212 212
         //组织参数
213
-        $this->param .= '&userkey=' . $sign;
214
-        $url = "http://" . $this->api . "/" . $this->method . ".do?{$this->param}";
213
+        $this->param .= '&userkey='.$sign;
214
+        $url = "http://".$this->api."/".$this->method.".do?{$this->param}";
215 215
         $result = file_get_contents($url);
216 216
         $result = Xmls::toArray($result);
217 217
         $this->output = $result;
Please login to merge, or discard this patch.
src/service/qiniu/SmsService.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
     {
312 312
         if (is_object($object)) {
313 313
             $arr = (array)($object);
314
-        } else {
314
+        }else {
315 315
             $arr = &$object;
316 316
         }
317 317
         if (is_array($arr)) {
@@ -345,8 +345,8 @@  discard block
 block discarded – undo
345 345
         $recToken = $auth->authorizationV2($this->url, $this->method, json_encode($this->param), $this->contentType);
346 346
         $rtcToken['Content-Type'] = $this->contentType;
347 347
         dump($recToken);
348
-        dump($this->url . "?" . http_build_query($this->param));
349
-        $ret = Client::get($this->url . "?" . http_build_query($this->param), $recToken);
348
+        dump($this->url."?".http_build_query($this->param));
349
+        $ret = Client::get($this->url."?".http_build_query($this->param), $recToken);
350 350
         dump($ret);
351 351
         $this->output = $ret->json();
352 352
         return $this;
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
         $url = parse_url($this->url);
363 363
         $data = $url['path'] ?? '';
364 364
         if (isset($url['query'])) {
365
-            $data .= '?' . $url['query'];
365
+            $data .= '?'.$url['query'];
366 366
         }
367 367
         $data .= "\n";
368 368
         if (isset($this->param) && $this->contentType === 'application/x-www-form-urlencoded') {
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
     private function sign($data)
379 379
     {
380 380
         $sign = hash_hmac('sha1', $data, $this->secretKey, true);
381
-        return "Qiniu " . sprintf('%s:%s', $this->accessKey, $this->encode($sign));
381
+        return "Qiniu ".sprintf('%s:%s', $this->accessKey, $this->encode($sign));
382 382
     }
383 383
 
384 384
     /**
Please login to merge, or discard this patch.
src/service/ExcelService.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -167,12 +167,12 @@
 block discarded – undo
167 167
         //设置单元格内容
168 168
         foreach ($this->head as $key => $value) {
169 169
             foreach ($value as $k => $v) {
170
-                $sheet->setCellValueByColumnAndRow($v['index'], $key + 1, $v['value']);
170
+                $sheet->setCellValueByColumnAndRow($v['index'], $key+1, $v['value']);
171 171
             }
172 172
         }
173 173
         foreach ($this->content as $key => $value) {
174 174
             foreach ($value as $k => $v) {
175
-                $sheet->setCellValueByColumnAndRow($v['index'], $key + $this->head_length, $v['value']);
175
+                $sheet->setCellValueByColumnAndRow($v['index'], $key+$this->head_length, $v['value']);
176 176
             }
177 177
         }
178 178
         $writer = new Xlsx($spreadsheet);
Please login to merge, or discard this patch.
src/service/QqWryService.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -68,10 +68,10 @@  discard block
 block discarded – undo
68 68
     public function __construct(App $app)
69 69
     {
70 70
         $this->fp = 0;
71
-        if (($this->fp = fopen(__DIR__ . '/bin/qqwry.dat', 'rb')) !== false) {
71
+        if (($this->fp = fopen(__DIR__.'/bin/qqwry.dat', 'rb')) !== false) {
72 72
             $this->firstIp = $this->getLong();
73 73
             $this->lastIp = $this->getLong();
74
-            $this->totalIp = ($this->lastIp - $this->firstIp) / 7;
74
+            $this->totalIp = ($this->lastIp-$this->firstIp)/7;
75 75
         }
76 76
         parent::__construct($app);
77 77
     }
@@ -152,49 +152,49 @@  discard block
 block discarded – undo
152 152
                 // 如果数据文件没有被正确打开,则直接返回错误
153 153
                 throw new DtaException('数据库文件不存在!');
154 154
             }
155
-            $location['ip'] = $ip;   // 将输入的域名转化为IP地址
156
-            $ip = $this->packIp($location['ip']);   // 将输入的IP地址转化为可比较的IP地址
155
+            $location['ip'] = $ip; // 将输入的域名转化为IP地址
156
+            $ip = $this->packIp($location['ip']); // 将输入的IP地址转化为可比较的IP地址
157 157
             // 不合法的IP地址会被转化为255.255.255.255
158 158
             // 对分搜索
159
-            $l = 0;                         // 搜索的下边界
160
-            $u = $this->totalIp;            // 搜索的上边界
161
-            $findip = $this->lastIp;        // 如果没有找到就返回最后一条IP记录(QQWry.Dat的版本信息)
159
+            $l = 0; // 搜索的下边界
160
+            $u = $this->totalIp; // 搜索的上边界
161
+            $findip = $this->lastIp; // 如果没有找到就返回最后一条IP记录(QQWry.Dat的版本信息)
162 162
             while ($l <= $u) {              // 当上边界小于下边界时,查找失败
163
-                $i = floor(($l + $u) / 2);  // 计算近似中间记录
164
-                fseek($this->fp, $this->firstIp + $i * 7);
165
-                $beginip = strrev(fread($this->fp, 4));     // 获取中间记录的开始IP地址
163
+                $i = floor(($l+$u)/2); // 计算近似中间记录
164
+                fseek($this->fp, $this->firstIp+$i*7);
165
+                $beginip = strrev(fread($this->fp, 4)); // 获取中间记录的开始IP地址
166 166
                 // strrev函数在这里的作用是将little-endian的压缩IP地址转化为big-endian的格式
167 167
                 // 以便用于比较,后面相同。
168 168
                 if ($ip < $beginip) {       // 用户的IP小于中间记录的开始IP地址时
169
-                    $u = $i - 1;            // 将搜索的上边界修改为中间记录减一
170
-                } else {
169
+                    $u = $i-1; // 将搜索的上边界修改为中间记录减一
170
+                }else {
171 171
                     fseek($this->fp, $this->getLong3());
172
-                    $endip = strrev(fread($this->fp, 4));   // 获取中间记录的结束IP地址
172
+                    $endip = strrev(fread($this->fp, 4)); // 获取中间记录的结束IP地址
173 173
                     if ($ip > $endip) {     // 用户的IP大于中间记录的结束IP地址时
174
-                        $l = $i + 1;        // 将搜索的下边界修改为中间记录加一
175
-                    } else {                  // 用户的IP在中间记录的IP范围内时
176
-                        $findip = $this->firstIp + $i * 7;
177
-                        break;              // 则表示找到结果,退出循环
174
+                        $l = $i+1; // 将搜索的下边界修改为中间记录加一
175
+                    }else {                  // 用户的IP在中间记录的IP范围内时
176
+                        $findip = $this->firstIp+$i*7;
177
+                        break; // 则表示找到结果,退出循环
178 178
                     }
179 179
                 }
180 180
             }
181 181
             //获取查找到的IP地理位置信息
182 182
             fseek($this->fp, $findip);
183
-            $location['beginip'] = long2ip($this->getLong());   // 用户IP所在范围的开始地址
183
+            $location['beginip'] = long2ip($this->getLong()); // 用户IP所在范围的开始地址
184 184
             $offset = $this->getLong3();
185 185
             fseek($this->fp, $offset);
186
-            $location['endip'] = long2ip($this->getLong());     // 用户IP所在范围的结束地址
187
-            $byte = fread($this->fp, 1);    // 标志字节
186
+            $location['endip'] = long2ip($this->getLong()); // 用户IP所在范围的结束地址
187
+            $byte = fread($this->fp, 1); // 标志字节
188 188
             switch (ord($byte)) {
189 189
                 case 1:                     // 标志字节为1,表示国家和区域信息都被同时重定向
190
-                    $countryOffset = $this->getLong3();         // 重定向地址
190
+                    $countryOffset = $this->getLong3(); // 重定向地址
191 191
                     fseek($this->fp, $countryOffset);
192
-                    $byte = fread($this->fp, 1);    // 标志字节
192
+                    $byte = fread($this->fp, 1); // 标志字节
193 193
                     switch (ord($byte)) {
194 194
                         case 2:             // 标志字节为2,表示国家信息又被重定向
195 195
                             fseek($this->fp, $this->getLong3());
196 196
                             $location['all'] = $this->getString();
197
-                            fseek($this->fp, $countryOffset + 4);
197
+                            fseek($this->fp, $countryOffset+4);
198 198
                             $location['extend'] = $this->getExtendString();
199 199
                             break;
200 200
                         default:            // 否则,表示国家信息没有被重定向
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
                 case 2:                     // 标志字节为2,表示国家信息被重定向
207 207
                     fseek($this->fp, $this->getLong3());
208 208
                     $location['all'] = $this->getString();
209
-                    fseek($this->fp, $offset + 8);
209
+                    fseek($this->fp, $offset+8);
210 210
                     $location['extend'] = $this->getExtendString();
211 211
                     break;
212 212
                 default:                    // 否则,表示国家信息没有被重定向
@@ -264,14 +264,14 @@  discard block
 block discarded – undo
264 264
             if (count($preg) == 4) {        //匹配 "浙江省杭州市"
265 265
                 $state = $preg[1] ? $preg[1] : ($preg[2] ? $preg[2] : $preg[3]);
266 266
                 $city = $preg[3];
267
-            } else if (count($preg) == 7) { //匹配 "浙江省杭州市江干区"
267
+            }else if (count($preg) == 7) { //匹配 "浙江省杭州市江干区"
268 268
                 $state = $preg[1] ? $preg[1] : ($preg[2] ? $preg[2] : $preg[3]);
269 269
                 $city = $preg[3];
270 270
                 $area = $preg[5];
271
-            } else if (count($preg) == 3) { //匹配 "香港"
271
+            }else if (count($preg) == 3) { //匹配 "香港"
272 272
                 $state = $preg[1] ? $preg[1] : $preg[2];
273 273
                 $city = $state;
274
-            } else if (count($preg) == 2) {  //匹配 "浙江省"
274
+            }else if (count($preg) == 2) {  //匹配 "浙江省"
275 275
                 $state = $preg[1] ? $preg[1] : $this->unknown;
276 276
             }
277 277
         }
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
     private function getLong3()
297 297
     {
298 298
         //将读取的little-endian编码的3个字节转化为长整型数
299
-        $result = unpack('Vlong', fread($this->fp, 3) . chr(0));
299
+        $result = unpack('Vlong', fread($this->fp, 3).chr(0));
300 300
         return $result['long'];
301 301
     }
302 302
 
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
     {
324 324
         $char = fread($this->fp, 1);
325 325
         while (ord($char) > 0) {        // 字符串按照C格式保存,以\0结束
326
-            $data .= $char;             // 将读取的字符连接到给定字符串之后
326
+            $data .= $char; // 将读取的字符连接到给定字符串之后
327 327
             $char = fread($this->fp, 1);
328 328
         }
329 329
         return $data;
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
      */
336 336
     private function getExtendString()
337 337
     {
338
-        $byte = fread($this->fp, 1);    // 标志字节
338
+        $byte = fread($this->fp, 1); // 标志字节
339 339
         switch (ord($byte)) {
340 340
             case 0:                     // 没有区域信息
341 341
                 $area = "";
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
                 }
383 383
                 $IPParts[$i] = str_pad(decHex($IPPart), 2, '0', STR_PAD_LEFT);
384 384
             }
385
-            return '0000:0000:0000:0000:0000:ffff:' . $IPParts[1] . $IPParts[2] . ':' . $IPParts[3] . $IPParts[4];
385
+            return '0000:0000:0000:0000:0000:ffff:'.$IPParts[1].$IPParts[2].':'.$IPParts[3].$IPParts[4];
386 386
         }
387 387
         return '';
388 388
     }
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
         $district['lng'] = '';
415 415
 
416 416
         if (!empty($province_name)) {
417
-            $json_province = json_decode(file_get_contents(__DIR__ . '/bin/province.json'), true);
417
+            $json_province = json_decode(file_get_contents(__DIR__.'/bin/province.json'), true);
418 418
             foreach ($json_province['rows'] as $key => $value) {
419 419
                 if ($value['name'] == $province_name) {
420 420
                     $province['name'] = $value['name'];
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
             }
426 426
         }
427 427
         if (!empty($city_name)) {
428
-            $json_city = json_decode(file_get_contents(__DIR__ . '/bin/city.json'), true);
428
+            $json_city = json_decode(file_get_contents(__DIR__.'/bin/city.json'), true);
429 429
             foreach ($json_city['rows'] as $key => $value) {
430 430
                 if ($value['name'] == $city_name) {
431 431
                     $city['name'] = $value['name'];
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
             }
437 437
         }
438 438
         if (!empty($district_name)) {
439
-            $json_district = json_decode(file_get_contents(__DIR__ . '/bin/district.json'), true);
439
+            $json_district = json_decode(file_get_contents(__DIR__.'/bin/district.json'), true);
440 440
             foreach ($json_district['rows'] as $key => $value) {
441 441
                 if ($value['name'] == $district_name) {
442 442
                     $district['name'] = $value['name'];
Please login to merge, or discard this patch.
src/service/Ip/IpIpService.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@
 block discarded – undo
42 42
      */
43 43
     public function __construct(App $app)
44 44
     {
45
-        $this->reader = new IpIpReader(__DIR__ . '../bin/ipipfree.ipdb');
45
+        $this->reader = new IpIpReader(__DIR__.'../bin/ipipfree.ipdb');
46 46
         parent::__construct($app);
47 47
     }
48 48
 
Please login to merge, or discard this patch.
src/service/taobao/bin/dingtalk/DingTalkClient.php 3 patches
Indentation   +322 added lines, -322 removed lines patch added patch discarded remove patch
@@ -1,27 +1,27 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 class DingTalkClient
3 3
 {
4
-	/**@Author chaohui.zch copy from TopClient and modify 2016-12-14 **/
4
+    /**@Author chaohui.zch copy from TopClient and modify 2016-12-14 **/
5 5
 
6 6
     /**@Author chaohui.zch modify $gatewayUrl 2017-07-18 **/
7 7
     public $gatewayUrl = "https://eco.taobao.com/router/rest";
8 8
 
9
-	public $format = "xml";
9
+    public $format = "xml";
10 10
 
11
-	public $connectTimeout;
11
+    public $connectTimeout;
12 12
 
13
-	public $readTimeout;
13
+    public $readTimeout;
14 14
 
15 15
     public $apiCallType;
16 16
 
17 17
     public $httpMethod;
18 18
 
19
-	/** 是否打开入参check**/
20
-	public $checkRequest = true;
19
+    /** 是否打开入参check**/
20
+    public $checkRequest = true;
21 21
 
22
-	protected $apiVersion = "2.0";
22
+    protected $apiVersion = "2.0";
23 23
 
24
-	protected $sdkVersion = "dingtalk-sdk-php-20161214";
24
+    protected $sdkVersion = "dingtalk-sdk-php-20161214";
25 25
 
26 26
     public function __construct($apiCallType = null, $httpMethod = null, $format = "xml"){
27 27
         $this->apiCallType = $apiCallType;
@@ -29,80 +29,80 @@  discard block
 block discarded – undo
29 29
         $this->format = $format;
30 30
     }
31 31
 
32
-	public function curl($url, $postFields = null)
33
-	{
34
-		$ch = curl_init();
35
-		curl_setopt($ch, CURLOPT_URL, $url);
36
-		curl_setopt($ch, CURLOPT_FAILONERROR, false);
37
-		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
38
-		if ($this->readTimeout) {
39
-			curl_setopt($ch, CURLOPT_TIMEOUT, $this->readTimeout);
40
-		}
41
-		if ($this->connectTimeout) {
42
-			curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
43
-		}
44
-		curl_setopt ( $ch, CURLOPT_USERAGENT, "dingtalk-sdk-php" );
45
-		//https 请求
46
-		if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" ) {
47
-			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
48
-			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
49
-		}
50
-
51
-		if (is_array($postFields) && 0 < count($postFields))
52
-		{
53
-			$postBodyString = "";
54
-			$postMultipart = false;
55
-			foreach ($postFields as $k => $v)
56
-			{
57
-				if("@" != substr($v, 0, 1))//判断是不是文件上传
58
-				{
59
-					$postBodyString .= "$k=" . urlencode($v) . "&"; 
60
-				}
61
-				else//文件上传用multipart/form-data,否则用www-form-urlencoded
62
-				{
63
-					$postMultipart = true;
64
-					if(class_exists('\CURLFile')){
65
-						$postFields[$k] = new \CURLFile(substr($v, 1));
66
-					}
67
-				}
68
-			}
69
-			unset($k, $v);
70
-			curl_setopt($ch, CURLOPT_POST, true);
71
-			if ($postMultipart)
72
-			{
73
-				if (class_exists('\CURLFile')) {
74
-				    curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
75
-				} else {
76
-				    if (defined('CURLOPT_SAFE_UPLOAD')) {
77
-				        curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
78
-				    }
79
-				}
80
-				curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
81
-			}
82
-			else
83
-			{
84
-				$header = array("content-type: application/x-www-form-urlencoded; charset=UTF-8");
85
-				curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
86
-				curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString,0,-1));
87
-			}
88
-		}
89
-		$reponse = curl_exec($ch);
32
+    public function curl($url, $postFields = null)
33
+    {
34
+        $ch = curl_init();
35
+        curl_setopt($ch, CURLOPT_URL, $url);
36
+        curl_setopt($ch, CURLOPT_FAILONERROR, false);
37
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
38
+        if ($this->readTimeout) {
39
+            curl_setopt($ch, CURLOPT_TIMEOUT, $this->readTimeout);
40
+        }
41
+        if ($this->connectTimeout) {
42
+            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
43
+        }
44
+        curl_setopt ( $ch, CURLOPT_USERAGENT, "dingtalk-sdk-php" );
45
+        //https 请求
46
+        if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" ) {
47
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
48
+            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
49
+        }
50
+
51
+        if (is_array($postFields) && 0 < count($postFields))
52
+        {
53
+            $postBodyString = "";
54
+            $postMultipart = false;
55
+            foreach ($postFields as $k => $v)
56
+            {
57
+                if("@" != substr($v, 0, 1))//判断是不是文件上传
58
+                {
59
+                    $postBodyString .= "$k=" . urlencode($v) . "&"; 
60
+                }
61
+                else//文件上传用multipart/form-data,否则用www-form-urlencoded
62
+                {
63
+                    $postMultipart = true;
64
+                    if(class_exists('\CURLFile')){
65
+                        $postFields[$k] = new \CURLFile(substr($v, 1));
66
+                    }
67
+                }
68
+            }
69
+            unset($k, $v);
70
+            curl_setopt($ch, CURLOPT_POST, true);
71
+            if ($postMultipart)
72
+            {
73
+                if (class_exists('\CURLFile')) {
74
+                    curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
75
+                } else {
76
+                    if (defined('CURLOPT_SAFE_UPLOAD')) {
77
+                        curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
78
+                    }
79
+                }
80
+                curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
81
+            }
82
+            else
83
+            {
84
+                $header = array("content-type: application/x-www-form-urlencoded; charset=UTF-8");
85
+                curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
86
+                curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString,0,-1));
87
+            }
88
+        }
89
+        $reponse = curl_exec($ch);
90 90
 		
91
-		if (curl_errno($ch))
92
-		{
93
-			throw new Exception(curl_error($ch),0);
94
-		}
95
-		else
96
-		{
97
-			$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
98
-			if (200 !== $httpStatusCode)
99
-			{
100
-				throw new Exception($reponse,$httpStatusCode);
101
-			}
102
-		}
103
-		curl_close($ch);
104
-		return $reponse;
105
-	}
91
+        if (curl_errno($ch))
92
+        {
93
+            throw new Exception(curl_error($ch),0);
94
+        }
95
+        else
96
+        {
97
+            $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
98
+            if (200 !== $httpStatusCode)
99
+            {
100
+                throw new Exception($reponse,$httpStatusCode);
101
+            }
102
+        }
103
+        curl_close($ch);
104
+        return $reponse;
105
+    }
106 106
 
107 107
     public function curl_get($url,$apiFields = null)
108 108
     {
@@ -234,97 +234,97 @@  discard block
 block discarded – undo
234 234
         return $reponse;
235 235
     }
236 236
 
237
-	public function curl_with_memory_file($url, $postFields = null, $fileFields = null)
238
-	{
239
-		$ch = curl_init();
240
-		curl_setopt($ch, CURLOPT_URL, $url);
241
-		curl_setopt($ch, CURLOPT_FAILONERROR, false);
242
-		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
243
-		if ($this->readTimeout) {
244
-			curl_setopt($ch, CURLOPT_TIMEOUT, $this->readTimeout);
245
-		}
246
-		if ($this->connectTimeout) {
247
-			curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
248
-		}
249
-		curl_setopt ( $ch, CURLOPT_USERAGENT, "dingtalk-sdk-php" );
250
-		//https 请求
251
-		if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" ) {
252
-			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
253
-			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
254
-		}
255
-		//生成分隔符
256
-		$delimiter = '-------------' . uniqid();
257
-		//先将post的普通数据生成主体字符串
258
-		$data = '';
259
-		if($postFields != null){
260
-			foreach ($postFields as $name => $content) {
261
-			    $data .= "--" . $delimiter . "\r\n";
262
-			    $data .= 'Content-Disposition: form-data; name="' . $name . '"';
263
-			    //multipart/form-data 不需要urlencode,参见 http:stackoverflow.com/questions/6603928/should-i-url-encode-post-data
264
-			    $data .= "\r\n\r\n" . $content . "\r\n";
265
-			}
266
-			unset($name,$content);
267
-		}
268
-
269
-		//将上传的文件生成主体字符串
270
-		if($fileFields != null){
271
-			foreach ($fileFields as $name => $file) {
272
-			    $data .= "--" . $delimiter . "\r\n";
273
-			    $data .= 'Content-Disposition: form-data; name="' . $name . '"; filename="' . $file['filename'] . "\" \r\n";
274
-			    $data .= 'Content-Type: ' . $file['type'] . "\r\n\r\n";//多了个文档类型
275
-
276
-			    $data .= $file['content'] . "\r\n";
277
-			}
278
-			unset($name,$file);
279
-		}
280
-		//主体结束的分隔符
281
-		$data .= "--" . $delimiter . "--";
282
-
283
-		curl_setopt($ch, CURLOPT_POST, true);
284
-		curl_setopt($ch, CURLOPT_HTTPHEADER , array(
285
-		    'Content-Type: multipart/form-data; boundary=' . $delimiter,
286
-		    'Content-Length: ' . strlen($data))
287
-		); 
288
-		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
289
-		curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
290
-
291
-		$reponse = curl_exec($ch);
292
-		unset($data);
293
-
294
-		if (curl_errno($ch))
295
-		{
296
-			throw new Exception(curl_error($ch),0);
297
-		}
298
-		else
299
-		{
300
-			$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
301
-			if (200 !== $httpStatusCode)
302
-			{
303
-				throw new Exception($reponse,$httpStatusCode);
304
-			}
305
-		}
306
-		curl_close($ch);
307
-		return $reponse;
308
-	}
309
-
310
-	protected function logCommunicationError($apiName, $requestUrl, $errorCode, $responseTxt)
311
-	{
312
-		$localIp = isset($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : "CLI";
313
-		$logger = new TopLogger;
314
-		$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_comm_err_" . "_" . date("Y-m-d") . ".log";
315
-		$logger->conf["separator"] = "^_^";
316
-		$logData = array(
317
-		date("Y-m-d H:i:s"),
318
-		$apiName,
319
-		$localIp,
320
-		PHP_OS,
321
-		$this->sdkVersion,
322
-		$requestUrl,
323
-		$errorCode,
324
-		str_replace("\n","",$responseTxt)
325
-		);
326
-		$logger->log($logData);
327
-	}
237
+    public function curl_with_memory_file($url, $postFields = null, $fileFields = null)
238
+    {
239
+        $ch = curl_init();
240
+        curl_setopt($ch, CURLOPT_URL, $url);
241
+        curl_setopt($ch, CURLOPT_FAILONERROR, false);
242
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
243
+        if ($this->readTimeout) {
244
+            curl_setopt($ch, CURLOPT_TIMEOUT, $this->readTimeout);
245
+        }
246
+        if ($this->connectTimeout) {
247
+            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
248
+        }
249
+        curl_setopt ( $ch, CURLOPT_USERAGENT, "dingtalk-sdk-php" );
250
+        //https 请求
251
+        if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" ) {
252
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
253
+            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
254
+        }
255
+        //生成分隔符
256
+        $delimiter = '-------------' . uniqid();
257
+        //先将post的普通数据生成主体字符串
258
+        $data = '';
259
+        if($postFields != null){
260
+            foreach ($postFields as $name => $content) {
261
+                $data .= "--" . $delimiter . "\r\n";
262
+                $data .= 'Content-Disposition: form-data; name="' . $name . '"';
263
+                //multipart/form-data 不需要urlencode,参见 http:stackoverflow.com/questions/6603928/should-i-url-encode-post-data
264
+                $data .= "\r\n\r\n" . $content . "\r\n";
265
+            }
266
+            unset($name,$content);
267
+        }
268
+
269
+        //将上传的文件生成主体字符串
270
+        if($fileFields != null){
271
+            foreach ($fileFields as $name => $file) {
272
+                $data .= "--" . $delimiter . "\r\n";
273
+                $data .= 'Content-Disposition: form-data; name="' . $name . '"; filename="' . $file['filename'] . "\" \r\n";
274
+                $data .= 'Content-Type: ' . $file['type'] . "\r\n\r\n";//多了个文档类型
275
+
276
+                $data .= $file['content'] . "\r\n";
277
+            }
278
+            unset($name,$file);
279
+        }
280
+        //主体结束的分隔符
281
+        $data .= "--" . $delimiter . "--";
282
+
283
+        curl_setopt($ch, CURLOPT_POST, true);
284
+        curl_setopt($ch, CURLOPT_HTTPHEADER , array(
285
+            'Content-Type: multipart/form-data; boundary=' . $delimiter,
286
+            'Content-Length: ' . strlen($data))
287
+        ); 
288
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
289
+        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
290
+
291
+        $reponse = curl_exec($ch);
292
+        unset($data);
293
+
294
+        if (curl_errno($ch))
295
+        {
296
+            throw new Exception(curl_error($ch),0);
297
+        }
298
+        else
299
+        {
300
+            $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
301
+            if (200 !== $httpStatusCode)
302
+            {
303
+                throw new Exception($reponse,$httpStatusCode);
304
+            }
305
+        }
306
+        curl_close($ch);
307
+        return $reponse;
308
+    }
309
+
310
+    protected function logCommunicationError($apiName, $requestUrl, $errorCode, $responseTxt)
311
+    {
312
+        $localIp = isset($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : "CLI";
313
+        $logger = new TopLogger;
314
+        $logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_comm_err_" . "_" . date("Y-m-d") . ".log";
315
+        $logger->conf["separator"] = "^_^";
316
+        $logData = array(
317
+        date("Y-m-d H:i:s"),
318
+        $apiName,
319
+        $localIp,
320
+        PHP_OS,
321
+        $this->sdkVersion,
322
+        $requestUrl,
323
+        $errorCode,
324
+        str_replace("\n","",$responseTxt)
325
+        );
326
+        $logger->log($logData);
327
+    }
328 328
 
329 329
     public function execute($request, $session = null,$bestUrl = null){
330 330
         if(DingTalkConstant::$CALL_TYPE_OAPI == $this->apiCallType){
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
         return $this->executeWithCorpId($request,$bestUrl, $accessKey, $accessSecret, $suiteTicket, null);
343 343
     }
344 344
 
345
-	public function executeWithCorpId($request, $bestUrl = null, $accessKey, $accessSecret, $suiteTicket, $corpId) {
345
+    public function executeWithCorpId($request, $bestUrl = null, $accessKey, $accessSecret, $suiteTicket, $corpId) {
346 346
         if(DingTalkConstant::$CALL_TYPE_OAPI == $this->apiCallType){
347 347
             return $this->_executeOapi($request, null, $bestUrl,$accessKey, $accessSecret, $suiteTicket, $corpId);
348 348
         }else{
@@ -494,160 +494,160 @@  discard block
 block discarded – undo
494 494
     }
495 495
 
496 496
     private function _execute($request, $session = null,$bestUrl = null)
497
-	{
498
-		$result =  new ResultSet(); 
499
-		if($this->checkRequest) {
500
-			try {
501
-				$request->check();
502
-			} catch (Exception $e) {
503
-
504
-				$result->code = $e->getCode();
505
-				$result->msg = $e->getMessage();
506
-				return $result;
507
-			}
508
-		}
509
-		//组装系统参数
510
-		$sysParams["v"] = $this->apiVersion;
511
-		$sysParams["format"] = $this->format;
512
-		$sysParams["method"] = $request->getApiMethodName();
513
-		$sysParams["timestamp"] = date("Y-m-d H:i:s");
514
-		if (null != $session)
515
-		{
516
-			$sysParams["session"] = $session;
517
-		}
518
-		$apiParams = array();
519
-		//获取业务参数
520
-		$apiParams = $request->getApiParas();
521
-
522
-
523
-		//系统参数放入GET请求串
524
-		if($bestUrl){
497
+    {
498
+        $result =  new ResultSet(); 
499
+        if($this->checkRequest) {
500
+            try {
501
+                $request->check();
502
+            } catch (Exception $e) {
503
+
504
+                $result->code = $e->getCode();
505
+                $result->msg = $e->getMessage();
506
+                return $result;
507
+            }
508
+        }
509
+        //组装系统参数
510
+        $sysParams["v"] = $this->apiVersion;
511
+        $sysParams["format"] = $this->format;
512
+        $sysParams["method"] = $request->getApiMethodName();
513
+        $sysParams["timestamp"] = date("Y-m-d H:i:s");
514
+        if (null != $session)
515
+        {
516
+            $sysParams["session"] = $session;
517
+        }
518
+        $apiParams = array();
519
+        //获取业务参数
520
+        $apiParams = $request->getApiParas();
521
+
522
+
523
+        //系统参数放入GET请求串
524
+        if($bestUrl){
525 525
             if(strpos($bestUrl,'?') === false){
526 526
                 $requestUrl = $bestUrl."?";
527 527
             }else{
528 528
                 $requestUrl = $bestUrl;
529 529
             }
530
-			$sysParams["partner_id"] = $this->getClusterTag();
531
-		}else{
532
-			$requestUrl = $this->gatewayUrl."?";
533
-			$sysParams["partner_id"] = $this->sdkVersion;
534
-		}
535
-
536
-		foreach ($sysParams as $sysParamKey => $sysParamValue)
537
-		{
538
-			// if(strcmp($sysParamKey,"timestamp") != 0)
539
-			$requestUrl .= "$sysParamKey=" . urlencode($sysParamValue) . "&";
540
-		}
541
-
542
-		$fileFields = array();
543
-		foreach ($apiParams as $key => $value) {
544
-			if(is_array($value) && array_key_exists('type',$value) && array_key_exists('content',$value) ){
545
-				$value['name'] = $key;
546
-				$fileFields[$key] = $value;
547
-				unset($apiParams[$key]);
548
-			}
549
-		}
550
-
551
-		// $requestUrl .= "timestamp=" . urlencode($sysParams["timestamp"]) . "&";
552
-		$requestUrl = substr($requestUrl, 0, -1);
553
-
554
-		//发起HTTP请求
555
-		try
556
-		{
557
-			if(count($fileFields) > 0){
558
-				$resp = $this->curl_with_memory_file($requestUrl, $apiParams, $fileFields);
559
-			}else{
560
-				$resp = $this->curl($requestUrl, $apiParams);
561
-			}
562
-		}
563
-		catch (Exception $e)
564
-		{
565
-			$this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_ERROR_" . $e->getCode(),$e->getMessage());
566
-			$result->code = $e->getCode();
567
-			$result->msg = $e->getMessage();
568
-			return $result;
569
-		}
570
-
571
-		unset($apiParams);
572
-		unset($fileFields);
573
-		//解析TOP返回结果
574
-		$respWellFormed = false;
575
-		if ("json" == $this->format)
576
-		{
577
-			$respObject = json_decode($resp);
578
-			if (null !== $respObject)
579
-			{
580
-				$respWellFormed = true;
581
-				foreach ($respObject as $propKey => $propValue)
582
-				{
583
-					$respObject = $propValue;
584
-				}
585
-			}
586
-		}
587
-		else if("xml" == $this->format)
588
-		{
589
-			$respObject = @simplexml_load_string($resp);
590
-			if (false !== $respObject)
591
-			{
592
-				$respWellFormed = true;
593
-			}
594
-		}
595
-
596
-		//返回的HTTP文本不是标准JSON或者XML,记下错误日志
597
-		if (false === $respWellFormed)
598
-		{
599
-			$this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_RESPONSE_NOT_WELL_FORMED",$resp);
600
-			$result->code = 0;
601
-			$result->msg = "HTTP_RESPONSE_NOT_WELL_FORMED";
602
-			return $result;
603
-		}
604
-
605
-		//如果TOP返回了错误码,记录到业务错误日志中
606
-		if (isset($respObject->code))
607
-		{
608
-			$logger = new TopLogger;
609
-			$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_biz_err_" .  "_" . date("Y-m-d") . ".log";
610
-			$logger->log(array(
611
-				date("Y-m-d H:i:s"),
612
-				$resp
613
-			));
614
-		}
615
-		return $respObject;
616
-	}
617
-
618
-	public function exec($paramsArray)
619
-	{
620
-		if (!isset($paramsArray["method"]))
621
-		{
622
-			trigger_error("No api name passed");
623
-		}
624
-		$inflector = new LtInflector;
625
-		$inflector->conf["separator"] = ".";
626
-		$requestClassName = ucfirst($inflector->camelize(substr($paramsArray["method"], 7))) . "Request";
627
-		if (!class_exists($requestClassName))
628
-		{
629
-			trigger_error("No such dingtalk-api: " . $paramsArray["method"]);
630
-		}
631
-
632
-		$session = isset($paramsArray["session"]) ? $paramsArray["session"] : null;
633
-
634
-		$req = new $requestClassName;
635
-		foreach($paramsArray as $paraKey => $paraValue)
636
-		{
637
-			$inflector->conf["separator"] = "_";
638
-			$setterMethodName = $inflector->camelize($paraKey);
639
-			$inflector->conf["separator"] = ".";
640
-			$setterMethodName = "set" . $inflector->camelize($setterMethodName);
641
-			if (method_exists($req, $setterMethodName))
642
-			{
643
-				$req->$setterMethodName($paraValue);
644
-			}
645
-		}
646
-		return $this->execute($req, $session);
647
-	}
648
-
649
-	private function getClusterTag()
530
+            $sysParams["partner_id"] = $this->getClusterTag();
531
+        }else{
532
+            $requestUrl = $this->gatewayUrl."?";
533
+            $sysParams["partner_id"] = $this->sdkVersion;
534
+        }
535
+
536
+        foreach ($sysParams as $sysParamKey => $sysParamValue)
537
+        {
538
+            // if(strcmp($sysParamKey,"timestamp") != 0)
539
+            $requestUrl .= "$sysParamKey=" . urlencode($sysParamValue) . "&";
540
+        }
541
+
542
+        $fileFields = array();
543
+        foreach ($apiParams as $key => $value) {
544
+            if(is_array($value) && array_key_exists('type',$value) && array_key_exists('content',$value) ){
545
+                $value['name'] = $key;
546
+                $fileFields[$key] = $value;
547
+                unset($apiParams[$key]);
548
+            }
549
+        }
550
+
551
+        // $requestUrl .= "timestamp=" . urlencode($sysParams["timestamp"]) . "&";
552
+        $requestUrl = substr($requestUrl, 0, -1);
553
+
554
+        //发起HTTP请求
555
+        try
556
+        {
557
+            if(count($fileFields) > 0){
558
+                $resp = $this->curl_with_memory_file($requestUrl, $apiParams, $fileFields);
559
+            }else{
560
+                $resp = $this->curl($requestUrl, $apiParams);
561
+            }
562
+        }
563
+        catch (Exception $e)
564
+        {
565
+            $this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_ERROR_" . $e->getCode(),$e->getMessage());
566
+            $result->code = $e->getCode();
567
+            $result->msg = $e->getMessage();
568
+            return $result;
569
+        }
570
+
571
+        unset($apiParams);
572
+        unset($fileFields);
573
+        //解析TOP返回结果
574
+        $respWellFormed = false;
575
+        if ("json" == $this->format)
576
+        {
577
+            $respObject = json_decode($resp);
578
+            if (null !== $respObject)
579
+            {
580
+                $respWellFormed = true;
581
+                foreach ($respObject as $propKey => $propValue)
582
+                {
583
+                    $respObject = $propValue;
584
+                }
585
+            }
586
+        }
587
+        else if("xml" == $this->format)
588
+        {
589
+            $respObject = @simplexml_load_string($resp);
590
+            if (false !== $respObject)
591
+            {
592
+                $respWellFormed = true;
593
+            }
594
+        }
595
+
596
+        //返回的HTTP文本不是标准JSON或者XML,记下错误日志
597
+        if (false === $respWellFormed)
598
+        {
599
+            $this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_RESPONSE_NOT_WELL_FORMED",$resp);
600
+            $result->code = 0;
601
+            $result->msg = "HTTP_RESPONSE_NOT_WELL_FORMED";
602
+            return $result;
603
+        }
604
+
605
+        //如果TOP返回了错误码,记录到业务错误日志中
606
+        if (isset($respObject->code))
607
+        {
608
+            $logger = new TopLogger;
609
+            $logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_biz_err_" .  "_" . date("Y-m-d") . ".log";
610
+            $logger->log(array(
611
+                date("Y-m-d H:i:s"),
612
+                $resp
613
+            ));
614
+        }
615
+        return $respObject;
616
+    }
617
+
618
+    public function exec($paramsArray)
619
+    {
620
+        if (!isset($paramsArray["method"]))
621
+        {
622
+            trigger_error("No api name passed");
623
+        }
624
+        $inflector = new LtInflector;
625
+        $inflector->conf["separator"] = ".";
626
+        $requestClassName = ucfirst($inflector->camelize(substr($paramsArray["method"], 7))) . "Request";
627
+        if (!class_exists($requestClassName))
628
+        {
629
+            trigger_error("No such dingtalk-api: " . $paramsArray["method"]);
630
+        }
631
+
632
+        $session = isset($paramsArray["session"]) ? $paramsArray["session"] : null;
633
+
634
+        $req = new $requestClassName;
635
+        foreach($paramsArray as $paraKey => $paraValue)
636
+        {
637
+            $inflector->conf["separator"] = "_";
638
+            $setterMethodName = $inflector->camelize($paraKey);
639
+            $inflector->conf["separator"] = ".";
640
+            $setterMethodName = "set" . $inflector->camelize($setterMethodName);
641
+            if (method_exists($req, $setterMethodName))
642
+            {
643
+                $req->$setterMethodName($paraValue);
644
+            }
645
+        }
646
+        return $this->execute($req, $session);
647
+    }
648
+
649
+    private function getClusterTag()
650 650
     {
651
-	    return substr($this->sdkVersion,0,11)."-cluster".substr($this->sdkVersion,11);
651
+        return substr($this->sdkVersion,0,11)."-cluster".substr($this->sdkVersion,11);
652 652
     }
653 653
 }
Please login to merge, or discard this patch.
Spacing   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 
24 24
 	protected $sdkVersion = "dingtalk-sdk-php-20161214";
25 25
 
26
-    public function __construct($apiCallType = null, $httpMethod = null, $format = "xml"){
26
+    public function __construct($apiCallType = null, $httpMethod = null, $format = "xml") {
27 27
         $this->apiCallType = $apiCallType;
28 28
         $this->httpMethod = $httpMethod;
29 29
         $this->format = $format;
@@ -41,9 +41,9 @@  discard block
 block discarded – undo
41 41
 		if ($this->connectTimeout) {
42 42
 			curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
43 43
 		}
44
-		curl_setopt ( $ch, CURLOPT_USERAGENT, "dingtalk-sdk-php" );
44
+		curl_setopt($ch, CURLOPT_USERAGENT, "dingtalk-sdk-php");
45 45
 		//https 请求
46
-		if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" ) {
46
+		if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") {
47 47
 			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
48 48
 			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
49 49
 		}
@@ -54,14 +54,14 @@  discard block
 block discarded – undo
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
-					$postBodyString .= "$k=" . urlencode($v) . "&"; 
59
+					$postBodyString .= "$k=".urlencode($v)."&"; 
60 60
 				}
61 61
 				else//文件上传用multipart/form-data,否则用www-form-urlencoded
62 62
 				{
63 63
 					$postMultipart = true;
64
-					if(class_exists('\CURLFile')){
64
+					if (class_exists('\CURLFile')) {
65 65
 						$postFields[$k] = new \CURLFile(substr($v, 1));
66 66
 					}
67 67
 				}
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 			{
73 73
 				if (class_exists('\CURLFile')) {
74 74
 				    curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
75
-				} else {
75
+				}else {
76 76
 				    if (defined('CURLOPT_SAFE_UPLOAD')) {
77 77
 				        curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
78 78
 				    }
@@ -82,35 +82,35 @@  discard block
 block discarded – undo
82 82
 			else
83 83
 			{
84 84
 				$header = array("content-type: application/x-www-form-urlencoded; charset=UTF-8");
85
-				curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
86
-				curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString,0,-1));
85
+				curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
86
+				curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString, 0, -1));
87 87
 			}
88 88
 		}
89 89
 		$reponse = curl_exec($ch);
90 90
 		
91 91
 		if (curl_errno($ch))
92 92
 		{
93
-			throw new Exception(curl_error($ch),0);
93
+			throw new Exception(curl_error($ch), 0);
94 94
 		}
95 95
 		else
96 96
 		{
97 97
 			$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
98 98
 			if (200 !== $httpStatusCode)
99 99
 			{
100
-				throw new Exception($reponse,$httpStatusCode);
100
+				throw new Exception($reponse, $httpStatusCode);
101 101
 			}
102 102
 		}
103 103
 		curl_close($ch);
104 104
 		return $reponse;
105 105
 	}
106 106
 
107
-    public function curl_get($url,$apiFields = null)
107
+    public function curl_get($url, $apiFields = null)
108 108
     {
109 109
         $ch = curl_init();
110 110
 
111 111
         foreach ($apiFields as $key => $value)
112 112
         {
113
-            $url .= "&" ."$key=" . urlencode($value);
113
+            $url .= "&"."$key=".urlencode($value);
114 114
         }
115 115
 
116 116
         curl_setopt($ch, CURLOPT_URL, $url);
@@ -130,10 +130,10 @@  discard block
 block discarded – undo
130 130
             curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
131 131
         }
132 132
 
133
-        curl_setopt ( $ch, CURLOPT_USERAGENT, "dingtalk-sdk-php" );
133
+        curl_setopt($ch, CURLOPT_USERAGENT, "dingtalk-sdk-php");
134 134
 
135 135
         //https ignore ssl check ?
136
-        if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" )
136
+        if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https")
137 137
         {
138 138
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
139 139
             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
@@ -143,14 +143,14 @@  discard block
 block discarded – undo
143 143
 
144 144
         if (curl_errno($ch))
145 145
         {
146
-            throw new Exception(curl_error($ch),0);
146
+            throw new Exception(curl_error($ch), 0);
147 147
         }
148 148
         else
149 149
         {
150 150
             $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
151 151
             if (200 !== $httpStatusCode)
152 152
             {
153
-                throw new Exception($reponse,$httpStatusCode);
153
+                throw new Exception($reponse, $httpStatusCode);
154 154
             }
155 155
         }
156 156
         curl_close($ch);
@@ -169,9 +169,9 @@  discard block
 block discarded – undo
169 169
         if ($this->connectTimeout) {
170 170
             curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
171 171
         }
172
-        curl_setopt ( $ch, CURLOPT_USERAGENT, "dingtalk-sdk-php" );
172
+        curl_setopt($ch, CURLOPT_USERAGENT, "dingtalk-sdk-php");
173 173
         //https 请求
174
-        if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" ) {
174
+        if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") {
175 175
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
176 176
             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
177 177
         }
@@ -182,17 +182,17 @@  discard block
 block discarded – undo
182 182
             $postMultipart = false;
183 183
             foreach ($postFields as $k => $v)
184 184
             {
185
-                if(!is_string($v)){
185
+                if (!is_string($v)) {
186 186
                     $v = json_encode($v);
187 187
                 }
188
-                if("@" != substr($v, 0, 1))//判断是不是文件上传
188
+                if ("@" != substr($v, 0, 1))//判断是不是文件上传
189 189
                 {
190
-                    $postBodyString .= "$k=" . urlencode($v) . "&";
190
+                    $postBodyString .= "$k=".urlencode($v)."&";
191 191
                 }
192 192
                 else//文件上传用multipart/form-data,否则用www-form-urlencoded
193 193
                 {
194 194
                     $postMultipart = true;
195
-                    if(class_exists('\CURLFile')){
195
+                    if (class_exists('\CURLFile')) {
196 196
                         $postFields[$k] = new \CURLFile(substr($v, 1));
197 197
                     }
198 198
                 }
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
             {
204 204
                 if (class_exists('\CURLFile')) {
205 205
                     curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
206
-                } else {
206
+                }else {
207 207
                     if (defined('CURLOPT_SAFE_UPLOAD')) {
208 208
                         curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
209 209
                     }
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
             }
213 213
             else {
214 214
                 $header = array("Content-Type: application/json; charset=utf-8", "Content-Length:".strlen(json_encode($postFields)));
215
-                curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
215
+                curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
216 216
                 curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postFields));
217 217
             }
218 218
         }
@@ -220,14 +220,14 @@  discard block
 block discarded – undo
220 220
 
221 221
         if (curl_errno($ch))
222 222
         {
223
-            throw new Exception(curl_error($ch),0);
223
+            throw new Exception(curl_error($ch), 0);
224 224
         }
225 225
         else
226 226
         {
227 227
             $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
228 228
             if (200 !== $httpStatusCode)
229 229
             {
230
-                throw new Exception($reponse,$httpStatusCode);
230
+                throw new Exception($reponse, $httpStatusCode);
231 231
             }
232 232
         }
233 233
         curl_close($ch);
@@ -246,44 +246,44 @@  discard block
 block discarded – undo
246 246
 		if ($this->connectTimeout) {
247 247
 			curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
248 248
 		}
249
-		curl_setopt ( $ch, CURLOPT_USERAGENT, "dingtalk-sdk-php" );
249
+		curl_setopt($ch, CURLOPT_USERAGENT, "dingtalk-sdk-php");
250 250
 		//https 请求
251
-		if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" ) {
251
+		if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") {
252 252
 			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
253 253
 			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
254 254
 		}
255 255
 		//生成分隔符
256
-		$delimiter = '-------------' . uniqid();
256
+		$delimiter = '-------------'.uniqid();
257 257
 		//先将post的普通数据生成主体字符串
258 258
 		$data = '';
259
-		if($postFields != null){
259
+		if ($postFields != null) {
260 260
 			foreach ($postFields as $name => $content) {
261
-			    $data .= "--" . $delimiter . "\r\n";
262
-			    $data .= 'Content-Disposition: form-data; name="' . $name . '"';
261
+			    $data .= "--".$delimiter."\r\n";
262
+			    $data .= 'Content-Disposition: form-data; name="'.$name.'"';
263 263
 			    //multipart/form-data 不需要urlencode,参见 http:stackoverflow.com/questions/6603928/should-i-url-encode-post-data
264
-			    $data .= "\r\n\r\n" . $content . "\r\n";
264
+			    $data .= "\r\n\r\n".$content."\r\n";
265 265
 			}
266
-			unset($name,$content);
266
+			unset($name, $content);
267 267
 		}
268 268
 
269 269
 		//将上传的文件生成主体字符串
270
-		if($fileFields != null){
270
+		if ($fileFields != null) {
271 271
 			foreach ($fileFields as $name => $file) {
272
-			    $data .= "--" . $delimiter . "\r\n";
273
-			    $data .= 'Content-Disposition: form-data; name="' . $name . '"; filename="' . $file['filename'] . "\" \r\n";
274
-			    $data .= 'Content-Type: ' . $file['type'] . "\r\n\r\n";//多了个文档类型
272
+			    $data .= "--".$delimiter."\r\n";
273
+			    $data .= 'Content-Disposition: form-data; name="'.$name.'"; filename="'.$file['filename']."\" \r\n";
274
+			    $data .= 'Content-Type: '.$file['type']."\r\n\r\n"; //多了个文档类型
275 275
 
276
-			    $data .= $file['content'] . "\r\n";
276
+			    $data .= $file['content']."\r\n";
277 277
 			}
278
-			unset($name,$file);
278
+			unset($name, $file);
279 279
 		}
280 280
 		//主体结束的分隔符
281
-		$data .= "--" . $delimiter . "--";
281
+		$data .= "--".$delimiter."--";
282 282
 
283 283
 		curl_setopt($ch, CURLOPT_POST, true);
284
-		curl_setopt($ch, CURLOPT_HTTPHEADER , array(
285
-		    'Content-Type: multipart/form-data; boundary=' . $delimiter,
286
-		    'Content-Length: ' . strlen($data))
284
+		curl_setopt($ch, CURLOPT_HTTPHEADER, array(
285
+		    'Content-Type: multipart/form-data; boundary='.$delimiter,
286
+		    'Content-Length: '.strlen($data))
287 287
 		); 
288 288
 		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
289 289
 		curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
@@ -293,14 +293,14 @@  discard block
 block discarded – undo
293 293
 
294 294
 		if (curl_errno($ch))
295 295
 		{
296
-			throw new Exception(curl_error($ch),0);
296
+			throw new Exception(curl_error($ch), 0);
297 297
 		}
298 298
 		else
299 299
 		{
300 300
 			$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
301 301
 			if (200 !== $httpStatusCode)
302 302
 			{
303
-				throw new Exception($reponse,$httpStatusCode);
303
+				throw new Exception($reponse, $httpStatusCode);
304 304
 			}
305 305
 		}
306 306
 		curl_close($ch);
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
 	{
312 312
 		$localIp = isset($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : "CLI";
313 313
 		$logger = new TopLogger;
314
-		$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_comm_err_" . "_" . date("Y-m-d") . ".log";
314
+		$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/').'/'."logs/top_comm_err_"."_".date("Y-m-d").".log";
315 315
 		$logger->conf["separator"] = "^_^";
316 316
 		$logData = array(
317 317
 		date("Y-m-d H:i:s"),
@@ -321,38 +321,38 @@  discard block
 block discarded – undo
321 321
 		$this->sdkVersion,
322 322
 		$requestUrl,
323 323
 		$errorCode,
324
-		str_replace("\n","",$responseTxt)
324
+		str_replace("\n", "", $responseTxt)
325 325
 		);
326 326
 		$logger->log($logData);
327 327
 	}
328 328
 
329
-    public function execute($request, $session = null,$bestUrl = null){
330
-        if(DingTalkConstant::$CALL_TYPE_OAPI == $this->apiCallType){
329
+    public function execute($request, $session = null, $bestUrl = null) {
330
+        if (DingTalkConstant::$CALL_TYPE_OAPI == $this->apiCallType) {
331 331
             return $this->_executeOapi($request, $session, $bestUrl, null, null, null, null);
332
-        }else{
332
+        }else {
333 333
             return $this->_execute($request, $session, $bestUrl);
334 334
         }
335 335
     }
336 336
 
337
-    public function executeWithAccessKey($request, $bestUrl = null, $accessKey, $accessSecret){
337
+    public function executeWithAccessKey($request, $bestUrl = null, $accessKey, $accessSecret) {
338 338
         return $this->executeWithCorpId($request, $bestUrl, $accessKey, $accessSecret, null, null);
339 339
     }
340 340
 
341
-    public function executeWithSuiteTicket($request,$bestUrl = null, $accessKey, $accessSecret, $suiteTicket){
342
-        return $this->executeWithCorpId($request,$bestUrl, $accessKey, $accessSecret, $suiteTicket, null);
341
+    public function executeWithSuiteTicket($request, $bestUrl = null, $accessKey, $accessSecret, $suiteTicket) {
342
+        return $this->executeWithCorpId($request, $bestUrl, $accessKey, $accessSecret, $suiteTicket, null);
343 343
     }
344 344
 
345 345
 	public function executeWithCorpId($request, $bestUrl = null, $accessKey, $accessSecret, $suiteTicket, $corpId) {
346
-        if(DingTalkConstant::$CALL_TYPE_OAPI == $this->apiCallType){
347
-            return $this->_executeOapi($request, null, $bestUrl,$accessKey, $accessSecret, $suiteTicket, $corpId);
348
-        }else{
346
+        if (DingTalkConstant::$CALL_TYPE_OAPI == $this->apiCallType) {
347
+            return $this->_executeOapi($request, null, $bestUrl, $accessKey, $accessSecret, $suiteTicket, $corpId);
348
+        }else {
349 349
             return $this->_execute($request, null, $bestUrl);
350 350
         }
351 351
     }
352 352
 
353
-    private function _executeOapi($request, $session = null,$bestUrl = null,$accessKey, $accessSecret, $suiteTicket, $corpId){
354
-        $result =  new ResultSet();
355
-        if($this->checkRequest) {
353
+    private function _executeOapi($request, $session = null, $bestUrl = null, $accessKey, $accessSecret, $suiteTicket, $corpId) {
354
+        $result = new ResultSet();
355
+        if ($this->checkRequest) {
356 356
             try {
357 357
                 $request->check();
358 358
             } catch (Exception $e) {
@@ -365,16 +365,16 @@  discard block
 block discarded – undo
365 365
 
366 366
         $sysParams["method"] = $request->getApiMethodName();
367 367
         //系统参数放入GET请求串
368
-        if($bestUrl){
369
-            if(strpos($bestUrl,'?') === false){
368
+        if ($bestUrl) {
369
+            if (strpos($bestUrl, '?') === false) {
370 370
                 $requestUrl = $bestUrl."?";
371
-            }else{
371
+            }else {
372 372
                 $requestUrl = $bestUrl;
373 373
             }
374
-        }else{
374
+        }else {
375 375
             $requestUrl = $this->gatewayUrl."?";
376 376
         }
377
-        if(null != $accessKey){
377
+        if (null != $accessKey) {
378 378
             $timestamp = $this->getMillisecond();
379 379
             // 验证签名有效性
380 380
             $canonicalString = $this->getCanonicalStringForIsv($timestamp, $suiteTicket);
@@ -383,17 +383,17 @@  discard block
 block discarded – undo
383 383
             $queryParams["accessKey"] = $accessKey;
384 384
             $queryParams["signature"] = $signature;
385 385
             $queryParams["timestamp"] = $timestamp+"";
386
-            if($suiteTicket != null) {
386
+            if ($suiteTicket != null) {
387 387
                 $queryParams["suiteTicket"] = $suiteTicket;
388 388
             }
389
-            if($corpId != null){
390
-                $queryParams["corpId"] =  $corpId;
389
+            if ($corpId != null) {
390
+                $queryParams["corpId"] = $corpId;
391 391
             }
392 392
             foreach ($queryParams as $queryParamKey => $queryParamValue) {
393
-                $requestUrl .= "$queryParamKey=" . urlencode($queryParamValue) . "&";
393
+                $requestUrl .= "$queryParamKey=".urlencode($queryParamValue)."&";
394 394
             }
395
-        }else{
396
-            $requestUrl .= "access_token=" . urlencode($session) . "&";
395
+        }else {
396
+            $requestUrl .= "access_token=".urlencode($session)."&";
397 397
         }
398 398
 
399 399
         $apiParams = array();
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
         $apiParams = $request->getApiParas();
402 402
         $fileFields = array();
403 403
         foreach ($apiParams as $key => $value) {
404
-            if(is_array($value) && array_key_exists('type',$value) && array_key_exists('content',$value) ){
404
+            if (is_array($value) && array_key_exists('type', $value) && array_key_exists('content', $value)) {
405 405
                 $value['name'] = $key;
406 406
                 $fileFields[$key] = $value;
407 407
                 unset($apiParams[$key]);
@@ -414,19 +414,19 @@  discard block
 block discarded – undo
414 414
         //发起HTTP请求
415 415
         try
416 416
         {
417
-            if(count($fileFields) > 0){
417
+            if (count($fileFields) > 0) {
418 418
                 $resp = $this->curl_with_memory_file($requestUrl, $apiParams, $fileFields);
419
-            }else{
420
-                if(DingTalkConstant::$METHOD_POST == $this->httpMethod){
419
+            }else {
420
+                if (DingTalkConstant::$METHOD_POST == $this->httpMethod) {
421 421
                     $resp = $this->curl_json($requestUrl, $apiParams);
422
-                }else{
422
+                }else {
423 423
                     $resp = $this->curl_get($requestUrl, $apiParams);
424 424
                 }
425 425
             }
426 426
         }
427 427
         catch (Exception $e)
428 428
         {
429
-            $this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_ERROR_" . $e->getCode(),$e->getMessage());
429
+            $this->logCommunicationError($sysParams["method"], $requestUrl, "HTTP_ERROR_".$e->getCode(), $e->getMessage());
430 430
             $result->code = $e->getCode();
431 431
             $result->msg = $e->getMessage();
432 432
             return $result;
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
                 $respWellFormed = true;
445 445
             }
446 446
         }
447
-        else if("xml" == $this->format)
447
+        else if ("xml" == $this->format)
448 448
         {
449 449
             $respObject = @simplexml_load_string($resp);
450 450
             if (false !== $respObject)
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
         //返回的HTTP文本不是标准JSON或者XML,记下错误日志
457 457
         if (false === $respWellFormed)
458 458
         {
459
-            $this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_RESPONSE_NOT_WELL_FORMED",$resp);
459
+            $this->logCommunicationError($sysParams["method"], $requestUrl, "HTTP_RESPONSE_NOT_WELL_FORMED", $resp);
460 460
             $result->code = 0;
461 461
             $result->msg = "HTTP_RESPONSE_NOT_WELL_FORMED";
462 462
             return $result;
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
         if (isset($respObject->code))
467 467
         {
468 468
             $logger = new TopLogger;
469
-            $logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_biz_err_" .  "_" . date("Y-m-d") . ".log";
469
+            $logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/').'/'."logs/top_biz_err_"."_".date("Y-m-d").".log";
470 470
             $logger->log(array(
471 471
                 date("Y-m-d H:i:s"),
472 472
                 $resp
@@ -477,26 +477,26 @@  discard block
 block discarded – undo
477 477
 
478 478
     private function getMillisecond() {
479 479
         list($s1, $s2) = explode(' ', microtime());
480
-        return (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);
480
+        return (float)sprintf('%.0f', (floatval($s1)+floatval($s2))*1000);
481 481
     }
482 482
 
483 483
     private function getCanonicalStringForIsv($timestamp, $suiteTicket) {
484 484
         $result = $timestamp;
485
-        if($suiteTicket != null) {
485
+        if ($suiteTicket != null) {
486 486
             $result .= "\n".$suiteTicket;
487 487
         }
488 488
         return $result;
489 489
     }
490 490
 
491
-    private function computeSignature($accessSecret, $canonicalString){
491
+    private function computeSignature($accessSecret, $canonicalString) {
492 492
         $s = hash_hmac('sha256', $canonicalString, $accessSecret, true);
493 493
         return base64_encode($s);
494 494
     }
495 495
 
496
-    private function _execute($request, $session = null,$bestUrl = null)
496
+    private function _execute($request, $session = null, $bestUrl = null)
497 497
 	{
498
-		$result =  new ResultSet(); 
499
-		if($this->checkRequest) {
498
+		$result = new ResultSet(); 
499
+		if ($this->checkRequest) {
500 500
 			try {
501 501
 				$request->check();
502 502
 			} catch (Exception $e) {
@@ -521,14 +521,14 @@  discard block
 block discarded – undo
521 521
 
522 522
 
523 523
 		//系统参数放入GET请求串
524
-		if($bestUrl){
525
-            if(strpos($bestUrl,'?') === false){
524
+		if ($bestUrl) {
525
+            if (strpos($bestUrl, '?') === false) {
526 526
                 $requestUrl = $bestUrl."?";
527
-            }else{
527
+            }else {
528 528
                 $requestUrl = $bestUrl;
529 529
             }
530 530
 			$sysParams["partner_id"] = $this->getClusterTag();
531
-		}else{
531
+		}else {
532 532
 			$requestUrl = $this->gatewayUrl."?";
533 533
 			$sysParams["partner_id"] = $this->sdkVersion;
534 534
 		}
@@ -536,12 +536,12 @@  discard block
 block discarded – undo
536 536
 		foreach ($sysParams as $sysParamKey => $sysParamValue)
537 537
 		{
538 538
 			// if(strcmp($sysParamKey,"timestamp") != 0)
539
-			$requestUrl .= "$sysParamKey=" . urlencode($sysParamValue) . "&";
539
+			$requestUrl .= "$sysParamKey=".urlencode($sysParamValue)."&";
540 540
 		}
541 541
 
542 542
 		$fileFields = array();
543 543
 		foreach ($apiParams as $key => $value) {
544
-			if(is_array($value) && array_key_exists('type',$value) && array_key_exists('content',$value) ){
544
+			if (is_array($value) && array_key_exists('type', $value) && array_key_exists('content', $value)) {
545 545
 				$value['name'] = $key;
546 546
 				$fileFields[$key] = $value;
547 547
 				unset($apiParams[$key]);
@@ -554,15 +554,15 @@  discard block
 block discarded – undo
554 554
 		//发起HTTP请求
555 555
 		try
556 556
 		{
557
-			if(count($fileFields) > 0){
557
+			if (count($fileFields) > 0) {
558 558
 				$resp = $this->curl_with_memory_file($requestUrl, $apiParams, $fileFields);
559
-			}else{
559
+			}else {
560 560
 				$resp = $this->curl($requestUrl, $apiParams);
561 561
 			}
562 562
 		}
563 563
 		catch (Exception $e)
564 564
 		{
565
-			$this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_ERROR_" . $e->getCode(),$e->getMessage());
565
+			$this->logCommunicationError($sysParams["method"], $requestUrl, "HTTP_ERROR_".$e->getCode(), $e->getMessage());
566 566
 			$result->code = $e->getCode();
567 567
 			$result->msg = $e->getMessage();
568 568
 			return $result;
@@ -584,7 +584,7 @@  discard block
 block discarded – undo
584 584
 				}
585 585
 			}
586 586
 		}
587
-		else if("xml" == $this->format)
587
+		else if ("xml" == $this->format)
588 588
 		{
589 589
 			$respObject = @simplexml_load_string($resp);
590 590
 			if (false !== $respObject)
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
 		//返回的HTTP文本不是标准JSON或者XML,记下错误日志
597 597
 		if (false === $respWellFormed)
598 598
 		{
599
-			$this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_RESPONSE_NOT_WELL_FORMED",$resp);
599
+			$this->logCommunicationError($sysParams["method"], $requestUrl, "HTTP_RESPONSE_NOT_WELL_FORMED", $resp);
600 600
 			$result->code = 0;
601 601
 			$result->msg = "HTTP_RESPONSE_NOT_WELL_FORMED";
602 602
 			return $result;
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
 		if (isset($respObject->code))
607 607
 		{
608 608
 			$logger = new TopLogger;
609
-			$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_biz_err_" .  "_" . date("Y-m-d") . ".log";
609
+			$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/').'/'."logs/top_biz_err_"."_".date("Y-m-d").".log";
610 610
 			$logger->log(array(
611 611
 				date("Y-m-d H:i:s"),
612 612
 				$resp
@@ -623,21 +623,21 @@  discard block
 block discarded – undo
623 623
 		}
624 624
 		$inflector = new LtInflector;
625 625
 		$inflector->conf["separator"] = ".";
626
-		$requestClassName = ucfirst($inflector->camelize(substr($paramsArray["method"], 7))) . "Request";
626
+		$requestClassName = ucfirst($inflector->camelize(substr($paramsArray["method"], 7)))."Request";
627 627
 		if (!class_exists($requestClassName))
628 628
 		{
629
-			trigger_error("No such dingtalk-api: " . $paramsArray["method"]);
629
+			trigger_error("No such dingtalk-api: ".$paramsArray["method"]);
630 630
 		}
631 631
 
632 632
 		$session = isset($paramsArray["session"]) ? $paramsArray["session"] : null;
633 633
 
634 634
 		$req = new $requestClassName;
635
-		foreach($paramsArray as $paraKey => $paraValue)
635
+		foreach ($paramsArray as $paraKey => $paraValue)
636 636
 		{
637 637
 			$inflector->conf["separator"] = "_";
638 638
 			$setterMethodName = $inflector->camelize($paraKey);
639 639
 			$inflector->conf["separator"] = ".";
640
-			$setterMethodName = "set" . $inflector->camelize($setterMethodName);
640
+			$setterMethodName = "set".$inflector->camelize($setterMethodName);
641 641
 			if (method_exists($req, $setterMethodName))
642 642
 			{
643 643
 				$req->$setterMethodName($paraValue);
@@ -648,6 +648,6 @@  discard block
 block discarded – undo
648 648
 
649 649
 	private function getClusterTag()
650 650
     {
651
-	    return substr($this->sdkVersion,0,11)."-cluster".substr($this->sdkVersion,11);
651
+	    return substr($this->sdkVersion, 0, 11)."-cluster".substr($this->sdkVersion, 11);
652 652
     }
653 653
 }
Please login to merge, or discard this patch.
Braces   +27 added lines, -35 removed lines patch added patch discarded remove patch
@@ -54,11 +54,12 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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)
Please login to merge, or discard this patch.