代码之家  ›  专栏  ›  技术社区  ›  jay ram

如何在URL核心php中从API获取JSON?

  •  0
  • jay ram  · 技术社区  · 1 年前

    我没有得到json,我已经试过很多次了。我没有得到任何json。如果你知道其中哪一个是错误的,请让我知道这个网站url json没有发布我尝试掠夺时间没有相关api https://kalviaruvi.com/simpleshopping/api-firebase/get-categories.php?accesskey=90336

    此get-categories.php

         `<?php
         header('Access-Control-Allow-Origin: *');
         header("Content-Type: application/json");
         header("Expires: 0");
         header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
        header("Cache-Control: no-store, no-cache, must-revalidate");
        header("Cache-Control: post-check=0, pre-check=0", false);
        header("Pragma: no-cache");
        include_once('../includes/crud.php');
        $db = new Database();
        $db->connect();
        include_once('../includes/variables.php');
        include_once('../includes/custom-functions.php');
        $fn = new custom_functions;
        $config = $fn->get_configurations();
        $time_slot_config = $fn->time_slot_config();
        if (isset($config['system_timezone']) && isset($config['system_timezone_gmt'])) {
        date_default_timezone_set($config['system_timezone']);
        $db->sql("SET `time_zone` = '" . $config['system_timezone_gmt'] . "'");
        } else {
        date_default_timezone_set('Asia/Kolkata');
        $db->sql("SET `time_zone` = '+05:30'");
        }
        if (isset($_POST['accesskey'])) {
        $access_key_received = $db->escapeString($fn- 
     >xss_clean($_POST['accesskey']));
        if ($access_key_received == $access_key) {
            // get all category data from category table
            $sql_query = "SELECT * 
                FROM category 
                ORDER BY id ASC ";
            $db->sql($sql_query);
            $res = $db->getResult();
            if (!empty($res)) {
                for ($i = 0; $i < count($res); $i++) {
                    $res[$i]['image'] = (!empty($res[$i]['image'])) ? DOMAIN_URL . '' . $res[$i]['image'] : '';
                    $res[$i]['web_image'] = (!empty($res[$i]['web_image'])) ? DOMAIN_URL . '' . $res[$i]      ['web_image'] : '';
                }
                $tmp = [];
                foreach ($res as $r) {
                    $r['childs'] = [];
    
                    $db->sql("SELECT * FROM subcategory WHERE category_id = '" . $r['id'] . "' ORDER BY id   DESC");
                    $childs = $db->getResult();
                    if (!empty($childs)) {
                        for ($i = 0; $i < count($childs); $i++) {
                            $childs[$i]['image'] = (!empty($childs[$i]['image'])) ? DOMAIN_URL . '' . $childs[$i]['image'] : '';
                            $r['childs'][$childs[$i]['slug']] = (array)$childs[$i];
                        }
                    }
                    $tmp[] = $r;
                }
                $res = $tmp;
                $response['error'] = "false";
                $response['data'] = $res;
            } else {
                $response['error'] = "true";
                $response['message'] = "No data found!";
            }
            print_r(json_encode($response));
        } else {
            die('accesskey is incorrect.');
        }
         } else {
        die('accesskey is require.');
        }
        $db->disconnect();
    

    此自定义功能

       `<?php
    //access key to access API
    $access_key = "90336";
    
    //google play url
    $gplay_url = "https://play.google.com/store/apps/details?id=com.city.ecommerce";
    
    // email configuration
    $email_subject = "Notification of changes to account information!";
    $change_message = "You have change your admin info such as email and or password.";
    $reset_message = "Your new password is ";
    
    //order notification configuration
    $reservation_subject = "New Order Notification!";
    $reservation_message = "There is new order, please check Admin Panel.";
    $order_subject = "Order Confirm Notification!";
    $order_message = "your order has been placed. we will reach to you very soon";
    
    $register_subject = "Thank You for Registering with City-Ecommerce";
    $register_message = "Thank You for Registering with City-Ecommerce. We Welcome you to best shopping experience for your family";
    $process_subject = "Confirmation mail for you City-Ecommerce order no ";
    $process_message = "Thank you for shopping at City-Ecommerce<br>
        The following items in your order will be shipped from our warehouse.<br>
        Once these items have been shipped, we will send you an email with the expected delivery date.<br>
        Order Details: <br>";
    $shipped_subject = " Your City-Ecommerce Order has been shipped from here";
    $shipped_message = "Thank you for your order on City-Ecommerce. Your Order No .";
                        
    $delievered_subject = " Your City-Ecommerce order no.";
    $delievered_message = "Thank you for your order on City-Ecommerce. Your Order No .";
    //copyright
    $copyright = "";
    
        ?>`
    

    如何获取json-api-url

    1 回复  |  直到 1 年前
        1
  •  1
  •   Allen Chak    1 年前

    使用 $_GET 而不是 $_POST 如果您想从URL中获取值,请在get-categories.php中。

    如果您想继续使用 $_POST ,您不能通过浏览器访问API,只需将参数附加在URL的末尾。