soap

這幾天在做soap接收上行數據,他是一個接口,從網上可以下到nusoap.php這個文件。

如果短信接口的服務器端沒有用PHP自帶的soap擴展,是自己寫的,而我們網站打開了soap擴展,這就很讓我爲難了,環境不一樣,代碼就有些小不一樣了。糾結了我半天,最後我同事發現nusoap.php的最後有

if (!extension_loaded('soap')) {

/**

* For backwards compatiblity, define soapclient unless the PHP SOAP extension is loaded.

*/

class soapclient extends nusoap_client {

}

}

這段代碼,暈,這下我知道該怎麼做了,

require_once dirname(__FILE__)."/nusoap.php";

//創建一個soapclient對象,參數是server的WSDL 

$client=new nusoap_client('http://61.145.229.29:9002/MWGate/wmgw.asmx?wsdl');

//將對應參數值賦到下面數組以供調用

$parameters = array(

'userId'=>$userid,

'password'=>$password

);

$sms=$client->call('MongateCsGetSmsExEx',$parameters);

實例化nusoap_client這個類,就OK了。

好了,不兼容的問題解決了,剩下的就是編碼的問題了,在文件頭部要加上header('Content-Type:text/html;charset=UTF-8');

然後修改nusoap.php這個文件,將var $decode_utf8 = true;改成var $decode_utf8 = false;

將這些都給改成UTF-8

if (strpos($headers['content-type'], '=')) {

$enc = str_replace('"', '', substr(strstr($headers["content-type"], '='), 1));

$this->debug('Got response encoding: ' . $enc);

if(preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i',$enc)){

$this->xml_encoding = strtoupper($enc);

} else {

// $this->xml_encoding = 'US-ASCII';

$this->xml_encoding = 'UTF-8';

}

} else {

// should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1

// $this->xml_encoding = 'ISO-8859-1';

$this->xml_encoding = 'UTF-8';

}

 

好了,中文顯示正常了。

WSDL也就那麼回事,做過才知道,原來一切都是如此的簡單。

另外就是打開soap擴展和不打開soap擴展,開發出來的服務器端是不一樣的。

下面這篇文章是說當soap擴展打開的時候怎麼樣開發soap服務器端和客戶端的。

http://article.yeeyan.org/view/jimmylee/5424?from_com

人要不斷的學習,才能進步!!!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章