From 3e09d7b949bcd9be6866d80833da43d9f85dff62 Mon Sep 17 00:00:00 2001 From: Devil Date: Wed, 28 Jul 2021 13:44:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=92=E4=BB=B6=E4=B8=8B=E8=BD=BD=E7=BD=91?= =?UTF-8?q?=E7=BB=9C=E6=B3=A2=E5=8A=A8=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/service/PackageInstallService.php | 40 +++++++-------------------- 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/app/service/PackageInstallService.php b/app/service/PackageInstallService.php index f190cb1eb..fe9ed7fc7 100644 --- a/app/service/PackageInstallService.php +++ b/app/service/PackageInstallService.php @@ -338,41 +338,21 @@ class PackageInstallService */ public static function HttpRequest($url, $data) { - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_FAILONERROR, false); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - - $body_string = ''; - if(is_array($data) && 0 < count($data)) + $res = CurlPost($url, $data); + $result = json_decode($res, true); + if(empty($result)) { - foreach($data as $k => $v) - { - $body_string .= $k.'='.urlencode($v).'&'; - } - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, $body_string); - } - $headers = [ - 'Content-type: application/x-www-form-urlencoded;charset=UTF-8', - 'X-Requested-With: XMLHttpRequest', - ]; - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - $reponse = curl_exec($ch); - $error = curl_errno($ch); - curl_close($ch); - if($error) - { - return DataReturn("curl出错,错误码:$error", -1); + return DataReturn('商店网络不通['.$res.']', -1); } - // 是否json格式数据 - if(substr($reponse, 0, 1) != '{') + // 是否非数组 + if(is_string($result)) { - return DataReturn("返回数据格式有误:$reponse", -1); + return DataReturn($result, -1); } - return json_decode($reponse, true); + + // 请求成功 + return $result; } } ?> \ No newline at end of file -- GitLab