@@ -143,11 +143,14 @@ public function parseCurl($curlContent) {
143
143
}
144
144
145
145
//get data
146
- if (!preg_match ("#--data \\$?'([^']*)'#is " , $ curlContent , $ postDataMatch )) {
147
- $ postData = '' ;
148
- } else {
149
- $ postData = $ postDataMatch [1 ];
146
+ //单引号
147
+ if (!preg_match ("#(?:--data\S*|-d) \\$?'([^']*)'#is " , $ curlContent , $ postDataMatch )) {
148
+ //双引号
149
+ if (!preg_match ('#(?:--data\S*|-d) \\$?"([^"]*)"#is ' , $ curlContent , $ postDataMatch )) {
150
+ $ postDataMatch [1 ] = '' ;
151
+ }
150
152
}
153
+ $ postData = $ postDataMatch [1 ];
151
154
152
155
return array (
153
156
'url ' => $ matchUrl [1 ],
@@ -245,7 +248,11 @@ public function setLogPath($logPath) {
245
248
* @return [type] [description]
246
249
*/
247
250
protected function _log ($ msg ) {
248
- file_put_contents ($ this ->logPath , $ msg . "\n" , FILE_APPEND );
251
+ try {
252
+ $ res = file_put_contents ($ this ->logPath , $ msg . "\n" , FILE_APPEND );
253
+ } catch (\Exception $ e ) {
254
+ error_log ("CurlAutoLogin 无法写入日志文件 {$ this ->logPath }: {$ msg }" );
255
+ }
249
256
}
250
257
251
258
/**
@@ -261,7 +268,25 @@ public function getLastCookieFile() {
261
268
* @return string
262
269
*/
263
270
public function getLastCookieContent () {
264
- return file_get_contents ($ this ->getLastCookieFile ());
271
+ if ($ file = $ this ->getLastCookieFile ()) {
272
+ if (file_exists ($ file )) {
273
+ return file_get_contents ($ file );
274
+ }
275
+ }
276
+ return '' ;
277
+ }
278
+
279
+ /**
280
+ * 手动追加cookie内容
281
+ * @param $content
282
+ * @return bool|int
283
+ */
284
+ public function appendCookieContent ($ content )
285
+ {
286
+ if (file_exists ($ file = $ this ->getLastCookieFile ())) {
287
+ return file_put_contents ($ file , $ content . "\n" , FILE_APPEND );
288
+ }
289
+ return false ;
265
290
}
266
291
267
292
/**
@@ -279,7 +304,12 @@ public function setLastCookieFile($cookieFile) {
279
304
* 清空上次存储的cookie
280
305
*/
281
306
public function removeLastCookie () {
282
- file_put_contents ($ this ->getLastCookieFile (), '' );
307
+ if ($ file = $ this ->getLastCookieFile ()) {
308
+ //文件存在才清空
309
+ if (file_exists ($ file )) {
310
+ file_put_contents ($ file , '' );
311
+ }
312
+ }
283
313
return $ this ;
284
314
}
285
315
0 commit comments