testtestsandboxi - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of testtestsandboxi.php
- <?php
- $b64url = function ($string) {
- return rtrim(strtr(base64_encode($string), '+/', '-_'), '=');
- };
- $prepare_payload = function ($path, $data, $method) {
- return [
- 'PATH' => $path,
- strtoupper($method) => array_map('strval', $data)
- ];
- };
- $apiSecret = 'hVwtyN33yoNW-oWV349QQx-kms.FqLCs';
- $path = '/billingapi/kinghills/sgate/callback';
- $data = [
- "amount" => "100.0000",
- "currency" => "GBP",
- "custom_data" => "",
- "customer_id" => "",
- "fee_from_merchant" => "2.5000",
- "masked_pan" => "",
- "merchant_id" => "129",
- "order" => "116803780218342408",
- "product_id" => "306",
- "requested_amount" => "100.0000",
- "status" => "done",
- "webhook_id" => "3443384",
- "webhook_type" => "withdrawal",
- "withdrawal_request_id" => "145889"
- ];
- $method = 'POST'; // Измените на 'GET', если нужно
- $payload = $prepare_payload($path, $data, $method);
- ksort($payload[$method]);
- $head = ['alg' => 'HS256'];
- $headJson = json_encode($head, JSON_UNESCAPED_SLASHES);
- $payloadJson = json_encode($payload, JSON_UNESCAPED_SLASHES);
- $trueSign = $b64url(hash_hmac('sha256', $b64url($headJson) . '.' . $b64url($payloadJson), $apiSecret, true));
- echo $trueSign;
- ?>