Take http://www.webxml.com.cn/zh_cn/index.aspx
1. Use soap call
- //The server supports soap extension:
- /*Example 1:
- $client = new SoapClient("http://fy.webxml.com.cn/webservices /EnglishChinese.asmx?wsdl");
- $parameters = array("wordKey"=>"test");
- //Chinese and English bidirectional translation return data: array
- $result = $client->TranslatorString($parameters );
- echo "
";</li>
<li> print_r($result->TranslatorStringResult)."<br />";</li>
<li> echo " ";
- //Chinese and English bidirectional translation return array Sentence examples:
- $result1 = $client->Translator($parameters);
- echo "
";</li>
<li> print_r($result1->TranslatorResult)."<br />";</li>
<li> echo " ";
- //Get candidate words:
- $result2 = $client->SuggestWord($parameters);
- echo "
";</li>
<li> print_r($result2->SuggestWordResult). "<br />";</li>
<li> echo " ";
- //Get the read MP3 byte stream, return data: byte array Byte[]
- $result3 = $client->GetMp3($ parameters);
- echo "
";</li>
<li> print_r($result3)."<br />";</li>
<li> echo " ";
- */
-
-
- /*Example2:
-
- $client = new SoapClient("http://webservice.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl");
- $param = array('theIpAddress'=>'202.96.134.33');
- $ result = $client->getCountryCityByIp($param);
- echo "
";</li>
<li> print_r($result->getCountryCityByIpResult);</li>
<li> echo " ";
-
- $result1 = $client ->getGeoIPContext($param);
- echo "
";</li>
<li> print_r($result1);</li>
<li> echo " ";
-
- $result2 = $client->getVersionTime(
- );
- echo "
";</li>
<li> print_r($result2);</li>
<li> echo " ";
-
- */
- //Example3:
-
- $client = new SoapClient("http://webservice. webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl");
- //Get the province, region and mobile phone card type information of the domestic mobile phone number
- $parm=array('mobileCode'=>'1367007',' userID'=>'');
- $result=$client->getMobileCodeInfo($parm);
- echo ($result->getMobileCodeInfoResult)."
";
- //Get the domestic mobile phone number Geodatabase information
- $result1 = $client->getDatabaseInfo($parm);
- print_r($result1)."
";
-
- // Get the list of SOAP types (Returns list of SOAP types)
- echo '
';</li>
<li> print_r($client->__getTypes ()) ;</li>
<li> echo ' ';
-
- // Get the functions provided by webservice
- echo '
';</li>
<li> print_r( $client->__getFunctions ()) ;</li>
<li> echo ' ';
- //If the server does not support soap extension, you can introduce an online open source class library
- ?>
Copy the code
2. Use curl to POST
-
- cPost('l8200352367');
- /**
- * Use POST method in CURL to submit data
- *@param string $xml $xml data to be submitted
- */
- function cPost($phone){
- $curlPost = "mobileCode=$phone&userID=";
- $ ch = curl_init();//Initialize curl session, return a handle
- curl_setopt($ch, CURLOPT_URL, "http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo");
- curl_setopt($ ch, CURLOPT_POST, 1);//When enabled, a regular POST request will be sent, the type is: application/x-www-form-urlencoded, just like the form submission
- curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//Return the information obtained by curl_exec() in the form of a file stream instead of outputting it directly
- $res = curl_exec($ch);
- curl_close($ch);
- var_dump ($res);
- }
Copy code
|