-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat_api.php
44 lines (35 loc) · 1.02 KB
/
chat_api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
if(isset($_POST["user"]) && isset($_POST["q"]) && isset($_GET["mode"])){
if($_GET["mode"] == "chat"){
$url = "http://localhost:5000/chat";
}elseif($_GET["mode"] == "write"){
$url = "http://localhost:5000/mode/write";
}elseif($_GET["mode"] == "talk"){
$url = "http://localhost:5000/mode/talk";
}
$data = array(
'user' => $_POST["user"],
'q' => $_POST["q"]
);
if(isset($_POST["w"])){
$data = array(
'user' => $_POST["user"],
'q' => $_POST["q"],
'w' => $_POST["w"]
);
}
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if ($response === false) {
// error
echo("500 Error");
} else {
// レスポンスを処理
echo($response);
}
curl_close($ch);
}
?>