/** * Create an HMAC signature and POST the payload to your webhook. * Uses the same secret your receiver validates (LPS_DID_SHARED_SECRET). * * @param array $payload Associative array to send as JSON. * @param string $endpoint Optional override (defaults to your hook). * @return array { ok: bool, status?: int, body?: string|array, error?: string } */ function lps_send_did_webhook(array $payload, $endpoint = '') { if (!defined('LPS_DID_SHARED_SECRET') || !LPS_DID_SHARED_SECRET) { return ['ok' => false, 'error' => 'Missing LPS_DID_SHARED_SECRET']; } $endpoint = $endpoint ?: home_url('/wp-json/lps-did/v1/hook'); $raw = wp_json_encode($payload, JSON_UNESCAPED_SLASHES); if ($raw === false) { return ['ok' => false, 'error' => 'JSON encode failed']; } // HMAC signature over the EXACT raw body $signature = 'sha256=' . hash_hmac('sha256', $raw, LPS_DID_SHARED_SECRET); $args = [ 'method' => 'POST', 'headers' => [ 'Content-Type' => 'application/json', 'X-DID-Signature' => $signature, // Do NOT also send X-DID-Secret when using signature ], 'body' => $raw, 'timeout' => 20, ]; $resp = wp_remote_post($endpoint, $args); if (is_wp_error($resp)) { return ['ok'=>false, 'error'=>$resp->get_error_message()]; } $status = wp_remote_retrieve_response_code($resp); $body = wp_remote_retrieve_body($resp); // Try to decode JSON response from your receiver $decoded = json_decode($body, true); return [ 'ok' => ($status >= 200 && $status < 300), 'status' => $status, 'body' => $decoded ?? $body, ]; } https://lpslama.com/post-sitemap.xml 2025-09-12T01:29:55+00:00 https://lpslama.com/page-sitemap.xml 2025-09-21T16:29:27+00:00 https://lpslama.com/e-landing-page-sitemap.xml 2024-06-28T02:23:19+00:00 https://lpslama.com/elementskit_content-sitemap.xml 2025-09-20T18:08:21+00:00 https://lpslama.com/elementskit_template-sitemap.xml 2025-09-18T23:13:54+00:00 https://lpslama.com/product-sitemap.xml 2025-09-21T18:05:16+00:00 https://lpslama.com/elementor-hf-sitemap.xml 2025-05-19T04:21:04+00:00 https://lpslama.com/category-sitemap.xml 2025-09-12T01:29:55+00:00 https://lpslama.com/post_tag-sitemap.xml 2025-09-07T20:38:12+00:00 https://lpslama.com/product_cat-sitemap.xml 2025-09-21T18:05:16+00:00