2015-09-04 88 views
1

有這樣PHP soap客戶端請求與方法參數 - 如何?

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和創建的SOAP客戶端

$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調用這個方法的正確方法。我認爲令牌和輸入參數必須用內部數組發送?但我該怎麼做?

謝謝。從PHP

回答

0

調用皁的方法是非常困難,這要歸功於wsdltophp https://github.com/mikaelcom/WsdlToPhp

我通過genrating皁類和類似的生成的函數內發送參數解決了這一;

$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()); 
     }