properties; // 提取email屬性值 $email = $contact_properties->email->value; // 提取名字屬性值 $first_name = $contact_properties->名字->值; // 提取姓氏屬性值 $last_name = $contact_properties->姓氏->值; // 對聯(lián)絡(luò)人資料執(zhí)行某些操作,例如將其新增至資料庫或傳送電子郵件通知 // 例如: $contact_data = 數(shù)組( '電子郵件' => $電子郵件, '名字' => $名字, '姓氏' => $姓氏 ); // 將聯(lián)絡(luò)人資料新增至資料庫或傳送電子郵件通知等 // 向 HubSpot 發(fā)送 HTTP 回應(yīng),表示 Webhook 已成功接收並處理 http_response_code(200); } ?></pre> <p>和 webhook-api-key.php:</p>; $api_key_secret_value ); // 將 HTTP POST 請求傳送到 webhook 端點(diǎn) URL $ch =curl_init($endpoint_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); $回應(yīng)=curl_exec($ch); // 檢查是否有錯(cuò)誤 如果(curl_errno($ ch)){ $error_message=curl_error($ch); echo '錯(cuò)誤:'.$error_message; } // 取得HTTP回應(yīng)狀態(tài)碼 $http_status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); // 關(guān)閉HTTP POST請求 捲曲_關(guān)閉($ch); // 處理 webhook 回應(yīng) 如果($http_status_code === 200){ echo 'Webhook 已成功驗(yàn)證。'; } 別的 { echo 'Webhook 驗(yàn)證失敗,HTTP 狀態(tài)碼:' 。 $http_status_code; } ?></pre> <p>在 Hubspot 設(shè)定中,網(wǎng)址為「https:/.../hubspot/webhook.php」。</p> <p>這樣可以嗎?我這麼問是因?yàn)楫?dāng)我嘗試測試它時(shí)它殺死了我的伺服器,並且我在互聯(lián)網(wǎng)上找不到使用這種身份驗(yàn)證的範(fàn)例。 </p> <p>謝謝! </p>
所以其實(shí)很簡單。網(wǎng)路上沒有範(fàn)例,文件也很差,它更多地解釋了 Hubspot 簽名而不是 API 金鑰。 我最終明白了它是如何工作的,這是工作代碼:
$expectedSecretName = 'word'; // Replace with your expected secret name $expectedSecretValue = 'another_word'; // Replace with your expected secret value $requestBody = file_get_contents('php://input'); $data = json_decode($requestBody); if($_SERVER['HTTP_WORD'] == $expectedSecretValue){ //do something with values $email = $data->email; $firstname= $data->firstname; $lastname= $data->lastname; } else{ //not from Hubspot }