opencart4 api document
Call
*- Method to call the storefront API and return a response.
* - @Example
* - We create a hash from the data in a similar method to how amazon does things.
* - $call = 'order';
- $username = 'API username';
- $key = 'API Key';
- $domain = 'www.yourdomain.com';
- $path = '/';
- $store_id = 0;
- $language = 'en-gb';
- $time = time();
* - // Build hash string
- $string = $call . "\n";
- $string .= $username . "\n";
- $string .= $domain . "\n";
- $string .= $path . "\n";
- $string .= $store_id . "\n";
- $string .= $language . "\n";
- $string .= $currency . "\n";
- $string .= json_encode($_POST) . "\n";
- $string .= $time . "\n";
* - $signature = base64_encode(hash_hmac('sha1', $string, $key, true));
* - // Make remote call
- $url = '&call=' . $call;
- $url = '&username=' . urlencode($username);
- $url .= '&store_id=' . $store_id;
- $url .= '&language=' . $language;
- $url .= '¤cy=' . $currency;
- $url .= '&time=' . $time;
- $url .= '&signature=' . rawurlencode($signature);
* - $curl = curl_init();
* - curl_setopt($curl, CURLOPT_URL, 'https://' . $domain . $path . 'index.php?route=api/api' . $url);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($curl, CURLOPT_HEADER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
- curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
- curl_setopt($curl, CURLOPT_TIMEOUT, 30);
- curl_setopt($curl, CURLOPT_POST, 1);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $_POST);
* - $response = curl_exec($curl);
* - $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
* - curl_close($curl);
* - if ($status == 200) {
- $response_info = json_decode($response, true);
- } else {
- $response_info = [];
- }
* - @return void
*/`
- Method to call the storefront API and return a response.
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。