Request the Test interface as follows:
$data = [ " mobilephone " => " 123 ", " password " =>" 124 " ]; $result = Curlrequest ($APIURL, $data); if ($result [ " statuscode ' ] = = 200 else {echo Json_encode ($result);}
The Curl Request URL method is as follows:
/** * @param string $url Request address * @param string $data Request data * @param string $method Request way * @return Array one-dimensional array*/function Curlrequest ($url, $data="', $method ='POST') {$ch= Curl_init ();//Initialize the curl handlecurl_setopt ($ch, Curlopt_url, $url);//set the requested URLcurl_setopt ($ch, Curlopt_returntransfer,1);//set to True to convert the curl_exec () result to a string, while S is not a direct outputcurl_setopt ($ch, Curlopt_customrequest, $method);//Set Request Modecurl_setopt ($ch, Curlopt_httpheader,array ("x-http-method-override: $method"));//Set HTTP header informationcurl_setopt ($ch, Curlopt_postfields, $data);//set the committed string$document = curl_exec ($ch);//Perform predefined Curl$statusCode = Curl_getinfo ($ch, Curlinfo_http_code);//get HTTP request status Code ~curl_close ($ch); $document= Json_decode (Removebom ($document),true); $document ['StatusCode'] =$statusCode; return$document;}
If garbled characters are found in the returned JSON results, the BOM needs to be removed as follows:
/* * @param string $str String * @return string to remove after BOM */ " ) { if0,3) = = Pack ("CCC" ,0xef,0xbb,0xbf)) { 3); } return $str;}
PHP (Curl request) test interface case