3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * TME API - code snippet. * * More info at: https://developers.tme.eu */ if(!function_exists('hash_hmac')) { function hash_hmac($algo, $data, $key, $raw_output = false) { $algo = strtolower($algo); $pack = 'H'.strlen($algo('test')); $size = 64; $opad = str_repeat(chr(0x5C), $size); $ipad = str_repeat(chr(0x36), $size); if (strlen($key) > $size) { $key = str_pad(pack($pack, $algo($key)), $size, chr(0x00)); } else { $key = str_pad($key, $size, chr(0x00)); } for ($i = 0; $i < strlen($key) - 1; $i++) { $opad[$i] = $opad[$i] ^ $key[$i]; $ipad[$i] = $ipad[$i] ^ $key[$i]; } $output = $algo($opad.pack($pack, $algo($ipad.$data))); return ($raw_output) ? pack($pack, $output) : $output; } } $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
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
filename:       /in/dMGtT
function name:  (null)
number of ops:  31
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                                               'function_exists'
          1        SEND_VAL                                                 'hash_hmac'
          2        DO_ICALL                                         $5      
          3        BOOL_NOT                                         ~6      $5
          4      > JMPZ                                                     ~6, ->6
    9     5    >   DECLARE_FUNCTION                                         'hash_hmac'
   34     6    >   ASSIGN                                                   !0, 'b050bd709a43eecc443820c022b6774ca703ddb216b6f6765f'
   35     7        ASSIGN                                                   !1, '5656847466f0e5d08577'
   36     8        ASSIGN                                                   !2, <array>
   43     9        INIT_FCALL_BY_NAME                                       'api_call'
         10        SEND_VAL_EX                                              'Products%2FGetPrices'
         11        SEND_VAR_EX                                              !2
         12        SEND_VAR_EX                                              !0
         13        SEND_VAR_EX                                              !1
         14        SEND_VAL_EX                                              <true>
         15        DO_FCALL                                      0  $10     
         16        ASSIGN                                                   !3, $10
   44    17        INIT_FCALL                                               'json_decode'
         18        SEND_VAR                                                 !3
         19        SEND_VAL                                                 <true>
         20        DO_ICALL                                         $12     
         21        ASSIGN                                                   !4, $12
   46    22        INIT_FCALL                                               'var_dump'
         23        SEND_VAL                                                 '8.0.0'
         24        DO_ICALL                                                 
   48    25        ECHO                                                     '%3Cpre%3E'
   49    26        INIT_FCALL                                               'print_r'
         27        SEND_VAR                                                 !4
         28        DO_ICALL                                                 
   50    29        ECHO                                                     '%3C%2Fpre%3E'
   82    30      > RETURN                                                   1

