PHP:Curl https xml结果返回空白 [英] PHP : Curl https xml result returns blank

查看:559
本文介绍了PHP:Curl https xml结果返回空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请需要您的帮助!我试图创建一个PHP的肥皂客户端curl。当我运行我的PHP代码。我得到空白的结果。
这是一个https连接。我通过此示例生成包含OpenSSL的.pem文件



PHP CODE


  $ xml ='< ;?xml version =1.0encoding =utf-8?>'。 
'< x:Envelope xmlns:x =http://schemas.xmlsoap.org/soap/envelope/xmlns:req =http://olp.sadad.com/sadadpaymentmanagement/service/olppaymentmanager / req>'。
'< x:Header />'。
'< x:Body>'。
'< req:initiatePaymentDetailsReq>'。
'< req:olpIdAlias> *****< / req:olpIdAlias>'。
'< req:merchantId> *****< / req:merchantId>'。
'< req:merchantRefNum> 999454564< / req:merchantRefNum>'。
'< req:paymentAmount> 200< / req:paymentAmount>'。
'< req:paymentCurrency> SAR< / req:paymentCurrency>'。
'< req:dynamicMerchantLandingURL>< / req:dynamicMerchantLandingURL>'。
'< req:dynamicMerchantFailureURL>< / req:dynamicMerchantFailureURL>'。
'< / req:initiatePaymentDetailsReq>'。
'< / x:Body>'。
'< / x:Envelope>';
try {
$ url =https://b2brbtest.riyadbank.com/soap?service=RB_OLP_INITIATE_PAYMENT;
$ certFile = dirname(__ FILE __)。/ key1.pem;
$ certPass =*******;
$ ch = curl_init();
curl_setopt($ ch,CURLOPT_URL,$ url);
curl_setopt($ ch,CURLOPT_VERBOSE,true);
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ ch,CURLOPT_SSL_VERIFYHOST,false);
curl_setopt($ ch,CURLOPT_SSLCERT,$ certFile);
curl_setopt($ ch,CURLOPT_SSLCERTPASSWD,$ certPass);
$ headers = array();
array_push($ headers,Content-Type:text / xml; charset = utf-8);
array_push($ headers,SOAPAction:sii:RB_OLP_INITIATE_PAYMENT);

if($ xml!= null){
curl_setopt($ ch,CURLOPT_POSTFIELDS,$ xml);
array_push($ headers,Content-Length:。strlen($ xml));
}

curl_setopt($ ch,CURLOPT_POST,true);
curl_setopt($ ch,CURLOPT_HTTPHEADER,$ headers);
$ response = curl_exec($ ch);
$ code = curl_getinfo($ ch,CURLINFO_HTTP_CODE);
curl_close($ ch);
var_dump($ response);

} catch(Exception $ e){
echo $ e-> getMessage();


}

?>

OUTPUT



< blockquote>

string(228)



解决方案通过更改$ xml值解决此问题

  $ xml ='< soapenv:Envelope xmlns:soapenv =http:// schemas .xmlsoap.org / soap / envelope /xmlns:req =http://olp.bank.com/sappay/service/olppaymentmanager/req> 
< soapenv:Header />
< soapenv:Body>
< req:initiatePaymentDetailsReq>
< olpIdAlias> ****< / olpIdAlias>
< merchantId> ***< / merchantId>
< merchantRefNum>'。rand(1,15).rand()。< / merchantRefNum>
< paymentAmount>'。$ tb。'< / paymentAmount>
< paymentCurrency> SAR< / paymentCurrency>
< dynamicMerchantLandingURL>< / dynamicMerchantLandingURL>
< dynamicMerchantFailureURL>< / dynamicMerchantFailureURL>
< / req:initiatePaymentDetailsReq>
< / soapenv:Body>
< / soapenv:Envelope>';

这里是如何使用ssl连接SOAP webservice的完整代码

 <?php 
$ tb ='200';

$ xml ='< soapenv:Envelope xmlns:soapenv =http://schemas.xmlsoap.org/soap/envelope/xmlns:req =http://olp.bank。 com / sappay / service / olppaymentmanager / req>
< soapenv:Header />
< soapenv:Body>
< req:initiatePaymentDetailsReq>
< olpIdAlias> *****< / olpIdAlias>
< merchantId> ********< / merchantId>
< merchantRefNum>'。rand(1,15).rand()。< / merchantRefNum>
< paymentAmount>'。$ tb。'< / paymentAmount>
< paymentCurrency> SAR< / paymentCurrency>
< dynamicMerchantLandingURL>< / dynamicMerchantLandingURL>
< dynamicMerchantFailureURL>< / dynamicMerchantFailureURL>
< / req:initiatePaymentDetailsReq>
< / soapenv:Body>
< / soapenv:Envelope>';
try {
$ url =https://b2b.rb.com/soap?service=RB_OLP_INITIATE_PAYMENT;
$ certFile = dirname(__ FILE __)。/ key1.pem;
$ certPass =*****;
$ ch = curl_init();

curl_setopt($ ch,CURLOPT_URL,$ url);
curl_setopt($ ch,CURLOPT_VERBOSE,true);
curl_setopt($ ch,CURLOPT_POST,1);
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ ch,CURLOPT_SSL_VERIFYHOST,false);

