国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
PHP5 擴展SOAP 調用 webservice

php4時代調用webservice大部分使用的nusoap。到了php5已經(jīng)有了自己的soap擴展。所以可以完全的拋棄nusoap這個許久沒有更新過的東西了。

因為目前是本地開發(fā)需要。只說windows下的。

配置環(huán)境

windows下找到php安裝目錄下的php.ini。打開后編輯。找到

extension=php_soap.dll

然后將前面的;號去掉。

然后就是寫一個php文件來驗證一下。

實例程序

在apache的htdocs目錄下創(chuàng)建ws.php

代碼如下:

<?php
header("content-type:text/html;charset=utf-8");
try {
$client = new SoapClient( 'http://erp.test.com/SendSMS/Service.asmx?wsdl',array('trace' => true, 'exceptions' => true ));
var_dump($client->__getFunctions());
} catch (SOAPFault $e) {
print_r($e);
}
?>

在瀏覽器中輸入:http://localhost/ws.php后會出現(xiàn)

array
0 => string 'SendSMSResponse SendSMS(SendSMS $parameters)' (length=44)
1 => string 'SendSMS1Response SendSMS1(SendSMS1 $parameters)' (length=47)
2 => string 'SendMailResponse SendMail(SendMail $parameters)' (length=47)
3 => string 'IsSendSMSResponse IsSendSMS(IsSendSMS $parameters)' (length=50)
4 => string 'IsSendSMS1Response IsSendSMS1(IsSendSMS1 $parameters)' (length=53)
5 => string 'SendSMSResponse SendSMS(SendSMS $parameters)' (length=44)
6 => string 'SendSMS1Response SendSMS1(SendSMS1 $parameters)' (length=47)
7 => string 'SendMailResponse SendMail(SendMail $parameters)' (length=47)
8 => string 'IsSendSMSResponse IsSendSMS(IsSendSMS $parameters)' (length=50)
9 => string 'IsSendSMS1Response IsSendSMS1(IsSendSMS1 $parameters)' (length=53)

現(xiàn)在逐行解釋一下。$client = new SoapClient('http://erp.test.com/SendSMS/Service.asmx?wsdl',array('trace' =>true, 'exceptions' => true ));
這里的SoapClient類可以作為給定的ws的客戶端。這個SoapClient有兩種操作模式。
一個是WSDL模式,一個是Non-WSDL模式。
當然這里用的是WSDL模式。所以重點來說第一種。
WSDL模式中,SoapClient的構造參數(shù)分別是ws的請求地址以及各種請求配置參數(shù)。
var_dump($client->__getFunctions());
這里就是訪問后輸出的這個接口可提供的方法,返回值以及參數(shù)。
那么如何去調用方法呢。

<?php
header("content-type:text/html;charset=utf-8");
try {
$client = new SoapClient( 'http://erp.test.com/SendSMS/Service.asmx?wsdl',
array('trace' => true, 'exceptions' => true ));
var_dump($client->__getFunctions());
//第一個參數(shù)是命名空間,第二個參數(shù)是SoapHeader頭的類名,第三個是SoapHeader參數(shù)的數(shù)組可以寫成array
$v = array("Token"=>"");
$headers = new SoapHeader("http://test.com/","AuthenticationHeader",$v, false, SOAP_ACTOR_NEXT);
$client->__setSoapHeaders(array($headers));
//$types = $client->__getTypes(); //這里是為了查看方法的類型
  //print_r($types);
//這里就是根據(jù)方法參數(shù)的需要虛擬出來一個sms類型的數(shù)組
$sms1 = array(
'Id'=>100000,
'SjNo'=>'13512222222',
'UnickName'=>'tuangou',
'SmsContent'=>'test',
'Type'=>1000,
'OrderIdString'=>'1231114567'
);
$param = array(
'sms1'=>$sms1
);
//這里是需要注意到地方。調用方法的參數(shù)必須是一個數(shù)組。而且默認以parameters字段標識為參數(shù)數(shù)組。真正的參數(shù)都要放在$param變量中。
$return = $client->__soapCall("SendSMS1",array('parameters'=>$param));
print_r($return);
} catch (SOAPFault $e) {
print_r('Exception:'.$e);
}
?>
POST /SendSMS/Service.asmx HTTP/1.1
Host: erp.test.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://test.com/SendSMS1"

<?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:Header>
<AuthenticationHeader xmlns="http://test.com/">
<Token>string</Token>
</AuthenticationHeader>
</soap:Header>
<soap:Body>
<SendSMS1 xmlns="http://test.com/">
<sms1>
<Id>int</Id>
<SjNo>string</SjNo>
<UnickName>string</UnickName>
<SmsContent>string</SmsContent>
<Type>int</Type>
<OrderIdString>string</OrderIdString>
</sms1>
</SendSMS1>
</soap:Body>
</soap:Envelope>

這里可以看到。soap的Header和Body。Header里就是Token。Body里就是具體的方法了。

SendSMS1節(jié)點是方法名。

sms1節(jié)點就是參數(shù)。

sms1節(jié)點下的就是參數(shù)的屬性。

一定要按照順序對屬性進行逐個賦值。



本站僅提供存儲服務,所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Qt實現(xiàn)訪問WebService
NuSOAP webservice接口使用詳解
SOAP for Python [知識庫]
Java: JNI完全手冊
深入解讀PHP短信驗證碼原理
Webservice?安全性訪問
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服