|
@@ -127,4 +127,66 @@ class PublicData
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * POST 请求
|
|
|
+ * @param string $url
|
|
|
+ * @param array $param
|
|
|
+ * @param boolean $post_file 是否文件上传
|
|
|
+ * @return string content
|
|
|
+ */
|
|
|
+ public static function http_post_zp($url, $data, $options = [])
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ $ch = curl_init($url);
|
|
|
+ var_dump("参数:",$data);
|
|
|
+
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
+ curl_setopt($ch, CURLOPT_HEADER, false);
|
|
|
+ curl_setopt($ch, CURLOPT_POST, true);
|
|
|
+ curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
|
|
|
+ $headers = [
|
|
|
+ 'Authorization: Bearer be1856920c54ac537b530d69bc2eda73.gOO2BMq9NXavzEMq',
|
|
|
+ 'Content-Type: application/json',
|
|
|
+
|
|
|
+ ];
|
|
|
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
|
+
|
|
|
+ if (!empty($options)) {
|
|
|
+ curl_setopt_array($ch, $options);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $response = curl_exec($ch);
|
|
|
+
|
|
|
+ if (curl_errno($ch)) {
|
|
|
+ $error_msg = curl_error($ch);
|
|
|
+ curl_close($ch);
|
|
|
+ throw new Exception("CURL Error: $error_msg");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
+
|
|
|
+
|
|
|
+ curl_close($ch);
|
|
|
+
|
|
|
+
|
|
|
+ $responseBody = $response;
|
|
|
+ $headerEnd = strpos($response, "\r\n\r\n");
|
|
|
+
|
|
|
+ if ($headerEnd !== false) {
|
|
|
+
|
|
|
+ $responseBody = substr($response, $headerEnd + 4);
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ return [
|
|
|
+ 'response' => $responseBody,
|
|
|
+ 'http_code' => $http_code
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
}
|