程式CODE

2020年12月1日 星期二

cloudschool 學期資料api

 <?php

$API_client_id = "api ID";

$API_client_secret = "api 密碼";


$data = API($API_client_id,$API_client_secret);


echo "<pre>";

print_r($data);


function API($API_client_id,$API_client_secret){


    // =================================================

    //    學生榮譽榜 (url: https://api.chc.edu.tw)

    //    校務佈告欄 (url: https://api.chc.edu.tw/school-news)

    //    同步學期資料 (url: https://api.chc.edu.tw/semester-data)

    //    更改師生密碼 (url: https://api.chc.edu.tw/change-password)


    // API NAME

    $api_name = '/semester-data';

    //$api_name = '/school-news';

    // 更改師生密碼 (url: https://api.chc.edu.tw/change-password)


    // API URL

    $api_url = 'https://api.chc.edu.tw';

    //: https://api.chc.edu.tw/school-news

    // 建立 CURL 連線

    $ch = curl_init();

    // 取 access token

    curl_setopt($ch, CURLOPT_URL, $api_url."/oauth?authorize");

    // 設定擷取的URL網址

    curl_setopt($ch, CURLOPT_POST, TRUE);

    // the variable

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);


    curl_setopt($ch, CURLOPT_POSTFIELDS, array(

        'client_id' => $API_client_id,

        'client_secret' => $API_client_secret,

        'grant_type' => 'client_credentials'

    ));


    $data = curl_exec($ch);

    $data = json_decode($data);


    $access_token = $data->access_token;

    $authorization = "Authorization: Bearer ".$access_token;


    curl_setopt($ch, CURLOPT_URL, $api_url.$api_name);

    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization )); // **Inject Token into Header**

    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);


//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

    $result = curl_exec($ch);

    return json_decode($result);

}

========================================================

帶出

    [更新時間] => 2020-12-02 05:36:13

    [學年] => 109

    [學期] => 1

    [學期開始日期] => 2020-08-01

    [學期結束日期] => 2021-01-31

    [開學日] => 2020-08-31

    [結業日] => 2021-01-20

    [學期編班] => Array

        ( [0] => stdClass Object

                (
                    [年級] => 1
                    [班名] => 一
                    [班序] => 1
                    [導師] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [姓名] => 葉xx
                                    [身分證編碼] => c0e43562cadf2eebba750c5a28835b09fxxxxx
                                )

                        )

                    [學期編班] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [學號] => 109001
                                    [座號] => 1
                                    [姓名] => 王xx
                                    [英文姓名] => 
                                    [性別] => 男
                                    [身分證編碼] => de049fc43f3a4017ab207ecd4a013976xxxxxx
                                )
........................................
                )
    [學期教職員] => Array
        (
            [0] => stdClass Object
                (
                    [處室] => 學務處
                    [職稱] => 學務主任
                    [姓名] => 謝xx
                    [帳號] => xxxx
                    [性別] => 男
                    [身分證編碼] => dad27ff40b2f07cfa866af8510df535046b4dac98125df78d13bxxxx
                    [任教科目] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [年級] => 4
                                    [班序] => 6
                                    [科目] => 電腦
                                    [時數] => 1
                                )

                            [1] => stdClass Object
                                (
                                    [年級] => 4
                                    [班序] => 7
                                    [科目] => 電腦
                                    [時數] => 1
                                )

                        )

                )
..........................
    [單位資料] => Array
        (
            [0] => stdClass Object
                (
                    [處室編號] => 1
                    [處室名稱] => 校長室
                    [電話] => 
                    [分機] => 
                    [網址] => 
                    [排序] => 1
                    [單位職稱] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [職稱] => 校長
                                    [職稱編號] => 1
                                    [職別] => 校長
                                    [排序] => 1
                                )

                        )

                )
...................................
    [課表] => Array
        (
            [0] => stdClass Object
                (
                    [年級] => 1
                    [班序] => 1
                    [班名] => 一
                    [星期] => 1
                    [節次] => 1
                    [科目] => 體育
                    [兼課] => 
                    [專科教室] => 
                    [教師] => 黃xxx
                    [身分證編碼] => 18d1e6dc4f1e03a4a0bbacdb23b9761a9d6fbb142xxxxxxx
                )

...................................

沒有留言:

張貼留言