<?php

$bank_code = anti_injection($_POST['bank_code']);
$amount = intval ($_POST['amount']);
$tran_id = anti_injection($_POST['tran_id']);
$message = escapeString($_POST['message']);
$captcha = $_POST['ma_bao_mat'];

//Lấy thông tin username và password tại đây https://sv.gamebank.vn/user/tich-hop-qrpay
$Username = 'lnq003';
$Password = '96a3e5595e9d06ea961e748b0961eaff333333333333333322';
$url_code = 0; //Khi cần Gamebank gọi callback đúng link cụ thể, thì các bạn truyền urlcode ở đây, urlcode lấy ở  link https://sv.gamebank.vn/urls . Nếu để trống, chúng tôi sẽ gửi toàn bộ link callback đăng ký với chức năng QRPAY. 

require_once dirname(__FILE__) . '/securimage/securimage.php';$securimage = new Securimage();

if ($securimage->check($captcha) == false) {
     echo json_encode(array('code' => 101, 'message' => "Sai mã bảo mật"));
     exit();
}



$url = 'https://sv.gamebank.vn/payment/api?username='.$Username.'&password='.$Password. '&bank_code='.$bank_code. '&url_code='.$url_code.  '&amount='.$amount.'&tran_id='.$tran_id.'&message='.$message;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$resp = json_decode($output,true);


if($resp['code'] == 1) {
    echo json_encode($resp);
}
else {
    echo json_encode(array('code' => $resp['code'] , 'message' => $resp['message']));
}


//Anti Injection
function anti_injection($post_value)
{
    $banlist = array(
        ' insert ', ' select ', ' update ', ' delete ', 'distinct ', ' having ',
        ' truncate ', ' replace ', ' handler ', ' like ', ' as ', ' or ',
        ' procedure ', ' limit ', ' order by ', ' group by ', ' asc ', ' desc ',
        'concat(', '(select', '/insert', '/select', '/update', '/delete', '/distinct', '/having',
        '/truncate', '/replace', '/handler', '/like', '/as', '/or', '/procedure', '/limit',
        '/order by', '/group by', '/asc', '/desc',
        'chr(', 'chr=', 'chr%20', '%20chr', 'wget%20', '%20wget', 'wget(',
        'cmd=', '%20cmd', 'cmd%20', 'rush=', '%20rush', 'rush%20',
        'union%20', '%20union', 'union(', 'union=', 'echr(', '%20echr', 'echr%20', 'echr=',
        'esystem(', 'esystem%20', 'cp%20', '%20cp', 'cp(', 'mdir%20', '%20mdir', 'mdir(',
        'mcd%20', 'mrd%20', 'rm%20', '%20mcd', '%20mrd', '%20rm',
        'mcd(', 'mrd(', 'rm(', 'mcd=', 'mrd=', 'mv%20', 'rmdir%20', 'mv(', 'rmdir(',
        'chmod(', 'chmod%20', '%20chmod', 'chmod(', 'chmod=', 'chown%20', 'chgrp%20', 'chown(', 'chgrp(',
        'locate%20', 'grep%20', 'locate(', 'grep(', 'diff%20', 'kill%20', 'kill(', 'killall',
        'passwd%20', '%20passwd', 'passwd(', 'telnet%20', 'vi(', 'vi%20',
        'insert%20into', 'select%20', 'nigga(', '%20nigga', 'nigga%20', 'fopen', 'fwrite', '%20like', 'like%20',
        '$_request', '$_get', '$request', '$get', '.system', 'HTTP_PHP', '&aim', '%20getenv', 'getenv%20',
        'new_password', '&icq', '/etc/password', '/etc/shadow', '/etc/groups', '/etc/gshadow',
        'HTTP_USER_AGENT', 'HTTP_HOST', '/bin/ps', 'wget%20', 'uname\x20-a', '/usr/bin/id',
        '/bin///echo', '/bin/kill', '/bin/', '/chgrp', '/chown', '/usr/bin', 'g\+\+', 'bin/python',
        'bin/tclsh', 'bin/nasm', 'perl%20', 'traceroute%20', 'ping%20', '.pl', '/usr/X11R6/bin/xterm', 'lsof%20',
        '/bin/mail', '.conf', 'motd%20', 'HTTP/1.', '.inc.php', 'config.php', 'cgi-', '.eml',
        'file\://', 'window.open', '<SCRIPT>', 'javascript\://', 'img src', 'img%20src', '.jsp', 'ftp.exe',
        'xp_enumdsn', 'xp_availablemedia', 'xp_filelist', 'xp_cmdshell', 'nc.exe', '.htpasswd',
        'servlet', '/etc/passwd', 'wwwacl', '~root', '~ftp', '.js', '.jsp', 'admin_', '.history',
        'bash_history', '.bash_history', '~nobody', 'server-info', 'server-status', 'reboot%20', 'halt%20',
        'powerdown%20', '/home/ftp', '/home/www', 'secure_site, ok', 'chunked', 'org.apache', '/servlet/con',
        '<script', '/robot.txt', '/perl', 'mod_gzip_status', 'db_mysql.inc', '.inc', 'select%20from',
        'select from', 'drop%20', '.system', 'getenv', 'http_', '_php', 'php_', 'phpinfo()', '<?php', '?>', 'sql=',
        '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '=', '%20', ',', '<', '>', '--',
        'csleep', 'XOR', 'script'

    );

    // ---------------------------------------------

    if (preg_match('/[a-zA-Z0-9]+/', $post_value)) {
        $post_value = trim(str_replace($banlist, '', strtolower($post_value)));
        $post_value = stripslashes($post_value);
    } else {
        $post_value = NULL;
    }

    return $post_value;
}

    function escapeString($value) {
        $value = htmlspecialchars(strip_tags(trim($value)));
        return $value;
    }