API get data sumary about corona virus of Vietnam and Global
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
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
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ề.