如何在PHP中对REST端点执行HTTPS发布

时间:2011-09-16 12:01:15

标签: php soap curl payment-gateway

我有以下XML。用于在POLi支付网关中启动新交易。

<InitiateTransactionRequest
xmlns="http://schemas.datacontract.org/2004/07/Centricom.POLi.Services.MerchantAPI.Contract
s" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<AuthenticationCode>MerchantPassword</AuthenticationCode>
<Transaction
xmlns:dco="http://schemas.datacontract.org/2004/07/Centricom.POLi.Services.MerchantAPI.DCO"
>
<dco:CurrencyAmount>15.00</dco:CurrencyAmount>
<dco:CurrencyCode>AUD</dco:CurrencyCode>
<dco:MerchantCheckoutURL>http://www.pricebusterdvd.com/checkout</dco:MerchantCheckoutURL>
<dco:MerchantCode>PriceBusterDVD</dco:MerchantCode>
<dco:MerchantData>MerchantDataAssociatedWithTransaction</dco:MerchantData>
<dco:MerchantDateTime>2008-08-18T14:01:02</dco:MerchantDateTime>
<dco:MerchantHomePageURL>http://www.pricebusterdvd.com/home</dco:MerchantHomePageURL>
<dco:MerchantRef>MerchantReferenceAssociateWithTransaction</dco:MerchantRef>
<dco:NotificationURL>http://www.pricebusterdvd.com/notification</dco:NotificationURL>
<dco:SelectedFICode i:nil="true" />
<dco:SuccessfulURL>http://www.pricebusterdvd.com/successful</dco:SuccessfulURL>
<dco:Timeout>1000</dco:Timeout>
<dco:UnsuccessfulURL>http://www.pricebusterdvd.com/unsuccessful</dco:UnsuccessfulURL>
<dco:UserIPAddress>65.2.45.1</dco:UserIPAddress>
</Transaction>
</InitiateTransactionRequest>

这是REST端点URL ..

  

https://merchantapi.apac.paywithpoli.com/MerchantAPIService.svc/Xml/transaction/initiate

The request content-type must be set to ‘text/xml’ and the following XML data included within the request body:

我尝试使用CURL发送但收到错误..

$url='https://merchantapi.apac.paywithpoli.com/MerchantAPIService.svc/Xml/transaction/initiate';   
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_PORT, $server['port']);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
    curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
    curl_setopt($curl, CURLOPT_POSTFIELDS, $parameters);  
    $response = curl_exec($curl);       $response=str_replace('<a:','<',$response);$response=str_replace('</a:','</',$response);
    $result = simplexml_load_string($response);
    print_r($result);

错误 SimpleXMLElement对象([Code] =&gt; SimpleXMLElement对象([Value] =&gt; Receiver [Subcode] =&gt; SimpleXMLElement对象([Value] =&gt; a:InternalServiceFault))[Reason] =&gt; SimpleXMLElement对象([Text] =&gt;由于内部错误,服务器无法处理请求。有关错误的更多信息,请在服务器上启用IncludeExceptionDetailInFaults(来自ServiceBehaviorAttribute或来自配置行为)以发送异常信息返回到客户端,或根据Microsoft .NET Framework 3.0 SDK文档打开跟踪并检查服务器跟踪日志。))

0 个答案:

没有答案