Skip to content

Instantly share code, notes, and snippets.

@hypermkt
Created July 16, 2017 05:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hypermkt/84e624a39aa28cecff8041875e3dfe0d to your computer and use it in GitHub Desktop.
Save hypermkt/84e624a39aa28cecff8041875e3dfe0d to your computer and use it in GitHub Desktop.
<?php
$base_url = 'xxx';
$data = [
"text" => "Would you like to play a game?",
"attachments" => [
[
"text" => "Choose a game to play",
"fallback" => "You are unable to choose a game",
"callback_id" => "wopr_game",
"color" => "#3AA3E3",
"attachment_type" => "default",
"actions" => [
[
"name" => "game",
"text" => "Chess",
"type" => "button",
"value" => "chess"
],
[
"name" => "game",
"text" => "Falken's Maze",
"type" => "button",
"value" => "maze"
],
[
"name" => "game",
"text" => "Thermonuclear War",
"style" => "danger",
"type" => "button",
"value" => "war",
"confirm" => [
"title" => "Are you sure?",
"text" => "Wouldn't you prefer a good game of chess?",
"ok_text" => "Yes",
"dismiss_text" => "No"
]
]
]
]
]
];
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $base_url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); // post
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); // jsonデータを送信
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
$response = curl_exec($curl);
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
$body = substr($response, $header_size);
$result = json_decode($body, true);
curl_close($curl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment