Skip to content

Instantly share code, notes, and snippets.

@jagroop jagroop/soap.php
Created Jan 28, 2019

Embed
What would you like to do?
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Pixibox_soap {
const REQUEST_URL = 'http://example.com/DjamWebserv.asmx';
const COUPON_LINK = 'http://example.com/PixiboxMasterPrint.aspx';
const SUCCESS_RESPONSE_VALUES = [1, 2, 3];
public function generateXml($action, $paramsArray)
{
$params = '';
foreach ($paramsArray as $key => $value) {
$params .= "<".$key.">".$value."</".$key."> \n";
}
$xml = '<?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>
<'.$action.' xmlns="http://www.pixiboxwserv.fr/">
'.$params.'
</'.$action.'>
</soap:Body>
</soap:Envelope>';
return $xml;
}
public function request($action, array $params)
{
$body = $this->generateXml($action, $params);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => self::REQUEST_URL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $body,
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: text/xml"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
$xs = new SimpleXMLIterator($response);
$body = @$xs->xpath("//soap:Body");
$body = object_to_array($body);
switch ($action) {
case 'CreateUpdateUser':
$value = @$body[0]['CreateUpdateUserResponse']['CreateUpdateUserResult'];
_log($value);
return in_array($value, self::SUCCESS_RESPONSE_VALUES);
break;
default:
return false;
break;
}
}
public function getLink($email)
{
$queryStrings = http_build_query([
'Email' => $email,
'Partnerkey' => '123123'
]);
return self::COUPON_LINK .'?' . $queryStrings;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.