PHP链接WEB SERVICE类代码实例:
- //通讯类开始
- class webserv
- {
- //webservice 地址参数
-
var $webadd = array(
-
"publ" => "client.asmx?wsdl",
-
"client" => "Client.asmx?wsdl",
-
"bann" => "");
- //调用webservice
-
function soap($class,$function,$par = array()){
- //链接
- web service
-
$client = new SoapClient($this->webadd[$class]);
-
$require = $client->$function($par);
- //调用信息debug
- if (is_soap_fault($require)) {
- echo "远程接口".$function."调用失败!";
- exit();
- }
- //获取返回值
-
$function_result = $function."Result";
-
$str = $require->$function_result;
- //解析XML
-
$row = @simplexml_load_string( $str );
- //如果不能用XML解析直接返回
-
if ($row == false) {
- if (is_string($str)){
- return $str;
- } else {
-
$require = (get_object_vars($str));
-
$str = $require['string'];
- return $str;
- }
- }
- //结果转换为数组
-
$row_arr = get_object_vars($row);
- print_r($row_arr);exit();
-
$row_return = $row_arr['Table'];
- //判断是不是多反馈记录
- if (is_array($row_arr['Table'])) {
-
foreach ($row_return as $key => $vlaues){
- $rows[$key] = get_object_vars($vlaues);
- }
- } else {
- $rows[0] = get_object_vars($row_arr['Table']);
- }
- //通讯记录
-
//$this->soap_log($class,$function,$par,$rows);
- return $rows;
- }
- //接口通讯记录
- function soap_log($class, $function, $in, $out){
-
$log = date("Y-m-d H:i:s");
-
$log .= " ".$class."->".$function." input:";
-
$input = "";
- if ($in != array()) {
-
foreach ($in as $key => $vlaue){
-
$input .= $key."=".$vlaue;
- }
-
$log .= $input." output:".var_export($rows)."n";
- }
- }
- }
以上是通信类的内容。用法很简单
include 一下PHP链接WEB SERVICE类文件
<ol class="dp-xml">
<li class="alt"><span><span class="tag"><span> ? </span></span></span></li>
<li><span>include "./webserv.class.php"; </span></li>
<li class="alt">
<span>$</span><span class="attribute">webserv</span><span> = </span><span class="attribute-value">new</span><span> webserv; </span>
</li>
<li><span>//这里是调用方法给传递的参数 </span></li>
<li class="alt">
<span>$</span><span class="attribute">a</span><span> = </span><span class="attribute-value">array</span><span>("aa"=</span><span class="tag">></span><span>"aaaa"); </span>
</li>
<li>
<span>print_r($webser-</span><span class="tag">></span><span>soap("function_name",$a)); </span>
</li>
<li class="alt">
<span class="tag">?></span><span> </span>
</li>
</ol>
以上就是PHP链接WEB SERVICE类的相关使用方法。
http://www.bkjia.com/PHPjc/445913.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/445913.htmlTechArticlePHP链接WEB SERVICE类代码实例: //通讯类开始 classwebserv { //webservice地址参数 var$ webadd = array ( publ= client.asmx?wsdl, client= Client.asmx?wsdl, bann= ); //调...
Kenyataan:Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn