質問編集履歴

1

全文を記載しました。

2017/11/10 03:53

投稿

teityann1225
teityann1225

スコア158

test CHANGED
File without changes
test CHANGED
@@ -51,3 +51,177 @@
51
51
 
52
52
 
53
53
  ```
54
+
55
+ 全部のコードを記載します。
56
+
57
+ ```php
58
+
59
+ <?php
60
+
61
+ /*
62
+
63
+ * 定数読み込み
64
+
65
+ */
66
+
67
+ require_once('yahoo_constant.php');
68
+
69
+
70
+
71
+ /*
72
+
73
+ * アクセストークンの取得
74
+
75
+ * ここでは HTTP_Request2 を使用してみます
76
+
77
+ */
78
+
79
+ require_once('Net/URL2.php');
80
+
81
+ require_once('HTTP/Request2.php');
82
+
83
+
84
+
85
+ $code = $_REQUEST['code'];
86
+
87
+
88
+
89
+ $http_options = [
90
+
91
+ 'protocol_version' => '1.1',
92
+
93
+ 'connect_timeout' => '300',
94
+
95
+ 'timeout' => '300',
96
+
97
+ 'follow_redirects' => true,
98
+
99
+ 'max_redirects' => 3,
100
+
101
+ 'ssl_verify_peer' => false
102
+
103
+ ];
104
+
105
+ $req = new \HTTP_Request2(\TOKEN_ENDPOINT, \HTTP_Request2::METHOD_POST, $http_options);
106
+
107
+
108
+
109
+
110
+
111
+ $req->setHeader('Connection', 'keep-alive');
112
+
113
+ $req->setHeader('Content-Type', 'application/x-www-form-urlencoded');
114
+
115
+ $req->setHeader('Accept-Charset', 'UTF-8');
116
+
117
+
118
+
119
+
120
+
121
+ $request_parameter = [
122
+
123
+ 'code' => $_REQUEST['code'],
124
+
125
+ 'client_id' => \CLIENT_ID,
126
+
127
+ 'client_secret' => \CLIENT_SECRET,
128
+
129
+ 'redirect_uri' => \REDIRECT_URL,
130
+
131
+ 'grant_type' => 'authorization_code'
132
+
133
+ ];
134
+
135
+ foreach ($request_parameter as $key => $value) {
136
+
137
+ $req->addPostParameter($key, $value);}
138
+
139
+
140
+
141
+
142
+
143
+ try{
144
+
145
+ $res = $req->send();
146
+
147
+ if ($res->getStatus() != 200) {
148
+
149
+ error_log('doHttpRequest(): Request status is not 200: '.$res->getStatus());
150
+
151
+ return false;
152
+
153
+ }
154
+
155
+
156
+
157
+
158
+
159
+ // get response
160
+
161
+ $responses = json_decode($res->getBody());
162
+
163
+ $test=$res->getBody();
164
+
165
+ echo $test;
166
+
167
+ echo $responses->access_token;
168
+
169
+
170
+
171
+
172
+
173
+ list($client_id_signature, $jwt_encoded) = explode(".", $responses->id_token);
174
+
175
+ $jwt = json_decode(base64_decode($jwt_encoded));
176
+
177
+ $sub = $jwt->sub;
178
+
179
+ $email = $jwt->email;
180
+
181
+ echo '<br><br><br>';
182
+
183
+ $Atoken= $res->access_token;
184
+
185
+
186
+
187
+
188
+
189
+ } catch (\HTTP_Request2_Exception $e) {
190
+
191
+ error_log('doHttpRequest(): HTTP_Request2_Exception: '.$this->getMessageByHttpRequest2ExceptionCode($e->getCode()));
192
+
193
+ exit;
194
+
195
+ }
196
+
197
+
198
+
199
+ $ch = curl_init("https://userinfo.yahooapis.jp/yconnect/v1/attribute?schema=openid");
200
+
201
+ curl_setopt($ch, CURLOPT_GET, true);
202
+
203
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
204
+
205
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
206
+
207
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
208
+
209
+ 'Content-Type: application/json; charser=UTF-8',
210
+
211
+ 'Authorization: Bearer ' . $Atoken
212
+
213
+ ));
214
+
215
+ $result = curl_exec($ch);
216
+
217
+ echo $result;
218
+
219
+ curl_close($ch);
220
+
221
+
222
+
223
+
224
+
225
+ ?>
226
+
227
+ ```