<?php
include 'cauhinh.php';
$userDB           = "root";
$passDB           = "Helloword@@123@@12111@";
$server           = "localhost";
$DBase            = "account";
$conn['host']     = $server;
$conn['dbname']   = $DBase;
$conn['username'] = $userDB;
$conn['password'] = $passDB;
@mysql_connect("{$conn['host']}", "{$conn['username']}", "{$conn['password']}") or die("Ko thể kết nối data ...");
@mysql_select_db("{$conn['dbname']}") or die("chào bạn");
$connect = new mysqli($server, $userDB, $passDB, $DBase);
$connect->set_charset("utf8");
if ($connect->connect_error) {
    die("Bảo trì quay lại sau " . $connect->connect_error);
    exit();
}
date_default_timezone_set("Asia/Ho_Chi_Minh");

$result = curl_get_contents('https://api.web2m.com/historyapimomo1h/D2212F8A-6480-E8BD-3632-632A409C0FE7'); // thay token https://api.web2m.com/historyapimomo1h/ ? token


        $result = json_decode($result, true);
        foreach ((array) $result['momoMsg']['tranList'] as $data)
        {
            $partnerId      = $data['partnerId'];               // SỐ ĐIỆN THOẠI CHUYỂN
            $comment        = $data['comment'];                 // NỘI DUNG CHUYỂN TIỀN
            $tranId         = $data['tranId'];                  // MÃ GIAO DỊCH
            $partnerName    = $data['partnerName'];             // TÊN CHỦ VÍ
            $thaidz         = $data['amount'];                  // SỐ TIỀN CHUYỂN
            $io         = $data['io'];                  // IO

        
		$cmd = strtolower($comment);
		$thai = explode('nap ',$cmd);
		$username = $thai[1];
		$amount = $thaidz * $khuyenmai;

if($io == 1 && strpos($cmd,'nap') !== false){
    if(mysql_num_rows(mysql_query("SELECT tranid FROM naptien WHERE tranid='".$tranId."'")) == 0){
        $time = time();

        @mysql_query("INSERT INTO `naptien`(`uid`, `sotien`, `loaithe`, `time`, `tinhtrang`, `tranid`) VALUES ('$username','$amount ','MoMo','$time','1','$tranId');");
        @mysql_query("UPDATE `player` SET `coin` = `coin` + '$amount', `tongnap` = `tongnap` + '$amount' , `tongthang` = `tongthang` + '$amount' WHERE `username` = '$username' ");
        echo' '.$username.' + '.$amount.'vnd <br>';
        }
    }

}

?>