Skip to content

Instantly share code, notes, and snippets.

@quangpro1610
Last active February 16, 2022 10:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quangpro1610/491c279c1bbc6a329dd6a68c01015fea to your computer and use it in GitHub Desktop.
Save quangpro1610/491c279c1bbc6a329dd6a68c01015fea to your computer and use it in GitHub Desktop.
API get data sumary about corona virus of Vietnam and Global
<?php
header('Content-Type: text/html; charset=utf-8');
$url = 'https://code.junookyo.xyz/api/ncov-moh/data.json';
$content = file_get_contents($url);
$json = json_decode($content, true);
$data = $json['data'];
$result = array(
'messages' => array(
'0' => array(
'text' => "Thế giới: \n + Số ca nhiễm: " . number_format($data['global']['cases'],0,",",".") . "\n + Tử vong: " . number_format($data['global']['deaths'],0,",",".") . "\n + Đã hồi phục: " . number_format($data['global']['recovered'],0,",",".") . "\n\nViệt Nam: \n + Số ca nhiễm: " . number_format($data['vietnam']['cases'],0,",",".") . "\n + Tử vong: " . number_format($data['vietnam']['deaths'],0,",",".") . "\n + Đã hồi phục: " .number_format($data['vietnam']['recovered'],0,",",".")
),
)
);
echo json_encode($result, JSON_UNESCAPED_UNICODE);
@quangpro1610
Copy link
Author

14.03.2020 - 21:37 PM: Fix lại code, không cần phải ghi vô file json nữa, chỉ cần in ra là được rồi. Có thể dùng postman để kiểm tra chuỗi json trả về.

@quangpro1610
Copy link
Author

14.03.2020 - 21:37 PM: Fix lại code, không cần phải ghi vô file json nữa, chỉ cần in ra là được rồi. Có thể dùng postman để kiểm tra chuỗi json trả về.

Thay vì gọi đến file json trong API url thì bạn gọi vào chatfuel trực tiếp từ file này.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment