php中調用WebService接口


一、背景

調用第三方短信提供商的WebService接口。


二、介紹

1.WebService三要素:#

SOAP(Simple Object Access Protocol) 用來描述傳遞信息的格式

WSDL(Web Services Description Language) 用來描述如何訪問具體的接口

UDDI(Universal Description Discovery and Integration) 用來管理,分發,查詢WebService

2.SoapUi#

SoapUI是一個開源測試工具,通過soap/http來檢查、調用、實現Web Service的功能/負載/符合性測試。

2021-04-06-22-34-27


三、使用方法

1.建立SOAP

使用SoapUi:

2021-04-06-22-34-33

使用php:

Copy

    $client = new SoapClient("http://XXX/webservice/mmsservice.asmx?wsdl", array( "stream_context" => stream_context_create( array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, ) ) ) ) ); 

2.調用接口 and 獲取返回值

使用SoapUi:

2021-04-06-22-34-44

使用php:

Copy

    //調用接口 $parm = array('mobile' => ‘136XXXXXX’, 'mmsid' => 'XXX', 'sToken' => 'XXX'); $result = $client->SendPersonMMS($parm); //獲取返回值 $result = get_object_vars($result); echo $result["SendPersonMMSResult"]; 

四、總體代碼

Copy

header("content-type:text/html;charset=utf-8"); try { //解決OpenSSL Error問題需要加第二個array參數,具體參考 http://stackoverflow.com/questions/25142227/unable-to-connect-to-wsdl $client = new SoapClient("http://XXX/webservice/mmsservice.asmx?wsdl", array( "stream_context" => stream_context_create( array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, ) ) ) ) ); //print_r($client->__getFunctions()); //print_r($client->__getTypes()); $parm = array('mobile' => ‘136XXXXXX’, 'mmsid' => 'XXX', 'sToken' => 'XXX'); $result = $client->SendPersonMMS($parm); //print_r($result); //將stdclass object的$result轉換為array $result = get_object_vars($result); //輸出結果 echo $result["SendPersonMMSResult"]; } catch (SOAPFault $e) { print $e; }


轉載地址:https://www.cnblogs.com/xjnotxj/p/6212143.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM