今天用curl模拟調用 各種出錯
接口請求格式是這樣的
POST /Web/Web.asmx HTTP/1.1
Host: 121.14.195.138
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/SendSMS"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<SendSMS xmlns="http://tempuri.org/">
<UserName>string</UserName>
<UserPwd>string</UserPwd>
<Mobile>string</Mobile>
<Message>string</Message>
</SendSMS>
</soap:Body>
</soap:Envelope>
用curl模拟出錯 就不在描述了;
然後在論壇發現可以用soapclient可以很友善的解決這樣websever
百度了下 發現一個很不錯的例子:
<?php
header ( "Content-Type: text/html; charset=gb2312" );
/*
* 指定WebService路徑并初始化一個WebService用戶端
*/
$ws = "http://www.webservicex.net/globalweather.asmx?wsdl";//webservice服務的位址
$client = new SoapClient ($ws);
/*
* 擷取SoapClient對象引用的服務所提供的所有方法
*/
echo ("SOAP伺服器提供的開放函數:");
echo ('<pre>');
var_dump ( $client->__getFunctions () );//擷取伺服器上提供的方法
echo ('</pre>');
echo ("SOAP伺服器提供的Type:");
echo ('<pre>');
var_dump ( $client->__getTypes () );//擷取伺服器上資料類型
echo ('</pre>');
echo ("執行GetGUIDNode的結果:");
$result=$client->getWeather(array('CityName'=>'zhengzhou','CountryName'=>'china'));//查詢中國鄭州的天氣,傳回的是一個結構體
echo $result->GetWeatherResult;//顯示結果
?>
最後:
$params = array(
'UserName' =>$username,
'UserPwd' => $password,
'Mobile'=> $mobile,
'Message'=>$content
);
$client = new SoapClient("http://xx:8006/Web/Web.asmx?wsdl");
$result=$client->SendSMS($params);
echo $result->SendSMSResult;//顯示結果