简体   繁体   English

PHP的SOAP客户端的请求与方法参数-如何?

[英]php soap client request with method parameters - how?

There is a soap method like that 有这样的肥皂方法

POST /webservice/mobilepayment.asmx HTTP/1.1
Host: portal.mobilaidat.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/MPaymentBasic"

<?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:Body>
    <MPaymentBasic xmlns="http://tempuri.org/">
      <token>
        <FirmWebCode>string</FirmWebCode>
        <UserName>string</UserName>
        <Password>string</Password>
      </token>
      <input>
        <GsmNo>string</GsmNo>
        <ProductCode>string</ProductCode>
        <ProductPrice>decimal</ProductPrice>
        <SendTransactionResult>boolean</SendTransactionResult>
        <ServiceTypeID>int</ServiceTypeID>
        <PaymentTypeID>int</PaymentTypeID>
        <FirmMPaymentRefID>string</FirmMPaymentRefID>
        <WebUrl>string</WebUrl>
        <ClientIP>string</ClientIP>
      </input>
    </MPaymentBasic>
  </soap:Body>
</soap:Envelope>

And response is like that 回应就是这样

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?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:Body>
    <MPaymentBasicResponse xmlns="http://tempuri.org/">
      <MPaymentBasicResult>
        <TransactionID>long</TransactionID>
        <StatusCode>int</StatusCode>
        <ErrorCode>string</ErrorCode>
        <ErrorDesc>string</ErrorDesc>
      </MPaymentBasicResult>
    </MPaymentBasicResponse>
  </soap:Body>
</soap:Envelope>

I connected to wsdl and created a soap client 我连接到wsdl并创建了一个肥皂客户端

$client = new SoapClient($wsdl_url);
$params = array('FirmWebCode' =>'234234234234232342','UserName' =>'YYASASASd','Password' =>'4PHPY3','GsmNo' =>'5424444444','ProductPrice' =>'1','SendTransactionResult' =>True,'ServiceTypeID' =>0,'PaymentTypeID' =>0,'FirmMPaymentRefID' =>234234);

    $response=$client->MPaymentBasic('MPaymentBasic', array('parameters' => $params));
print_r($response);

And result is like that 结果是这样的

stdClass Object ( [MPaymentBasicResult] => stdClass Object ( [TransactionID] => 0 [StatusCode] => 1 [ErrorCode] => Object reference not set to an instance of an object. [ErrorDesc] => Object reference not set to an instance of an object. ) )

The question is I am not really sure what is the proper way of calling this method with php. 问题是我不太确定用php调用此方法的正确方法是什么。 I think token and input parameters must be send with inner arrays? 我认为令牌和输入参数必须与内部数组一起发送吗? But how can I do that? 但是我该怎么办呢?

Thanks. 谢谢。

Calling soap method from php is really difficult, thanks to wsdltophp https://github.com/mikaelcom/WsdlToPhp 由于wsdltophp https://github.com/mikaelcom/WsdlToPhp ,从php调用soap方法确实非常困难。

I solved this by genrating soap classes and sending parameters inside generated functions like that; 我通过生成soap类并在生成的函数中发送参数来解决了这个问题;

   $mobilePaymentServiceMP = new MobilePaymentServiceMP();
    // sample call for MobilePaymentServiceMP::MPaymentBasic()

    $tokenVar=new MobilePaymentStructWSAuthToken('XXXXXXXXXXX','XXXXXX','XXXXX');
    /**
         * Constructor method for WSAuthToken
         * @see parent::__construct()
         * @param string $_firmWebCode
         * @param string $_userName
         * @param string $_password
         * @return MobilePaymentStructWSAuthToken
         */


    $inputVar= new MobilePaymentStructWSMPaymentBasicInput(1,true,0,0,'XXXXXXXXX','XXXXXXXXX','testttttt','http://www.XXXXXXXX.com','192.168.1.1'); 
/**
         * Constructor method for WSMPaymentBasicInput
         * @see parent::__construct()
         * @param decimal $_productPrice
         * @param boolean $_sendTransactionResult
         * @param int $_serviceTypeID
         * @param int $_paymentTypeID
         * @param string $_gsmNo
         * @param string $_productCode
         * @param string $_firmMPaymentRefID
         * @param string $_webUrl
         * @param string $_clientIP
         * @return MobilePaymentStructWSMPaymentBasicInput
         */



    $tmpVar=new MobilePaymentStructMPaymentBasic($tokenVar,$inputVar);
    /**
         * Constructor method for MPaymentBasic
         * @see parent::__construct()
         * @param MobilePaymentStructWSAuthToken $_token
         * @param MobilePaymentStructWSMPaymentBasicInput $_input
         * @return MobilePaymentStructMPaymentBasic
         */

    if($mobilePaymentServiceMP->MPaymentBasic($tmpVar)) {
        ECHO "CALLED OK;<br>";
        print_r($mobilePaymentServiceMP->getResult());
        }
    else {
        ECHO "CALLED ERROR;<br>";
        print_r($mobilePaymentServiceMP->getLastError());
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM