簡體   English   中英

PHP的SOAP客戶端的請求與方法參數-如何?

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

有這樣的肥皂方法

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>

回應就是這樣

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>

我連接到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);

結果是這樣的

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. ) )

問題是我不太確定用php調用此方法的正確方法是什么。 我認為令牌和輸入參數必須與內部數組一起發送嗎? 但是我該怎么辦呢?

謝謝。

由於wsdltophp https://github.com/mikaelcom/WsdlToPhp ,從php調用soap方法確實非常困難。

我通過生成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