@@ -114,22 +114,33 @@ public function into_class( string $class, string $method, $query = [], $parent
114114 }
115115
116116 public function call_api ( $ method , $ path , $ query = null , $ params =null ) {
117+ $ method = strtoupper ($ method );
117118 $ key = ['apiKey ' => $ this ->key ];
118- $ query = array_merge_recursive ($ key , $ query ??[]);
119- $ options = ['query ' => $ query ];
120- //
121- if (!empty ($ params ['form_params ' ])||!empty ($ params ['multipart ' ])){
122- $ options = array_merge_recursive ($ options ,$ params );
123- }else if (!empty ($ params )){
124- $ options = ['query ' => $ query ,'form_params ' =>$ params ];
119+ $ options = ['query ' => $ key ];
120+
121+ if ('GET ' ==$ method && !empty ($ query )){
122+ $ query = array_merge_recursive ($ key , $ query ??[]);
123+ $ options = ['query ' => $ this ->http_build_query ($ query )];
124+ }else if (in_array ($ method ,['POST ' ,'PUT ' ,'PATCH ' ,'DELETE ' ] )&& !empty ($ params )){
125+ if (!empty ($ params ['multipart ' ])){
126+ $ options = array_merge_recursive ($ options ,$ params );
127+ }else {
128+ $ options ['body ' ] = $ this ->http_build_query ($ params ['form_params ' ]??$ params );
129+ }
125130 }
131+ //
126132 $ res = $ this ->send_request ($ method , $ path ,$ options );
127133 if ( str_contains ($ res ->getHeader ("Content-Type " )[0 ], 'json ' ) ) {
128134 return json_decode ($ res ->getBody ()->getContents ());
129135 }
130136
131137 return $ res ->getBody ()->getContents ();
132138 }
139+ protected function http_build_query ($ data ,$ numeric_prefix =false ,$ arg_separator =null ,$ encoding_type =PHP_QUERY_RFC3986 ){
140+ $ str = http_build_query ($ data ,$ numeric_prefix ,$ arg_separator =null ,$ encoding_type );
141+ $ str = preg_replace ('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/ ' , '%5B%5D= ' , $ str );
142+ return $ str ;
143+ }
133144
134145 protected function send_request ( $ method , $ path , $ opts ) {
135146 try {
0 commit comments