有像这样的肥皂方法
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调用此方法的正确方法是什么。我认为必须使用内部数组发送令牌和输入参数?但是我该怎么做呢?
感谢。
答案 0 :(得分:0)
从php调用soap方法真的很难,多亏了wsdltophp https://github.com/mikaelcom/WsdlToPhp
我通过生成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());
}