程式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. (
  2. [年級] => 1
  3. [班名] =>
  4. [班序] => 1
  5. [導師] => Array
  6. (
  7. [0] => stdClass Object
  8. (
  9. [姓名] => xx
  10. [身分證編碼] => c0e43562cadf2eebba750c5a28835b09fxxxxx
  11. )
  12.  
  13. )
  14.  
  15. [學期編班] => Array
  16. (
  17. [0] => stdClass Object
  18. (
  19. [學號] => 109001
  20. [座號] => 1
  21. [姓名] => xx
  22. [英文姓名] =>
  23. [性別] =>
  24. [身分證編碼] => de049fc43f3a4017ab207ecd4a013976xxxxxx
  25. )
  26. ........................................
  1. )
  1. [學期教職員] => Array
  2. (
  3. [0] => stdClass Object
  4. (
  5. [處室] => 學務處
  6. [職稱] => 學務主任
  7. [姓名] => xx
  8. [帳號] => xxxx
  9. [性別] =>
  10. [身分證編碼] => dad27ff40b2f07cfa866af8510df535046b4dac98125df78d13bxxxx
  11. [任教科目] => Array
  12. (
  13. [0] => stdClass Object
  14. (
  15. [年級] => 4
  16. [班序] => 6
  17. [科目] => 電腦
  18. [時數] => 1
  19. )
  20.  
  21. [1] => stdClass Object
  22. (
  23. [年級] => 4
  24. [班序] => 7
  25. [科目] => 電腦
  26. [時數] => 1
  27. )
  28.  
  29. )
  30.  
  31. )
  1. ..........................
  1. [單位資料] => Array
  2. (
  3. [0] => stdClass Object
  4. (
  5. [處室編號] => 1
  6. [處室名稱] => 校長室
  7. [電話] =>
  8. [分機] =>
  9. [網址] =>
  10. [排序] => 1
  11. [單位職稱] => Array
  12. (
  13. [0] => stdClass Object
  14. (
  15. [職稱] => 校長
  16. [職稱編號] => 1
  17. [職別] => 校長
  18. [排序] => 1
  19. )
  20.  
  21. )
  22.  
  23. )
  1. ...................................
  1. [課表] => Array
  2. (
  3. [0] => stdClass Object
  4. (
  5. [年級] => 1
  6. [班序] => 1
  7. [班名] =>
  8. [星期] => 1
  9. [節次] => 1
  10. [科目] => 體育
  11. [兼課] =>
  12. [專科教室] =>
  13. [教師] => xxx
  14. [身分證編碼] => 18d1e6dc4f1e03a4a0bbacdb23b9761a9d6fbb142xxxxxxx
  15. )

  1. ...................................

沒有留言:

張貼留言