3v4l.org

run code in 300+ PHP versions simultaneously
<?php class header { private $secretKey = '123'; private $storeId = 10; public function __construct($content, $url) { $this->setContentMd5($content); $this->setHttpVerb($url); } private function setContentMd5($content) { $this->contentMd5 = md5($content); } private function setHttpVerb($url) { if (parse_url($url, PHP_URL_QUERY)) { $this->httpVerb = parse_url($url, PHP_URL_PATH).'?'.parse_url($url, PHP_URL_QUERY); } else { $this->httpVerb = parse_url($url, PHP_URL_PATH); } } private function generateAuthorization() { return hash_hmac( 'sha256', $this->httpVerb . $this->contentMd5, $this->secretKey ); } public function generateHeader() { $headers = array( 'Accept' => 'application/vnd.boacompra.com.v1+json; charset=UTF-8', 'Content-Type' => 'application/json', 'Content-MD5' => $this->contentMd5, 'Authorization' => $this->storeId . ':' . $this->generateAuthorization() ); return $headers; } } echo 'POST EXAMPLE <br /> <pre>'; $content = '{"payment-method":{"reference":"ID-CND4","direct-token":"eyJkbmEiOiJjMWRkMzliYTY4YjY0MjlkOTRmNTQzM2YwMTFiNTRlZiIsImlwIjoiMTcyLjIxLjExMi4xNjEiLCJkZiI6IjJmOTExZjdkOTgyZDQzMDY4YTNmYjc2MWRlZWQzZjI1In0=","notify-url":"https://virtual-store.com/notifications/","test-mode":0,"payment-group":"credit_card","country":"BR","language":"en-US"},"payer":{"name":"Payer Pagador","email":"payer@uolinc.com","phone-area-code":"11","phone-number":"988881234","document":{"type":"CPF","number":"00000000191"},"birth-date":"1982-12-20"}}'; $headerPost = new header($content, 'https://api.boacompra.com/payment-methods'); print_r($headerPost->generateHeader());
Output for 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
POST EXAMPLE <br /> <pre> Deprecated: Creation of dynamic property header::$contentMd5 is deprecated in /in/Qebl5 on line 15 Deprecated: Creation of dynamic property header::$httpVerb is deprecated in /in/Qebl5 on line 23 Array ( [Accept] => application/vnd.boacompra.com.v1+json; charset=UTF-8 [Content-Type] => application/json [Content-MD5] => a3253fd007c32a6ab1d28542cbf34b44 [Authorization] => 10:93d795ccb9729de3b8b0db1fec3a50be13fdc412b7550368ab94fdec4709ea7f )
Output for 7.0.0 - 7.0.31, 7.1.0 - 7.1.21, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27
POST EXAMPLE <br /> <pre>Array ( [Accept] => application/vnd.boacompra.com.v1+json; charset=UTF-8 [Content-Type] => application/json [Content-MD5] => a3253fd007c32a6ab1d28542cbf34b44 [Authorization] => 10:93d795ccb9729de3b8b0db1fec3a50be13fdc412b7550368ab94fdec4709ea7f )

preferences:
152.07 ms | 403 KiB | 200 Q