Skip to content

Instantly share code, notes, and snippets.

@zakirkun
Created April 2, 2020 13:59
Show Gist options
  • Save zakirkun/b2001a3bc313743c4cf497b2877b1cd7 to your computer and use it in GitHub Desktop.
Save zakirkun/b2001a3bc313743c4cf497b2877b1cd7 to your computer and use it in GitHub Desktop.
<?php
/**
* Kawal Corona
* Register here https://app.whatspie.com/
*/
$endpoint = "https://app.whatspie.com/api/messages?";
function _curl($url, $method = "GET", $postdata = null)
{
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_POSTFIELDS => $postdata,
CURLOPT_HTTPHEADER => array(
"Accept: application/json",
"Content-Type: application/x-www-form-urlencoded",
"Authorization: Bearer aZY4OIzGLZ5jZI2jN1HzeVKwkzaKD4M79TKfMgl2HTq8IfIisQ"
),
));
$response = curl_exec($curl);
return $response;
}
function getMessage()
{
global $endpoint;
$_build = array(
'device' => '089505240347'
);
$url = $endpoint.http_build_query($_build);
return _curl($url);
}
function _run()
{
$pesan = json_decode(getMessage(), true);
foreach ($pesan['data'] as $messages) {
if($messages['msg_type'] != 'ingoing') continue;
if (preg_match("/@c.us/i", $messages['from_number'])) {
$nomor = explode("@c.us", $messages['from_number'])[0];
if (preg_match("/!corona/i", $messages['body']) or preg_match("/#corona/i", $messages['body'])) {
$text = _data_corona();
$kirim = _kirim($nomor, $text);
echo $kirim;
}
}
}
}
function _kirim($nomor , $pesan)
{
global $endpoint;
$_build = array(
'receiver' => $nomor,
'device' => '089505240347',
'message' => $pesan,
'type' => 'chat'
);
$data = http_build_query($_build);
$response = _curl($endpoint, 'POST' , $data);
return $response;
}
function _data_corona()
{
$text = "Statistic COVID-19 By kawalcorona.com\n";
$dataId = json_decode(file_get_contents("https://api.kawalcorona.com/indonesia"), true);
$dataGl = [];
$dataGl['positif'] = json_decode(file_get_contents("https://api.kawalcorona.com/positif") , true)['value'];
$dataGl['sembuh'] = json_decode(file_get_contents("https://api.kawalcorona.com/sembuh") , true)['value'];
$dataGl['meninggal'] = json_decode(file_get_contents("https://api.kawalcorona.com/meninggal") , true)['value'];
$text .= "Update Global :
Positif ".$dataGl['positif'].".
Sembuh ".$dataGl['sembuh'].".
Meninggal ".$dataGl['meninggal'].".
-------------------------------------
Update Indonesia :
Positif ".$dataId[0]['positif'].".
Sembuh ".$dataId[0]['sembuh'].".
Meninggal ".$dataId[0]['meninggal'].".
-------------------------------------
Jagalah selalu kesehatan Anda dan Keluarga , jangan berpergian kemana mana jika tidak penting #DiRumahAja.";
return $text;
}
_run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment