首先,新建的时候要选择soap,然后deocument和rpc都可以。
类和方法的页面:
<?php //发货接口 class test{ function send_do_delivery($orderid,$money,$freight,$shipname,$shiptel,$shipmobile,$shipzip,$shiparea,$shipaddr,$memo,$send,$gift_send){ $orderData=array( ‘order_id‘ =>$orderid, ‘delivery‘ =>‘1‘, ‘logi_id‘ =>‘1‘, ‘other_name‘ =>‘‘, ‘logi_no‘ =>‘‘, ‘money‘ =>$money, ‘is_protect‘ =>false, ‘cost_freight‘ =>$freight, ‘ship_name‘ =>$shipname, ‘ship_tel‘ => $shiptel, ‘ship_mobile‘ =>$shipmobile, ‘ship_zip‘ =>$shipzip, ‘ship_area‘ =>$shiparea, ‘ship_addr‘ =>$shipaddr, ‘memo‘ =>$memo, ‘send‘ => $send, ‘gift_send‘ => $gift_send ); /**拼凑提交的数据*/ $params = array( ‘parms‘ => json_encode($orderData) ); $url = "http://XXXXXX/tools-do_delivery.html"; $res=$this->sendByPost($url,$params); //var_dump(); return $res; } #发送ERP请求 function sendByPost($url,$paramArray){ $postdata = http_build_query($paramArray); $length = strlen($postdata); $cl = curl_init($url); curl_setopt($cl, CURLOPT_POST, true); curl_setopt($cl,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1); curl_setopt($cl,CURLOPT_HTTPHEADER,array("Content-Type: application/x-www-form-urlencoded","Content-length: ".$length)); curl_setopt($cl,CURLOPT_POSTFIELDS,$postdata); curl_setopt($cl,CURLOPT_RETURNTRANSFER,true); $content = curl_exec($cl); curl_close($cl); return ($content); } } ?>
server.php
<?php include("delivery.php"); $Server=new SoapServer(‘delivery.wsdl‘); //SoapServer $Server->setClass("test"); $Server->handle(); ?>
delivery.wsdl
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://127.0.0.1/urlcode/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="delivery" targetNamespace="http://127.0.0.1/urlcode/"> <wsdl:message name="send_do_deliveryRequest"> <wsdl:part name="orderid" type="xsd:string"></wsdl:part> </wsdl:message> <wsdl:message name="send_do_deliveryResponse"> <wsdl:part name="send_do_deliveryResponse" type="xsd:string"/> </wsdl:message> <wsdl:portType name="delivery"> <wsdl:operation name="send_do_delivery"> <wsdl:input message="tns:send_do_deliveryRequest"/> <wsdl:output message="tns:send_do_deliveryResponse"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="deliverySOAP" type="tns:delivery"> <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="send_do_delivery"> <soap:operation soapAction="http://127.0.0.1/urlcode/send_do_delivery"/> <wsdl:input> <soap:body namespace="http://127.0.0.1/urlcode/" use="literal"/> </wsdl:input> <wsdl:output> <soap:body namespace="http://127.0.0.1/urlcode/" use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="delivery"> <wsdl:port binding="tns:deliverySOAP" name="deliverySOAP"> <soap:address location="http://127.0.0.1/urlcode/server.php"/> </wsdl:port> </wsdl:service> </wsdl:definitions>
deliverySOAP里面要改成server.php的路径
时间: 2024-10-18 13:00:34