Help > Forum > 網站集成 > 接收 webhook 事件的示例代码
接收 webhook 事件的示例代码
request_body = request.body.read request_data = JSON.parse(request_body) if request_data['type'] === 'post.created' # Do something with the webhook request data puts request_data['id'] end # Return a 200 HTTP status code status 200
request_body = request.get_data() request_data = json.loads(request_body) if request_data['type'] == 'post.created': # Do something with the webhook request data print(request_data['id']) # Return a 200 HTTP status code return '', 200
<?php $requestBody = file_get_contents('php://input'); $requestData = json_decode($requestBody, true); if ($requestData['type'] === 'post.created') { // Do something with the webhook request data echo $requestData['id']; } http_response_code(200); ?>
String requestBody = request.get_data(); JSONObject requestData = new JSONObject(requestBody); if (requestData.getString("type").equals("post.created")) { // Do something with the webhook request data System.out.println(requestData.getString("id")); } // Return a 200 HTTP status code return Response.ok().build();
const requestBody = request.body; const requestData = JSON.parse(requestBody); if (requestData.type === 'post.created') { // Do something with the webhook request data console.log(requestData.id); } // Return a 200 HTTP status code res.sendStatus(200);
// Read the request body requestBody, err := ioutil.ReadAll(r.Body) if err != nil { panic(err) } // Parse the request body as JSON var requestData map[string]interface{} if err := json.Unmarshal(requestBody, &requestData); err != nil { panic(err) } if requestData["type"] == "post.created" { // Do something with the webhook request data fmt.Println(requestData["id"]) } // Return a 200 HTTP status code w.WriteHeader(http.StatusOK)
string requestBody = Request.InputStream.ReadToEnd(); dynamic requestData = JObject.Parse(requestBody); if (requestData.type == "post.created") { // Do something with the webhook request data Console.WriteLine(requestData.id); } // Return a 200 HTTP status code return new HttpStatusCodeResult(200);
If you still need help, please contact us.