From aafae82fbbc5aa199beadea078f9cc40310c695a Mon Sep 17 00:00:00 2001 From: Guillaume Badi Date: Thu, 10 Sep 2015 18:17:31 +0200 Subject: [PATCH] json encode slashes for older php version --- src/Mailjet/php-mailjet-v3-simple.class.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Mailjet/php-mailjet-v3-simple.class.php b/src/Mailjet/php-mailjet-v3-simple.class.php index d93d9b2..7e53269 100644 --- a/src/Mailjet/php-mailjet-v3-simple.class.php +++ b/src/Mailjet/php-mailjet-v3-simple.class.php @@ -251,7 +251,7 @@ public function requestUrlBuilder($resource, $params = array(), $request, $id) if ($resource == "sendEmail") { $this->call_url = $this->apiUrl."/send/message"; } - else if ($resource == "send") { + else if ($resource == "send") { $this->call_url = $this->apiUrl."/send"; //json support for SendAPI } else if ($resource == "uploadCSVContactslistData") { @@ -278,7 +278,7 @@ public function requestUrlBuilder($resource, $params = array(), $request, $id) } else if (in_array($resource, self::$_templateResources)) { - $this->call_url = $this->makeUrlFromFilter('REST', 'template', $params['ID'], $resource); + $this->call_url = $this->makeUrlFromFilter('REST', 'template', $params['ID'], $resource); } else if (in_array($resource, self::$_contactResources)) { @@ -407,7 +407,14 @@ public function sendRequest($resource = false, $params = array(), $request = "GE unset($params['ID']); } - curl_setopt($curl_handle, CURLOPT_POSTFIELDS, json_encode($params, JSON_UNESCAPED_SLASHES)); + $j_e = null; + if (version_compare(phpversion(), '5.4.0', '<')) { + $j_e = str_replace('\\/', '/', json_encode($params)); + } else { + $j_e = json_encode($params, JSON_UNESCAPED_SLASHES); + } + + curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $j_e); curl_setopt($curl_handle, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json' ));