Function %00hash_hmac%2Fin%2FdMGtT%3A9%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 42
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
2 jumps found. (Code = 44) Position 1 = 65, Position 2 = 50
Branch analysis from position: 65
2 jumps found. (Code = 43) Position 1 = 79, Position 2 = 85
Branch analysis from position: 79
1 jumps found. (Code = 42) Position 1 = 86
Branch analysis from position: 86
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 85
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
2 jumps found. (Code = 44) Position 1 = 65, Position 2 = 50
Branch analysis from position: 65
Branch analysis from position: 50
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
filename:       /in/dMGtT
function name:  hash_hmac
number of ops:  88
compiled vars:  !0 = $algo, !1 = $data, !2 = $key, !3 = $raw_output, !4 = $pack, !5 = $size, !6 = $opad, !7 = $ipad, !8 = $i, !9 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV_INIT                                        !3      <false>
   11     4        INIT_FCALL                                               'strtolower'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $10     
          7        ASSIGN                                                   !0, $10
   12     8        INIT_DYNAMIC_CALL                                        !0
          9        SEND_VAL_EX                                              'test'
         10        DO_FCALL                                      0  $12     
         11        STRLEN                                           ~13     $12
         12        CONCAT                                           ~14     'H', ~13
         13        ASSIGN                                                   !4, ~14
   13    14        ASSIGN                                                   !5, 64
   14    15        INIT_FCALL                                               'str_repeat'
         16        SEND_VAL                                                 '%5C'
         17        SEND_VAR                                                 !5
         18        DO_ICALL                                         $17     
         19        ASSIGN                                                   !6, $17
   15    20        INIT_FCALL                                               'str_repeat'
         21        SEND_VAL                                                 '6'
         22        SEND_VAR                                                 !5
         23        DO_ICALL                                         $19     
         24        ASSIGN                                                   !7, $19
   17    25        STRLEN                                           ~21     !2
         26        IS_SMALLER                                               !5, ~21
         27      > JMPZ                                                     ~22, ->42
   18    28    >   INIT_FCALL                                               'str_pad'
         29        INIT_FCALL                                               'pack'
         30        SEND_VAR                                                 !4
         31        INIT_DYNAMIC_CALL                                        !0
         32        SEND_VAR_EX                                              !2
         33        DO_FCALL                                      0  $23     
         34        SEND_VAR                                                 $23
         35        DO_ICALL                                         $24     
         36        SEND_VAR                                                 $24
         37        SEND_VAR                                                 !5
         38        SEND_VAL                                                 '%00'
         39        DO_ICALL                                         $25     
         40        ASSIGN                                                   !2, $25
         41      > JMP                                                      ->48
   20    42    >   INIT_FCALL                                               'str_pad'
         43        SEND_VAR                                                 !2
         44        SEND_VAR                                                 !5
         45        SEND_VAL                                                 '%00'
         46        DO_ICALL                                         $27     
         47        ASSIGN                                                   !2, $27
   23    48    >   ASSIGN                                                   !8, 0
         49      > JMP                                                      ->61
   24    50    >   FETCH_DIM_R                                      ~31     !6, !8
         51        FETCH_DIM_R                                      ~32     !2, !8
         52        BW_XOR                                           ~33     ~31, ~32
         53        ASSIGN_DIM                                               !6, !8
         54        OP_DATA                                                  ~33
   25    55        FETCH_DIM_R                                      ~35     !7, !8
         56        FETCH_DIM_R                                      ~36     !2, !8
         57        BW_XOR                                           ~37     ~35, ~36
         58        ASSIGN_DIM                                               !7, !8
         59        OP_DATA                                                  ~37
   23    60        PRE_INC                                                  !8
         61    >   STRLEN                                           ~39     !2
         62        SUB                                              ~40     ~39, 1
         63        IS_SMALLER                                               !8, ~40
         64      > JMPNZ                                                    ~41, ->50
   28    65    >   INIT_DYNAMIC_CALL                                        !0
         66        INIT_FCALL                                               'pack'
         67        SEND_VAR                                                 !4
         68        INIT_DYNAMIC_CALL                                        !0
         69        CONCAT                                           ~42     !7, !1
         70        SEND_VAL_EX                                              ~42
         71        DO_FCALL                                      0  $43     
         72        SEND_VAR                                                 $43
         73        DO_ICALL                                         $44     
         74        CONCAT                                           ~45     !6, $44
         75        SEND_VAL_EX                                              ~45
         76        DO_FCALL                                      0  $46     
         77        ASSIGN                                                   !9, $46
   30    78      > JMPZ                                                     !3, ->85
         79    >   INIT_FCALL                                               'pack'
         80        SEND_VAR                                                 !4
         81        SEND_VAR                                                 !9
         82        DO_ICALL                                         $48     
         83        QM_ASSIGN                                        ~49     $48
         84      > JMP                                                      ->86
         85    >   QM_ASSIGN                                        ~49     !9
         86    > > RETURN                                                   ~49
   31    87*     > RETURN                                                   null

End of function %00hash_hmac%2Fin%2FdMGtT%3A9%240

Function api_call:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dMGtT
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
-------------------------------------------------------------------------------------
   54     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
          4        RECV_INIT                                        !4      <false>
   56     5        CONCAT                                           ~10     'https%3A%2F%2Fapi.tme.eu%2F', !0
          6        CONCAT                                           ~11     ~10, '.json'
          7        ASSIGN                                                   !5, ~11
   59     8        ASSIGN_DIM                                               !1, 'Token'
          9        OP_DATA                                                  !2
   60    10        INIT_FCALL                                               'ksort'
         11        SEND_REF                                                 !1
         12        DO_ICALL                                                 
   63    13        INIT_FCALL                                               'str_replace'
   64    14        SEND_VAL                                                 <array>
   65    15        SEND_VAL                                                 <array>
   66    16        INIT_FCALL                                               'http_build_query'
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                         $15     
         19        SEND_VAR                                                 $15
         20        DO_ICALL                                         $16     
   63    21        ASSIGN                                                   !6, $16
   68    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
   69    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
   71    42        ASSIGN_DIM                                               !1, 'ApiSignature'
         43        OP_DATA                                                  !8
   75    44        INIT_ARRAY                                       ~28     'POST', 'method'
   76    45        ADD_ARRAY_ELEMENT                                ~28     'Content-type%3A+application%2Fx-www-form-urlencoded', 'header'
   77    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'
   73    51        ASSIGN                                                   !9, ~30
   81    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
   82    61*     > RETURN                                                   null

End of function api_call

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.93 ms | 1412 KiB | 45 Q