|
@@ -525,3 +525,33 @@ if (!function_exists('array_unique_fb')) {
|
|
|
return $out;
|
|
|
}
|
|
|
}
|
|
|
+if (!function_exists('do_request')) {
|
|
|
+ function do_request($url, $data, $header = null, $post = true, $json = false, $format = 0, $form = false)
|
|
|
+ {
|
|
|
+ $curl = curl_init();
|
|
|
+ curl_setopt($curl, CURLOPT_URL, $url);
|
|
|
+ curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
+ if ($post) {
|
|
|
+ curl_setopt($curl, CURLOPT_POST, 1);
|
|
|
+ if (!$json && !$form) {
|
|
|
+ curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
|
|
|
+ } else if ($json && !$form) {
|
|
|
+ curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data, $format));
|
|
|
+ } else {
|
|
|
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
|
+ if ($header) {
|
|
|
+ curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
|
|
|
+ curl_setopt($curl, CURLOPT_HEADER, 0);
|
|
|
+ }
|
|
|
+ $result = curl_exec($curl);
|
|
|
+ if (curl_errno($curl)) {
|
|
|
+ return json_encode(['status' => curl_errno($curl), 'msg' => '请求失败']);
|
|
|
+ }
|
|
|
+ curl_close($curl);
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+}
|