用于英国邮件网络服务 api 的 php 肥皂客户端? [英] php soap client for uk mail webservice api?

查看:33
本文介绍了用于英国邮件网络服务 api 的 php 肥皂客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个可以下订单的商业网站上工作.要跟踪该交付,我需要向用户提供一个链接,其中包含用户填写的表单中的所有参数,以创建交付并使用 UK Mail 和邮件中提供的链接跟踪其状态.

我必须使用 UK Mail Web Service API.谁能告诉我怎么做?我是 SOAP WSDL 的新手.

根据我的理解,我现在这样做了如何走得更远?我需要的只是基本客户端下面的代码:

  1. 验证登录并使用验证令牌

  2. 我需要发送参数来创建国内作业

  3. 我也需要跟踪送货状态

这是我更新的代码:

Username = 'xxx can't show here xxx';$LoginWebRequest->Password = 'xxx不能在这里显示xxx';//echo "

";打印_r($LoginWebRequest);"</pre>";出口;$Login = new stdClass();$Login->loginWebRequest = $LoginWebRequest;//echo "

";打印_r($登录);"</pre>";出口;$soapClient = new SoapClient('somewsdl?wsdl');$LoginResponse = $soapClient->Login($Login);//echo "

";打印_r($登录响应);"</pre>";出口;$LoginResponse = $soapClient->Login($Login);//-- 直到这里我的代码运行良好并且还给出了失败的输出但是添加代码//下面给了我错误无法找出问题所在$AuthenticationToken = $LoginResponse->LoginResult->AuthenticationToken;$AddDomesticConsignmentWebRequest = new stdClass();$AddDomesticConsignmentWebRequest->用户名 = 'xxxxxx';//设置上一步中的身份验证令牌$AddDomesticConsignmentWebRequest->AuthenticationToken = $AuthenticationToken ;//其他属性在这里设置...$AddDomesticConsignment = new stdClass();$AddDomesticConsignment->request = $AddDomesticConsignmentWebRequest;$soapClient = new SoapClient('https://svc?wsdl');$AddDomesticConsignmentResponse = $soapClient->AddDomesticConsignment($AddDomesticConsignment);?>

我已经解决了所有问题并得到了我的委托,不需要跟踪我的 api

我的xml是这样的或者你可以查看pdf

 XML 请求示例:<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:thir="http://webapp-cl.internet-delivery.com/ThirdPartyIntegrationService"><soap:Header/><肥皂:身体><thir:ConsignmentTrackingSearchV1><thir:UserName>mail.com</thir:UserName><thir:密码>123</thir:密码><thir:Token></thir:Token><thir:ConsignmentNumber>01161</thir:ConsignmentNumber><thir:IsPartialConsignmentNumber>false</thir:IsPartialConsignmentNumber><thir:CustomerReference></thir:CustomerReference><thir:IsPartialCustomerReference>false</thir:IsPartialCustomerReference><thir:DeliveryPostCode></thir:DeliveryPostCode><thir:MailingID></thir:MailingID><thir:MaxResults>100</thir:MaxResults></thir:ConsignmentTrackingSearchV1></soap:Body></soap:Envelope>

示例 xml 响应

 <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><肥皂:身体><ConsignmentTrackingSearchV1Response xmlns="http://webapp-cl.internet-delivery.com/ThirdPartyIntegrationService"><ConsignmentTrackingSearchV1Result><ResultState>成功</ResultState><寄售结果><寄售搜索结果><寄售编号>001161</寄售编号><CustomerRef1/><CustomerRef2/><SubCustomerRef1/><SubCustomerRef2/><DeliveryType/><寄售状态>已交付</寄售状态><DateTimeDelivered>2010-02-11T12:00:00+00:00</DateTimeDelivered><已交付项目数>2</已交付项目数><RecipientName>robin</RecipientName><交付评论/><ExpectedDeliveryDate>2010-02-11T00:00:00</ExpectedDeliveryDate><DeliveryService>次日</DeliveryService><TotalItems>2</TotalItems><Consignmentkey>22</Consignmentkey></寄售搜索结果></寄售结果></ConsignmentTrackingSearchV1Result></ConsignmentTrackingSearchV1Response></soap:Body></soap:Envelope>

