3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * TME API - code snippet. * * More info at: https://developers.tme.eu */ ini_set('display_errors', 1); error_reporting(E_ALL); $token = 'b050bd709a43eecc443820c022b6774ca703ddb216b6f6765f';//'<put_your_token_here>'; $app_secret = '5656847466f0e5d08577';//<put_your_app_secret_here>'; $params = array( 'SymbolList' => array('1N4007'), 'Country' => 'PL', 'Currency' => 'PLN', 'Language' => 'PL', ); $response = api_call('Products/GetPrices', $params, $token, $app_secret, true); $result = json_decode($response, true); var_dump(PHP_VERSION); echo '<pre>'; print_r($result); echo '</pre>'; //--------------------------------------------------------- function api_call($action, $params, $token, $app_secret, $show_header=false) { $api_url = 'https://api.tme.eu/' . $action . '.json'; // calculate HMAC-SHA1 signature $params['Token'] = $token; ksort($params); // In PHP 5.4 http_build_query() offers enc_type parameter (PHP_QUERY_RFC3986) which replaces bellow snippet. $encoded_params = str_replace( array('+', '%7E'), array('%20', '~'), http_build_query($params) ); $signature_base = 'POST' . '&' . rawurlencode($api_url) . '&' . rawurlencode($encoded_params); $api_signature = base64_encode(hash_hmac('sha1', $signature_base, $app_secret, true)); $params['ApiSignature'] = $api_signature; $opts = array('http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query($params) ) ); return file_get_contents($api_url, false, stream_context_create($opts)); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3kumK
function name:  (null)
number of ops:  32
compiled vars:  !0 = $token, !1 = $app_secret, !2 = $params, !3 = $response, !4 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   INIT_FCALL                                               'ini_set'
          1        SEND_VAL                                                 'display_errors'
          2        SEND_VAL                                                 1
          3        DO_ICALL                                                 
    9     4        INIT_FCALL                                               'error_reporting'
          5        SEND_VAL                                                 32767
          6        DO_ICALL                                                 
   11     7        ASSIGN                                                   !0, 'b050bd709a43eecc443820c022b6774ca703ddb216b6f6765f'
   12     8        ASSIGN                                                   !1, '5656847466f0e5d08577'
   13     9        ASSIGN                                                   !2, <array>
   20    10        INIT_FCALL_BY_NAME                                       'api_call'
         11        SEND_VAL_EX                                              'Products%2FGetPrices'
         12        SEND_VAR_EX                                              !2
         13        SEND_VAR_EX                                              !0
         14        SEND_VAR_EX                                              !1
         15        SEND_VAL_EX                                              <true>
         16        DO_FCALL                                      0  $10     
         17        ASSIGN                                                   !3, $10
   21    18        INIT_FCALL                                               'json_decode'
         19        SEND_VAR                                                 !3
         20        SEND_VAL                                                 <true>
         21        DO_ICALL                                         $12     
         22        ASSIGN                                                   !4, $12
   23    23        INIT_FCALL                                               'var_dump'
         24        SEND_VAL                                                 '8.0.0'
         25        DO_ICALL                                                 
   25    26        ECHO                                                     '%3Cpre%3E'
   26    27        INIT_FCALL                                               'print_r'
         28        SEND_VAR                                                 !4
         29        DO_ICALL                                                 
   27    30        ECHO                                                     '%3C%2Fpre%3E'
   59    31      > RETURN                                                   1

Function api_call:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3kumK
function name:  api_call
number of ops:  62
compiled vars:  !0 = $action, !1 = $params, !2 = $token, !3 = $app_secret, !4 = $show_header, !5 = $api_url, !6 = $encoded_params, !7 = $signature_base, !8 = $api_signature, !9 = $opts
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
          4        RECV_INIT                                        !4      <false>
   33     5        CONCAT                                           ~10     'https%3A%2F%2Fapi.tme.eu%2F', !0
          6        CONCAT                                           ~11     ~10, '.json'
          7        ASSIGN                                                   !5, ~11
   36     8        ASSIGN_DIM                                               !1, 'Token'
          9        OP_DATA                                                  !2
   37    10        INIT_FCALL                                               'ksort'
         11        SEND_REF                                                 !1
         12        DO_ICALL                                                 
   40    13        INIT_FCALL                                               'str_replace'
   41    14        SEND_VAL                                                 <array>
   42    15        SEND_VAL                                                 <array>
   43    16        INIT_FCALL                                               'http_build_query'
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                         $15     
         19        SEND_VAR                                                 $15
         20        DO_ICALL                                         $16     
   40    21        ASSIGN                                                   !6, $16
   45    22        INIT_FCALL                                               'rawurlencode'
         23        SEND_VAR                                                 !5
         24        DO_ICALL                                         $18     
         25        CONCAT                                           ~19     'POST%26', $18
         26        CONCAT                                           ~20     ~19, '%26'
         27        INIT_FCALL                                               'rawurlencode'
         28        SEND_VAR                                                 !6
         29        DO_ICALL                                         $21     
         30        CONCAT                                           ~22     ~20, $21
         31        ASSIGN                                                   !7, ~22
   46    32        INIT_FCALL                                               'base64_encode'
         33        INIT_FCALL                                               'hash_hmac'
         34        SEND_VAL                                                 'sha1'
         35        SEND_VAR                                                 !7
         36        SEND_VAR                                                 !3
         37        SEND_VAL                                                 <true>
         38        DO_ICALL                                         $24     
         39        SEND_VAR                                                 $24
         40        DO_ICALL                                         $25     
         41        ASSIGN                                                   !8, $25
   48    42        ASSIGN_DIM                                               !1, 'ApiSignature'
         43        OP_DATA                                                  !8
   52    44        INIT_ARRAY                                       ~28     'POST', 'method'
   53    45        ADD_ARRAY_ELEMENT                                ~28     'Content-type%3A+application%2Fx-www-form-urlencoded', 'header'
   54    46        INIT_FCALL                                               'http_build_query'
         47        SEND_VAR                                                 !1
         48        DO_ICALL                                         $29     
         49        ADD_ARRAY_ELEMENT                                ~28     $29, 'content'
         50        INIT_ARRAY                                       ~30     ~28, 'http'
   50    51        ASSIGN                                                   !9, ~30
   58    52        INIT_FCALL                                               'file_get_contents'
         53        SEND_VAR                                                 !5
         54        SEND_VAL                                                 <false>
         55        INIT_FCALL                                               'stream_context_create'
         56        SEND_VAR                                                 !9
         57        DO_ICALL                                         $32     
         58        SEND_VAR                                                 $32
         59        DO_ICALL                                         $33     
         60      > RETURN                                                   $33
   59    61*     > RETURN                                                   null

End of function api_call

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
211.81 ms | 1396 KiB | 39 Q