質問編集履歴

3

アクセストークンの削除

2018/03/15 01:53

投稿

yayoi_answer
yayoi_answer

スコア16

test CHANGED
File without changes
test CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
 
18
18
 
19
- $accessToken = 'fS+uYf5mVIwJZ+gVoNJnW4qhovFlS+1HhifZtQyUw5Y5jngbLe/LXBcCCWa7pEET1v1sX2sjJbAYTY19bnfTCVmFMGWFlMFsnTIz3K28C3nAFc26vaL5W3D1sRMkbCx01UD0T8bkv7A9IJZ3Yn57ywdB04t89/1O/w1cDnyilFU=';
19
+ $accessToken = 'アクセストークンの記述';
20
20
 
21
21
 
22
22
 

2

タイトルの変更

2018/03/15 01:53

投稿

yayoi_answer
yayoi_answer

スコア16

test CHANGED
@@ -1 +1 @@
1
- phpからpythonへ文言をPOST
1
+ phpからpythonへ文言をPOSTしたい
test CHANGED
File without changes

1

コードの追加

2018/03/14 10:27

投稿

yayoi_answer
yayoi_answer

スコア16

test CHANGED
File without changes
test CHANGED
@@ -7,3 +7,261 @@
7
7
  なにか実装のヒントをいただけたらと思います。
8
8
 
9
9
  よろしくお願いいたします。
10
+
11
+
12
+
13
+ ```php
14
+
15
+ <?php
16
+
17
+
18
+
19
+ $accessToken = 'fS+uYf5mVIwJZ+gVoNJnW4qhovFlS+1HhifZtQyUw5Y5jngbLe/LXBcCCWa7pEET1v1sX2sjJbAYTY19bnfTCVmFMGWFlMFsnTIz3K28C3nAFc26vaL5W3D1sRMkbCx01UD0T8bkv7A9IJZ3Yn57ywdB04t89/1O/w1cDnyilFU=';
20
+
21
+
22
+
23
+ $jsonString = file_get_contents('php://input');
24
+
25
+ error_log($jsonString);
26
+
27
+ $jsonObj = json_decode($jsonString);
28
+
29
+
30
+
31
+ $message = $jsonObj->{"events"}[0]->{"message"};
32
+
33
+ $replyToken = $jsonObj->{"events"}[0]->{"replyToken"};
34
+
35
+
36
+
37
+ 送られてきたメッセージの中身からレスポンスのタイプを選択
38
+
39
+ if ($message->{"text"} == '確認') {
40
+
41
+ // 確認ダイアログタイプ
42
+
43
+ $messageData = [
44
+
45
+ 'type' => 'template',
46
+
47
+ 'altText' => '確認ダイアログ',
48
+
49
+ 'template' => [
50
+
51
+ 'type' => 'confirm',
52
+
53
+ 'text' => '元気ですかー?',
54
+
55
+ 'actions' => [
56
+
57
+ [
58
+
59
+ 'type' => 'message',
60
+
61
+ 'label' => '元気です',
62
+
63
+ 'text' => '元気です'
64
+
65
+ ],
66
+
67
+ [
68
+
69
+ 'type' => 'message',
70
+
71
+ 'label' => 'まあまあです',
72
+
73
+ 'text' => 'まあまあです'
74
+
75
+ ],
76
+
77
+ ]
78
+
79
+ ]
80
+
81
+ ];
82
+
83
+ } elseif ($message->{"text"} == 'ボタン') {
84
+
85
+ // ボタンタイプ
86
+
87
+ $messageData = [
88
+
89
+ 'type' => 'template',
90
+
91
+ 'altText' => 'ボタン',
92
+
93
+ 'template' => [
94
+
95
+ 'type' => 'buttons',
96
+
97
+ 'title' => 'タイトルです',
98
+
99
+ 'text' => '選択してね',
100
+
101
+ 'actions' => [
102
+
103
+ [
104
+
105
+ 'type' => 'postback',
106
+
107
+ 'label' => 'webhookにpost送信',
108
+
109
+ 'data' => 'value'
110
+
111
+ ],
112
+
113
+ [
114
+
115
+ 'type' => 'uri',
116
+
117
+ 'label' => 'googleへ移動',
118
+
119
+ 'uri' => 'https://google.com'
120
+
121
+ ]
122
+
123
+ ]
124
+
125
+ ]
126
+
127
+ ];
128
+
129
+ } elseif ($message->{"text"} == 'カルーセル') {
130
+
131
+ // カルーセルタイプ
132
+
133
+ $messageData = [
134
+
135
+ 'type' => 'template',
136
+
137
+ 'altText' => 'カルーセル',
138
+
139
+ 'template' => [
140
+
141
+ 'type' => 'carousel',
142
+
143
+ 'columns' => [
144
+
145
+ [
146
+
147
+ 'title' => 'カルーセル1',
148
+
149
+ 'text' => 'カルーセル1です',
150
+
151
+ 'actions' => [
152
+
153
+ [
154
+
155
+ 'type' => 'postback',
156
+
157
+ 'label' => 'webhookにpost送信',
158
+
159
+ 'data' => 'value'
160
+
161
+ ],
162
+
163
+ [
164
+
165
+ 'type' => 'uri',
166
+
167
+ 'label' => '美容の口コミ広場を見る',
168
+
169
+ 'uri' => 'http://clinic.e-kuchikomi.info/'
170
+
171
+ ]
172
+
173
+ ]
174
+
175
+ ],
176
+
177
+ [
178
+
179
+ 'title' => 'カルーセル2',
180
+
181
+ 'text' => 'カルーセル2です',
182
+
183
+ 'actions' => [
184
+
185
+ [
186
+
187
+ 'type' => 'postback',
188
+
189
+ 'label' => 'webhookにpost送信',
190
+
191
+ 'data' => 'value'
192
+
193
+ ],
194
+
195
+ [
196
+
197
+ 'type' => 'uri',
198
+
199
+ 'label' => '女美会を見る',
200
+
201
+ 'uri' => 'https://jobikai.com/'
202
+
203
+ ]
204
+
205
+ ]
206
+
207
+ ],
208
+
209
+ ]
210
+
211
+ ]
212
+
213
+ ];
214
+
215
+ } else {
216
+
217
+ // それ以外は送られてきたテキストをオウム返し
218
+
219
+ $messageData = [
220
+
221
+ 'type' => 'text',
222
+
223
+ 'text' => $message->{"text"}
224
+
225
+ ];
226
+
227
+ }
228
+
229
+
230
+
231
+ $response = [
232
+
233
+ 'replyToken' => $replyToken,
234
+
235
+ 'messages' => [$messageData]
236
+
237
+ ];
238
+
239
+ error_log(json_encode($response));
240
+
241
+
242
+
243
+ $ch = curl_init('https://api.line.me/v2/bot/message/reply');
244
+
245
+ curl_setopt($ch, CURLOPT_POST, true);
246
+
247
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
248
+
249
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
250
+
251
+ curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($response));
252
+
253
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
254
+
255
+ 'Content-Type: application/json; charser=UTF-8',
256
+
257
+ 'Authorization: Bearer ' . $accessToken
258
+
259
+ ));
260
+
261
+ $result = curl_exec($ch);
262
+
263
+ error_log($result);
264
+
265
+ curl_close($ch);
266
+
267
+ ```