解决方案

简介

显然,这里缺少文档.不幸的是,$soapClient->__getTypes() 并没有说明什么.它只显示 Web 服务支持的可用复杂类型,但没有向我们展示它们之间的关系.即使你有一个所有可用操作的列表,它们的输入和输出类型由 $soapClient->__getFunctions() 返回,也不能保证你可以在不知道复杂类型的确切性质的情况下继续或者没有任何类型的文件.但幸运的是,这是一个提供 WSDL 文档的基于 SOAP 的 Web 服务.WSDL 文档描述了所有支持的操作和复杂类型,以及它们之间的关系.因此,我们只需检查 WSDL 文档就可以弄清楚如何使用该服务.

有两种方法可以检查 WSDL 文档:

  1. 从 WSDL 文档生成工件(客户端类)并检查工件
  2. 浏览 WSDL 文档和 XML Schema 文档.

1.文物

工件可以由强类型语言(如 Java 或 C#)提供的工具生成.https://qa-api.ukmail.com/Services/UKMAuthenticationServices/ 页面建议使用 svcutil.exe 工具为 C# 编程语言生成工件,或者您也可以使用 wsimport 工具为 Java 编程语言生成工件.我怀疑是否有任何好的工具可以为 PHP 编程语言生成工件.

2.WSDL 文档和 XML 模式

如果您不熟悉 C# 或 Java,您始终可以通过查看 WSDL 文档和 XML 模式来检查它.XML 模式可以包含在 WSDL 文档中或从外部文件导入.WSDL 文档描述了可以在 Web 服务上执行的操作,而 XML 模式描述了复杂的类型及其关系.

行动

我写了介绍部分,所以你知道如何自己做.下面我想展示一个例子.为了检查 WSDL 文档,我使用了两种方法.首先,我使用 wsimport 工具生成了工件,然后我阅读了大量 XML.

此服务的 WSDL 文档使用 import 语句分成几个文件.因此,为了找到所有操作和复杂类型,您必须遵循 import 语句.

身份验证

如果我们查看身份验证服务的 WSDL 文档(location),我们可以看到它导入了另一个WSDL文档:

<wsdl:import namespace="http://tempuri.org/" location="https://qa-api.ukmail.com/Services/UKMAuthenticationServices/UKMAuthenticationService.svc?wsdl=wsdl1"/>

后者(location),在其反过来,导入另一个:

<wsdl:import namespace="http://www.UKMail.com/Services/Contracts/ServiceContracts" location="https://qa-api.ukmail.com/Services/UKMAuthenticationServices/UKMAuthenticationService.svc?wsdl=wsdl0"/>

最后一个(location),导入所有相关的 XML 模式:

<xsd:schema targetNamespace="http://www.UKMail.com/Services/Contracts/ServiceContracts/Imports"><xsd:import schemaLocation="https://qa-api.ukmail.com/Services/UKMAuthenticationServices/UKMAuthenticationService.svc?xsd=xsd0" namespace="http://www.UKMail.com/Services/Contracts/ServiceContracts"/><xsd:import schemaLocation="https://qa-api.ukmail.com/Services/UKMAuthenticationServices/UKMAuthenticationService.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/><xsd:import schemaLocation="https://qa-api.ukmail.com/Services/UKMAuthenticationServices/UKMAuthenticationService.svc?xsd=xsd2" namespace="http://www.UKMail.com/Services/Contracts/DataContracts"/><xsd:import schemaLocation="https://qa-api.ukmail.com/Services/UKMAuthenticationServices/UKMAuthenticationService.svc?xsd=xsd3" namespace="http://schemas.datacontract.org/2004/07/UKMWebAPICommon.WebResponses"/></xsd:schema></wsdl:types>

还描述了也可以通过调用$soapClient->__getFunctions()查看的操作:

数组([0] =>登录响应登录(登录$参数)[1] =>LogoutResponse Logout(Logout $parameters))

在这里,我们看到 Login() 操作接受 Login 类型的 $parameters 作为它的参数并返回 Login 类型的响应代码>登录响应.这是它在 WSDL 文档中的样子:

<wsdl:input wsaw:Action="http://www.UKMail.com/Services/IUKMAuthenticationService/Login" message="tns:IUKMAuthenticationService_Login_InputMessage"/><wsdl:output wsaw:Action="http://www.UKMail.com/Services/Contracts/ServiceContracts/IUKMAuthenticationService/LoginResponse" message="tns:IUKMAuthenticationService_Login_OutputMessage"/></wsdl:操作>

Login 是一种复杂类型,这可以在导入的 XML Schema 文档之一(schemaLocation):

<xs:complexType><xs:序列><xs:element xmlns:q1="http://www.UKMail.com/Services/Contracts/DataContracts" minOccurs="0" name="loginWebRequest" nillable="true" type="q1:LoginWebRequest"/></xs:sequence></xs:complexType></xs:element>

它有一个名为 loginWebRequest 的元素,它也是一个名为 LoginWebRequest 的复杂类型,它在另一个导入的 XML 模式中进行了描述:

<xs:序列><xs:element name="密码" nillable="true" type="xs:string"/><xs:element name="用户名" nillable="true" type="xs:string"/></xs:sequence></xs:complexType>

LoginWebRequest 更简单.它有两种简单类型UsernamePassword,类型为String.

在 PHP 中,复杂类型由 stdClass 的对象表示.因此,为了调用 Login() 操作,我们必须创建两个对象 LoginLoginWebRequest:

$LoginWebRequest = new stdClass();$LoginWebRequest->用户名 = '用户名';$LoginWebRequest->Password = 'p@$$w0rd';$Login = new stdClass();$Login->loginWebRequest = $LoginWebRequest;$soapClient = new SoapClient('https://qa-api.ukmail.com/Services/UKMAuthenticationServices/UKMAuthenticationService.svc?wsdl');$LoginResponse = $soapClient->Login($Login);

这给了我们一个 LoginResponse 类型的结果:

<xs:complexType><xs:序列><xs:element xmlns:q2="http://www.UKMail.com/Services/Contracts/DataContracts" minOccurs="0" name="LoginResult" nillable="true" type="q2:UKMLoginResponse"/></xs:sequence></xs:complexType></xs:element>

,其中包含一个名为 LoginResult 的元素,其类型为 UKMLoginResponse:

<xs:complexContent mixed="false"><xs:extension base="tns:UKMWebResponse"><xs:序列><xs:element minOccurs="0" name="Accounts" nillable="true" type="tns:ArrayOfAccountWebModel"/><xs:element name="AuthenticationToken" nillable="true" type="xs:string"/></xs:sequence></xs:extension></xs:complexContent></xs:complexType>

UKMLoginResponse 有两个自己的 Accounts 元素,类型为 ArrayOfAccountWebModelAuthenticationToken 类型为 String 和从 UKMWebResponse 继承的另外三个元素(注意 extension 语句)Errors 类型 ArrayOfUKMWebErrorWarnings 类型 ArrayOfUKMWebWarningResult 类型 UKMResultState:

<xs:序列><xs:element minOccurs="0" name="Errors" nillable="true" type="tns:ArrayOfUKMWebError"/><xs:element xmlns:q1="http://schemas.datacontract.org/2004/07/UKMWebAPICommon.WebResponses" name="Result" type="q1:UKMResultState"/><xs:element minOccurs="0" name="Warnings" nillable="true" type="tns:ArrayOfUKMWebWarning"/></xs:sequence></xs:complexType>

在由 wsimport 工具生成的工件中,它看起来像这样:

public class UKMLoginResponse extends UKMWebResponse { ... }

因此,为了从 LoginResponse 获取身份验证令牌,我们执行以下操作:

$LoginResponse = $soapClient->Login($Login);$AuthenticationToken = $LoginResponse->LoginResult->AuthenticationToken;

调用方法

这里我不会很具体,因为它与我们上面所做的非常相似.

举个例子,让我们调用一个 AddDomesticConsignment() 方法.根据寄售服务的WSDL文档和$soapClient->__getFunctions()返回的结果,AddDomesticConsignment()方法需要一个$parametersAddDomesticConsignment 类型的 code> 参数,并返回 AddDomesticConsignmentResponse 类型的结果.通过分析 AddDomesticConsignment 复杂类型,我们看到它有一个名为 request 的元素,类型为 AddDomesticConsignmentWebRequest,它扩展了 AddConsignmentWebRequest它本身扩展了 WebRequest.以下是 AddDomesticConsignmentWebRequest 类型的所有元素的列表:

//添加DomesticConsignmentWebRequest 自己的元素布尔值十进制 CODA 量字符串确认电子邮件字符串确认电话布尔型 ExchangeOnDelivery整数扩展覆盖布尔值长长度PreDeliveryNotificationType PreDeliveryNotification字符串 SecureLocation1字符串 SecureLocation2布尔签名可选//从 AddConsignmentWebRequest 继承的元素字符串帐号地址WebModel地址字符串 AlternativeRef字符串企业名称字符串 CollectionJobNumber布尔值 ConfirmationOfDelivery字符串联系人姓名字符串客户引用字符串 电子邮件整数项内部服务密钥字符串特殊说明1字符串特殊说明2字符串电话十进制重量//从 WebRequest 继承的元素字符串用户名字符串 AuthenticationToken

请注意,并非所有元素都是必需的.那些可选的在 XML 架构中将 minOccurs 属性设置为 0.

所以,最终我们是这样调用方法的:

$AddDomesticConsignmentWebRequest = new stdClass();$AddDomesticConsignmentWebRequest->用户名 = '用户名';//设置上一步中的身份验证令牌$AddDomesticConsignmentWebRequest->AuthenticationToken = $AuthenticationToken;//其他属性在这里设置...$AddDomesticConsignment = new stdClass();$AddDomesticConsignment->request = $AddDomesticConsignmentWebRequest;$soapClient = new SoapClient('https://qa-api.ukmail.com/Services/UKMConsignmentServices/UKMConsignmentService.svc?wsdl');$AddDomesticConsignmentResponse = $soapClient->AddDomesticConsignment($AddDomesticConsignment);

AddDomesticConsignmentResponse 被解析为 We parse the LoginResponse 根据其在 XML Schema 文档中的定义.

好吧,我想这就是全部.我自己没有尝试过,但理论上应该可以.希望这会有所帮助.

更新

根据文件跟踪货物应该像执行以下操作一样简单:

//创建 SOAP 客户端$soapClient = new SoapClient('http://web-service/?wsdl');//调用`ConsignmentTrackingSearchV1`方法并传递搜索参数$ConsignmentTrackingSearchV1Response = $soapClient->ConsignmentTrackingSearchV1('mail.com',//用户名'123',//密码'',//令牌'01161',//托运编号'false',//IsPartialConsignmentNumber'',//客户参考'false'//IsPartialCustomerReference'',//送货邮政编码'',//邮件ID100//最大结果);//解析响应$ConsignmentTrackingSearchV1Result = $ConsignmentTrackingSearchV1Response->ConsignmentTrackingSearchV1Result;$ResultState = $ConsignmentTrackingSearchV1Result->ResultState;//成功的$ConsignmentResults = $ConsignmentTrackingSearchV1Result->ConsignmentResults;//遍历`ConsignmentResults`foreach ($ConsignmentResults 作为 $ConsignmentSearchResult) {$ConsignmentNumber = $ConsignmentSearchResult->ConsignmentNumber;$ConsignmentStatus = $ConsignmentSearchResult->ConsignmentStatus;//其他属性}

就是这样!

I'm working on a commerce site on which orders are placed. To track that delivery I need to give a link to users with all the parameters from a form filled by user to create a delivery and track its status using UK Mail with the link provided in a mail.

I have to use UK Mail Web Service API. Can anyone show me how to do so? I am new to SOAP WSDL.

From my understanding i did this now how to go further? My code below its just basic client i need to:

  1. authenticate login and use the authenticate token

  2. I need to send the parameters to create a domestic assignments

  3. I need to track the delivery status too

here is my updated code :

<?php 

$LoginWebRequest = new stdClass();
$LoginWebRequest->Username = 'xxx cant show here xxx';
$LoginWebRequest->Password = 'xxx cant show here xxx';

//echo "<pre>";  print_r($LoginWebRequest); "</pre>"; exit;

$Login = new stdClass();
$Login->loginWebRequest = $LoginWebRequest;

//echo "<pre>";  print_r($Login); "</pre>"; exit; 

$soapClient = new SoapClient('somewsdl?wsdl');
$LoginResponse = $soapClient->Login($Login);

//echo "<pre>";  print_r($LoginResponse); "</pre>"; exit; 

$LoginResponse = $soapClient->Login($Login);


// -- till here my code runs fine and also gives the failed output but adding the code //below gives me error cant find out whats wrong 


$AuthenticationToken = $LoginResponse->LoginResult->AuthenticationToken;



$AddDomesticConsignmentWebRequest = new stdClass();
$AddDomesticConsignmentWebRequest->Username = 'xxxxxx';
// setting the Authentication Token from the previous step
$AddDomesticConsignmentWebRequest->AuthenticationToken = $AuthenticationToken ;
// other properties are set here...

$AddDomesticConsignment = new stdClass();
$AddDomesticConsignment->request = $AddDomesticConsignmentWebRequest;


$soapClient = new SoapClient('https://svc?wsdl');
$AddDomesticConsignmentResponse = $soapClient->AddDomesticConsignment($AddDomesticConsignment);


?>

i have solved all and got my consignment no too just need to track my api

my xml is like this or u can check the pdf

     Example XML Request:
    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"        xmlns:thir="http://webapp-cl.internet-delivery.com/ThirdPartyIntegrationService">
    <soap:Header/>
    <soap:Body>
    <thir:ConsignmentTrackingSearchV1>
    <thir:UserName>mail.com</thir:UserName>
    <thir:Password>123</thir:Password>
    <thir:Token></thir:Token>
    <thir:ConsignmentNumber>01161</thir:ConsignmentNumber>
    <thir:IsPartialConsignmentNumber>false</thir:IsPartialConsignmentNumber>
    <thir:CustomerReference></thir:CustomerReference>
    <thir:IsPartialCustomerReference>false</thir:IsPartialCustomerReference>
    <thir:DeliveryPostCode></thir:DeliveryPostCode>
    <thir:MailingID></thir:MailingID>
    <thir:MaxResults>100</thir:MaxResults>
    </thir:ConsignmentTrackingSearchV1>
    </soap:Body>
    </soap:Envelope>

example xml response

      <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       <soap:Body>
       <ConsignmentTrackingSearchV1Response xmlns="http://webapp-cl.internet- delivery.com/ThirdPartyIntegrationService">
        <ConsignmentTrackingSearchV1Result>
        <ResultState>Successful</ResultState>
         <ConsignmentResults>
       <ConsignmentSearchResult>
    <ConsignmentNumber>001161</ConsignmentNumber>
    <CustomerRef1/>
   <CustomerRef2/>
     <SubCustomerRef1/>
     <SubCustomerRef2/>
      <DeliveryType/>
      <ConsignmentStatus>Delivered</ConsignmentStatus>
      <DateTimeDelivered>2010-02-11T12:00:00+00:00</DateTimeDelivered>
      <ItemsDelivered>2</ItemsDelivered>
      <RecipientName>robin</RecipientName>
      <DeliveryComments/>
      <ExpectedDeliveryDate>2010-02-11T00:00:00</ExpectedDeliveryDate>
       <DeliveryService>Next Day</DeliveryService>
      <TotalItems>2</TotalItems>
      <Consignmentkey>22</Consignmentkey>
        </ConsignmentSearchResult>
         </ConsignmentResults>
        </ConsignmentTrackingSearchV1Result>
        </ConsignmentTrackingSearchV1Response>
        </soap:Body>
       </soap:Envelope>

解决方案

Introduction

Obviously, documentation is missing here. Unfortunately, $soapClient->__getTypes() doesn't tell much. It only shows available complex types supported by a web service, but it doesn't show us the relationship among them. Even if You have a list of all available operations with their input and output types returned by $soapClient->__getFunctions(), there is no guarantee You can proceed without knowing the exact nature of the complex types or without having any kind of documentation. But fortunately, this is a SOAP-based web service that provides a WSDL document. The WSDL document describes all the supported operations and complex types, as well as their relationships. So, we can figure out how to use the service by only examining the WSDL document.

There are two ways of examining the WSDL document:

  1. generate artifacts (client classes) from the WSDL document and examine the artifacts
  2. look through the WSDL document and the XML Schema documents.

1. Artifacts

The artifacts can be generated by tools provided by the strong typed languages like Java or C#. The https://qa-api.ukmail.com/Services/UKMAuthenticationServices/ page suggests to use the svcutil.exe tool to generate the artifacts for the C# programming language, or You can also use the wsimport tool to generate the artifacts for the Java programming language. I doubt that there can be any good tool for generating the artifacts for the PHP programming language.

2. WSDL document and XML Schemas

If You're not familiar with C# or Java, You can always examine the WSDL document by looking through it and the XML Schemas. The XML Schemas can be included in the WSDL document or imported from an external file. While the WSDL document describes the operations that can be performed on the web service, the XML Schemas describe the complex types and their relationships.

Action

I wrote the Introduction part so that You know how to do it on Your own. Below I want to show an example of it. For the purpose of examining the WSDL document I used both ways. First I generated the artifacts using the wsimport tool, then I read a lot of XML.

The WSDL document for this service is divided into several files using import statements. So, in order to find all the operations and complex types You have to follow the import statements.

Authentication

If We look at the Authentication Service's WSDL document (location), We can see that it imports another WSDL document:

<wsdl:import namespace="http://tempuri.org/" location="https://qa-api.ukmail.com/Services/UKMAuthenticationServices/UKMAuthenticationService.svc?wsdl=wsdl1"/>

The latter (location), in its turn, imports another one:

<wsdl:import namespace="http://www.UKMail.com/Services/Contracts/ServiceContracts" location="https://qa-api.ukmail.com/Services/UKMAuthenticationServices/UKMAuthenticationService.svc?wsdl=wsdl0"/>

The final one (location), imports all the related XML Schemas:

<wsdl:types>
  <xsd:schema targetNamespace="http://www.UKMail.com/Services/Contracts/ServiceContracts/Imports">
    <xsd:import schemaLocation="https://qa-api.ukmail.com/Services/UKMAuthenticationServices/UKMAuthenticationService.svc?xsd=xsd0" namespace="http://www.UKMail.com/Services/Contracts/ServiceContracts"/>
    <xsd:import schemaLocation="https://qa-api.ukmail.com/Services/UKMAuthenticationServices/UKMAuthenticationService.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
    <xsd:import schemaLocation="https://qa-api.ukmail.com/Services/UKMAuthenticationServices/UKMAuthenticationService.svc?xsd=xsd2" namespace="http://www.UKMail.com/Services/Contracts/DataContracts"/>
    <xsd:import schemaLocation="https://qa-api.ukmail.com/Services/UKMAuthenticationServices/UKMAuthenticationService.svc?xsd=xsd3" namespace="http://schemas.datacontract.org/2004/07/UKMWebAPICommon.WebResponses"/>
  </xsd:schema>
</wsdl:types>

It also describes the operations which can also be viewed by calling $soapClient->__getFunctions():

Array
(
    [0] => LoginResponse Login(Login $parameters)
    [1] => LogoutResponse Logout(Logout $parameters)
)

Here, We see that the Login() operation accepts $parameters of type Login as its argument and returns a response of type LoginResponse. This is how it looks in the WSDL document:

<wsdl:operation name="Login">
  <wsdl:input wsaw:Action="http://www.UKMail.com/Services/IUKMAuthenticationService/Login" message="tns:IUKMAuthenticationService_Login_InputMessage"/>
  <wsdl:output wsaw:Action="http://www.UKMail.com/Services/Contracts/ServiceContracts/IUKMAuthenticationService/LoginResponse" message="tns:IUKMAuthenticationService_Login_OutputMessage"/>
</wsdl:operation>

Login is a complex type, this can be seen in one of the imported XML Schema documents (schemaLocation):

<xs:element name="Login">
  <xs:complexType>
    <xs:sequence>
      <xs:element xmlns:q1="http://www.UKMail.com/Services/Contracts/DataContracts" minOccurs="0" name="loginWebRequest" nillable="true" type="q1:LoginWebRequest"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

It has an element named loginWebRequest which is also a complex type called LoginWebRequest which is described in another imported XML Schema:

<xs:complexType name="LoginWebRequest">
  <xs:sequence>
    <xs:element name="Password" nillable="true" type="xs:string"/>
    <xs:element name="Username" nillable="true" type="xs:string"/>
  </xs:sequence>
</xs:complexType>

LoginWebRequest is simpler. It has two simple types Username and Password of type String.

In PHP complex types are represented by objects of stdClass. So, in order to call the Login() operation, We have to create two objects Login and LoginWebRequest:

$LoginWebRequest = new stdClass();
$LoginWebRequest->Username = 'Username';
$LoginWebRequest->Password = 'p@$$w0rd';

$Login = new stdClass();
$Login->loginWebRequest = $LoginWebRequest;

$soapClient = new SoapClient('https://qa-api.ukmail.com/Services/UKMAuthenticationServices/UKMAuthenticationService.svc?wsdl');
$LoginResponse = $soapClient->Login($Login);

This gives us a result of type LoginResponse:

<xs:element name="LoginResponse">
  <xs:complexType>
    <xs:sequence>
      <xs:element xmlns:q2="http://www.UKMail.com/Services/Contracts/DataContracts" minOccurs="0" name="LoginResult" nillable="true" type="q2:UKMLoginResponse"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

, which contains an element named LoginResult which has a type of UKMLoginResponse:

<xs:complexType name="UKMLoginResponse">
  <xs:complexContent mixed="false">
    <xs:extension base="tns:UKMWebResponse">
      <xs:sequence>
        <xs:element minOccurs="0" name="Accounts" nillable="true" type="tns:ArrayOfAccountWebModel"/>
        <xs:element name="AuthenticationToken" nillable="true" type="xs:string"/>
      </xs:sequence>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>

UKMLoginResponse has two elements of its own Accounts of type ArrayOfAccountWebModel and AuthenticationToken of type String and three more elements inhereted from UKMWebResponse (note the extension statement) Errors of type ArrayOfUKMWebError, Warnings of type ArrayOfUKMWebWarning and Result of type UKMResultState:

<xs:complexType name="UKMWebResponse">
  <xs:sequence>
    <xs:element minOccurs="0" name="Errors" nillable="true" type="tns:ArrayOfUKMWebError"/>
    <xs:element xmlns:q1="http://schemas.datacontract.org/2004/07/UKMWebAPICommon.WebResponses" name="Result" type="q1:UKMResultState"/>
    <xs:element minOccurs="0" name="Warnings" nillable="true" type="tns:ArrayOfUKMWebWarning"/>
  </xs:sequence>
</xs:complexType>

In the artifacts generated by the wsimport tool it looks like this:

public class UKMLoginResponse extends UKMWebResponse { ... }

So, in order to get the authentication token from the LoginResponse, we do the following:

$LoginResponse = $soapClient->Login($Login);
$AuthenticationToken = $LoginResponse->LoginResult->AuthenticationToken;

Calling a method

I won't be very specific here, because it's very similar to what we did above.

As an example, let's call a AddDomesticConsignment() method. According to the WSDL document of the Consignment Service and the result returned by $soapClient->__getFunctions() the AddDomesticConsignment() method takes one $parameters argument of type AddDomesticConsignment and returns a result of type AddDomesticConsignmentResponse. By analyzing the AddDomesticConsignment complex type, we see that it has an element named request of type AddDomesticConsignmentWebRequest which extends AddConsignmentWebRequest which itself extends WebRequest. Following is the list of all of the elements of the AddDomesticConsignmentWebRequest type:

// AddDomesticConsignmentWebRequest's own elements
boolean BookIn
decimal CODAmount
string ConfirmationEmail
string ConfirmationTelephone
boolean ExchangeOnDelivery
int ExtendedCover
boolean LongLength
PreDeliveryNotificationType PreDeliveryNotification
string SecureLocation1
string SecureLocation2
boolean SignatureOptional

// elements inhereted from AddConsignmentWebRequest
string AccountNumber
AddressWebModel Address
string AlternativeRef
string BusinessName
string CollectionJobNumber
boolean ConfirmationOfDelivery
string ContactName
string CustomersRef
string Email
int Items
int ServiceKey
string SpecialInstructions1
string SpecialInstructions2
string Telephone
decimal Weight

// elements inhereted from WebRequest
string Username
string AuthenticationToken

Note that not all of the elements are required. Those which are optional have the minOccurs attribute set to 0 in the XML Schema.

<xs:element minOccurs="0" name="PreDeliveryNotification" type="tns:PreDeliveryNotificationType"/>

So, eventually this is how We call the method:

$AddDomesticConsignmentWebRequest = new stdClass();
$AddDomesticConsignmentWebRequest->Username = 'Username';
// setting the Authentication Token from the previous step
$AddDomesticConsignmentWebRequest->AuthenticationToken = $AuthenticationToken;
// other properties are set here...

$AddDomesticConsignment = new stdClass();
$AddDomesticConsignment->request = $AddDomesticConsignmentWebRequest;

$soapClient = new SoapClient('https://qa-api.ukmail.com/Services/UKMConsignmentServices/UKMConsignmentService.svc?wsdl');
$AddDomesticConsignmentResponse = $soapClient->AddDomesticConsignment($AddDomesticConsignment);

The AddDomesticConsignmentResponse is parsed as We parsed the LoginResponse according to its definition in the XML Schema document.

Well, I guess this is all to it. I didn't try it myself, but in theory it should work. Hope this helps.

UPDATE

According to the documentation tracking the consignment should be as easy as doing the following:

// create the SOAP client
$soapClient = new SoapClient('http://web-service/?wsdl');
// call the `ConsignmentTrackingSearchV1` method and pass the search parameters
$ConsignmentTrackingSearchV1Response = $soapClient->ConsignmentTrackingSearchV1(
    'mail.com', // Username
    '123',      // Password
    '',         // Token
    '01161',    // ConsignmentNumber
    'false',    // IsPartialConsignmentNumber
    '',         // CustomerReference
    'false'     // IsPartialCustomerReference
    '',         // DeliveryPostCode
    '',         // MailingID
    100         // MaxResults
);
// parse the response
$ConsignmentTrackingSearchV1Result = $ConsignmentTrackingSearchV1Response->ConsignmentTrackingSearchV1Result;
$ResultState = $ConsignmentTrackingSearchV1Result->ResultState; // Successful
$ConsignmentResults = $ConsignmentTrackingSearchV1Result->ConsignmentResults;
// loop through the `ConsignmentResults`
foreach ($ConsignmentResults as $ConsignmentSearchResult) {
    $ConsignmentNumber = $ConsignmentSearchResult->ConsignmentNumber;
    $ConsignmentStatus = $ConsignmentSearchResult->ConsignmentStatus;
    // other properties
}

That's it!

这篇关于用于英国邮件网络服务 api 的 php 肥皂客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