<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Webhook extends CI_Controller {
	public function __construct()
	{
		parent::__construct();
		//$this->load->model('test');
	}
	public function index()
	{ 
		$json = array();
		//print_r(json_decode(stripslashes($json),true));
		//print_r($_POST);
		//ksort($_POST); 
		$key='Bud7ZELORG3KG0_G54scAQ';
		$url = 'https://castleevents.com/webhook';
		echo $signature = $this->generateSignature($key, $url, $json); 
		//return $request->getHeader('X-Mandrill-Signature') === $signature;
		die;
	}
	public function generateSignature($webhook_key, $url, $params) {
	    $signed_data = $url;
	    ksort($params);
	    foreach ($params as $key => $value) {
	        $signed_data .= $key;
	        $signed_data .= $value;
	    }

	    return base64_encode(hash_hmac('sha1', $signed_data, $webhook_key, true));
	    die;
	}
}
	