curl_setopt($ ch,CURLOPT_SSLCERT,$ certFile);
curl_setopt($ ch,CURLOPT_SSLCERTPASSWD,$ certPass);
$ headers = array()
array_push($ headers,Content-Type:text / xml; charset = utf-8);
array_push($ headers,SOAPAction:sii:RB_OLP_INITIATE_PAYMENT);
array_push($ headers,Host:b22.rb.com);

if($ xml!= null){
curl_setopt($ ch,CURLOPT_POSTFIELDS,$ xml);
array_push($ headers,Content-Length:。strlen($ xml));
}

curl_setopt($ ch,CURLOPT_POST,TRUE);
curl_setopt($ ch,CURLOPT_HTTPHEADER,$ headers);
$ response = curl_exec($ ch);
$ code = curl_getinfo($ ch,CURLINFO_HTTP_CODE);
curl_close($ ch);
print_r($ response);
} catch(Exception $ e){
echo $ e-> getMessage();
}


?>


Please need your help !. I am trying to create a PHP soap client with curl. when I run my PHP code. I getting the blank result . it's a https connection . I generate my .pem file with OpenSSL by this example

PHP CODE

    $xml = '<?xml version="1.0" encoding="utf-8"?>'.
        '<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://olp.sadad.com/sadadpaymentmanagement/service/olppaymentmanager/req">'.
           '<x:Header/>'.
            '<x:Body>'.
        '<req:initiatePaymentDetailsReq>'.
           '<req:olpIdAlias>*****</req:olpIdAlias>'.
             '  <req:merchantId>*****</req:merchantId>'.
        '<req:merchantRefNum>999454564</req:merchantRefNum>'.
            '<req:paymentAmount>200</req:paymentAmount>'.
            '<req:paymentCurrency>SAR</req:paymentCurrency>'.
            '<req:dynamicMerchantLandingURL></req:dynamicMerchantLandingURL>'.
            ' <req:dynamicMerchantFailureURL></req:dynamicMerchantFailureURL>'.
              '</req:initiatePaymentDetailsReq>'.
              '</x:Body>'.
              '</x:Envelope>';
    try{
    $url = "https://b2brbtest.riyadbank.com/soap?service=RB_OLP_INITIATE_PAYMENT";
     $certFile =  dirname(__FILE__)."/key1.pem";
      $certPass = "*******";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_VERBOSE, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSLCERT, $certFile);
    curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $certPass);
    $headers = array();
    array_push($headers, "Content-Type: text/xml; charset=utf-8");
    array_push($headers, "SOAPAction: sii:RB_OLP_INITIATE_PAYMENT");

    if($xml != null) {
        curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml");
        array_push($headers, "Content-Length: " . strlen($xml));
    }

    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    $response = curl_exec($ch);
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    var_dump($response);

    }  catch (Exception $e){
    echo $e->getMessage();


    }

    ?>

OUTPUT

string(228) " "

解决方案

Finally I solved this by changing $xml value

$xml = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://olp.bank.com/sappay/service/olppaymentmanager/req">
   <soapenv:Header/>
   <soapenv:Body>
      <req:initiatePaymentDetailsReq>
         <olpIdAlias>****</olpIdAlias>
         <merchantId>***</merchantId>
         <merchantRefNum>'.rand(1, 15).rand().'</merchantRefNum>
         <paymentAmount>'.$tb.'</paymentAmount>
         <paymentCurrency>SAR</paymentCurrency>
         <dynamicMerchantLandingURL></dynamicMerchantLandingURL>
         <dynamicMerchantFailureURL></dynamicMerchantFailureURL>
      </req:initiatePaymentDetailsReq>
   </soapenv:Body>
</soapenv:Envelope>';

here is full code of how to connect SOAP webservice with ssl

<?php
$tb='200';

$xml = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://olp.bank.com/sappay/service/olppaymentmanager/req">
   <soapenv:Header/>
   <soapenv:Body>
      <req:initiatePaymentDetailsReq>
         <olpIdAlias>*****</olpIdAlias>
         <merchantId>********</merchantId>
         <merchantRefNum>'.rand(1, 15).rand().'</merchantRefNum>
         <paymentAmount>'.$tb.'</paymentAmount>
         <paymentCurrency>SAR</paymentCurrency>
         <dynamicMerchantLandingURL></dynamicMerchantLandingURL>
         <dynamicMerchantFailureURL></dynamicMerchantFailureURL>
      </req:initiatePaymentDetailsReq>
   </soapenv:Body>
</soapenv:Envelope>';
try{
$url = "https://b2b.rb.com/soap?service=RB_OLP_INITIATE_PAYMENT";
 $certFile =  dirname(__FILE__)."/key1.pem";
  $certPass = "*****";
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

curl_setopt($ch, CURLOPT_SSLCERT, $certFile);
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $certPass);
$headers = array();
array_push($headers, "Content-Type: text/xml; charset=utf-8");
array_push($headers, "SOAPAction: sii:RB_OLP_INITIATE_PAYMENT");
array_push($headers, "Host:b22.rb.com");

if($xml != null) {
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
    array_push($headers, "Content-Length: " . strlen($xml));
}

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
     print_r($response);
}  catch (Exception $e){
echo $e->getMessage();
   }


?>

这篇关于PHP:Curl https xml结果返回空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