Asked  7 Months ago    Answers:  5   Viewed   31 times

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

 Answers

16

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


?>
Wednesday, March 31, 2021
 
QuantumMechanic
answered 7 Months ago
47

A simple request for the web service's available functions solved the problem.

$functions = $client->__getFunctions ();
var_dump ($functions);

EchoTestRequest was not a valid function call. The proper function call was EchoTest, which is illustrated by the functions variable dump.

array(1) { [0]=> string(54) "EchoTestResponse EchoTest(EchoTestRequest $parameters)" } 
Wednesday, March 31, 2021
 
cyber_truite
answered 7 Months ago
26

You should be using rawurlencode instead of htmlentities, and only on the XML part of the 'payload'. Also, you're defining your constant to the literal text "$xml" by using single quotes around your variable. So replacing those two lines with these should do:

$xml = 'xml_text='.rawurlencode('<?xml … </idibu>'); # <-- insert entire XML there

define('XML_PAYLOAD', $xml);
Wednesday, March 31, 2021
 
zIs
answered 7 Months ago
zIs
70

SOLVED

in soap_client.php, in catch, i added "echo $client->__getLastResponse();" which gave me the following output:

Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in Unknown on line 0

Warning: Cannot modify header information - headers already sent in Unknown on line 0
Dale Cooper, Harry Truman, Shelly Johnson, Bobby Briggs, Donna Hayward, Audrey Horne, James Hurley, Lucy Moran, Tommy Hill, Andy Brennan, John Smith

that last line is the string i passed to the client.

so what i tried was to uncomment "always_populate_raw_post_data = -1" in php.ini as the error suggested & restarted my Apache2.4 web-server and now it works, getting my string with no errors:

Dale Cooper, Harry Truman, Shelly Johnson, Bobby Briggs, Donna Hayward, Audrey Horne, James Hurley, Lucy Moran, Tommy Hill, Andy Brennan, John Smith

hope i helped someone with this, as i saw alot of unanswered questions about this error.

Saturday, May 29, 2021
 
Andres
answered 5 Months ago
84

Quick fix, add this in your options:

curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false)

Now you have no idea what host you're actually connecting to, because cURL will not verify the certificate in any way. Hope you enjoy man-in-the-middle attacks!

Or just add it to your current function:

/**
 * Get a web file (HTML, XHTML, XML, image, etc.) from a URL.  Return an
 * array containing the HTTP server response header fields and content.
 */
function get_web_page( $url )
{
    $options = array(
        CURLOPT_RETURNTRANSFER => true,     // return web page
        CURLOPT_HEADER         => false,    // don't return headers
        CURLOPT_FOLLOWLOCATION => true,     // follow redirects
        CURLOPT_ENCODING       => "",       // handle all encodings
        CURLOPT_USERAGENT      => "spider", // who am i
        CURLOPT_AUTOREFERER    => true,     // set referer on redirect
        CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
        CURLOPT_TIMEOUT        => 120,      // timeout on response
        CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
        CURLOPT_SSL_VERIFYPEER => false     // Disabled SSL Cert checks
    );

    $ch      = curl_init( $url );
    curl_setopt_array( $ch, $options );
    $content = curl_exec( $ch );
    $err     = curl_errno( $ch );
    $errmsg  = curl_error( $ch );
    $header  = curl_getinfo( $ch );
    curl_close( $ch );

    $header['errno']   = $err;
    $header['errmsg']  = $errmsg;
    $header['content'] = $content;
    return $header;
}
Tuesday, June 1, 2021
 
the_e
answered 5 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :