Last active
October 12, 2018 09:20
-
-
Save Odalrick/9eb338edb94e52369702549b37d30ba5 to your computer and use it in GitHub Desktop.
test WM3 swecandy api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function mergeHeadersG($headers) | |
| { | |
| foreach ($headers as $key => $value) | |
| yield $key . ': ' . $value; | |
| } | |
| function mergeHeaders($headers) | |
| { | |
| return implode("\r\n", iterator_to_array(mergeHeadersG($headers))); | |
| } | |
| function main() | |
| { | |
| $root = 'http://klippkungen.max-order.wm3-staging.se'; | |
| $token = '__kmz1MMzjV45z4gYTKQ_A'; | |
| $startHeaders = [ | |
| 'Accept' => 'application/json', | |
| 'Content-Type' => 'application/json', | |
| 'Authorization' => 'WM3 ' . base64_encode($token), | |
| ]; | |
| $p = function ($path) use ($root) { | |
| return $root . $path; | |
| }; | |
| // use key 'http' even if you send the request to https://... | |
| $options = array( | |
| 'http' => array( | |
| 'header' => mergeHeaders($startHeaders), | |
| 'method' => 'GET', | |
| ) | |
| ); | |
| $context = stream_context_create($options); | |
| $auth = function ($url) use ($context) { | |
| $result = file_get_contents($url, false, $context); | |
| if ($result === FALSE) { /* Handle error */ | |
| throw new RuntimeException('Something failed'); | |
| } | |
| }; | |
| $result = $auth($p('/api/v1/shop/admin/countries')); | |
| var_export($result); | |
| } | |
| main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment