Chủ Nhật, 8 tháng 1, 2017

Transaction API setMerchantId($merchant_id); $vippay_api->setApiUser($api_user); $vippay_api->setApiPassword($api_password); $vippay_api->setPin($sopin); $vippay_api->setSeri($seri); $vippay_api->setCardType(intval($card_type)); $vippay_api->setNote($user); // Ghi chu cua ban $vippay_api->cardCharging(); $code = intval($vippay_api->getCode()); $amount = intval($vippay_api->getInfoCard()); $error = $vippay_api->getMsg(); if ($code === 0 && $amount >= 10000) { switch ($amount) { case 10000: $xu = 15; break; case 20000: $xu = 20; break; case 30000: $xu = 30; break; case 50000: $xu = 55; break; case 100000: $xu = 115; break; case 200000: $xu = 235; break; case 300000: $xu = 300; break; case 500000: $xu = 600; break; case 1000000: $xu = 1300; break; } // Xu ly thong tin tai day $file = "carddung.log"; $fh = fopen($file, 'a') or die("cant open file"); fwrite($fh, "Tai khoan: " . $user . ", Loai the: " . $ten . ", Menh gia: " . $xu . ", Thoi gian: " . $transaction_id); fwrite($fh, "\r\n"); fclose($fh); $db = new mysqli(IP, USER, PASSWD, PPDB); $uid = uuidConvert($user); $res = $db->query('SELECT * FROM playerpoints WHERE playername="' . $uid . '" LIMIT 1'); if ($res->num_rows == 0) { $db->query('INSERT INTO playerpoints (playername,points) VALUES ("' . $uid . '",' . $xu . ')'); } else { $db->query('UPDATE playerpoints SET points=points+' . $xu . ' WHERE playername="' . $uid . '"'); } $db->close(); echo ''; } else { echo ''; $file = "cardsai.log"; $fh = fopen($file, 'a') or die("cant open file"); fwrite($fh, "Tai khoan: " . $user . ", Ma the: " . $sopin . ", Seri: " . $seri . ", Noi dung loi: " . $error . ", Thoi gian: " . $transaction_id); fwrite($fh, "\r\n"); fclose($fh); echo $error; } //var_dump($test); //echo '

ID request:' . $transaction_id; } function uuidFromString($string) { $val = md5($string, true); $byte = array_values(unpack('C16', $val)); $tLo = ($byte[0] << 24) | ($byte[1] << 16) | ($byte[2] << 8) | $byte[3]; $tMi = ($byte[4] << 8) | $byte[5]; $tHi = ($byte[6] << 8) | $byte[7]; $csLo = $byte[9]; $csHi = $byte[8] & 0x3f | (1 << 7); if (pack('L', 0x6162797A) == pack('N', 0x6162797A)) { $tLo = (($tLo & 0x000000ff) << 24) | (($tLo & 0x0000ff00) << 8) | (($tLo & 0x00ff0000) >> 8) | (($tLo & 0xff000000) >> 24); $tMi = (($tMi & 0x00ff) << 8) | (($tMi & 0xff00) >> 8); $tHi = (($tHi & 0x00ff) << 8) | (($tHi & 0xff00) >> 8); } $tHi &= 0x0fff; $tHi |= (3 << 12); $uuid = sprintf( '%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x', $tLo, $tMi, $tHi, $csHi, $csLo, $byte[10], $byte[11], $byte[12], $byte[13], $byte[14], $byte[15] ); return $uuid; } function uuidConvert($string) { $string = uuidFromString("OfflinePlayer:" . $string); return $string; } class Vippay_API { private $merchant_id; private $pin; private $seri; private $card_type; private $api_user; private $api_password; private $code; private $msg; private $info_card; private $transaction_id; private $note; /** * @return the $merchant_id */ public function getMerchantId() { return $this->merchant_id; } /** * @return the $pin */ public function getPin() { return $this->pin; } /** * @return the $seri */ public function getSeri() { return $this->seri; } /** * @return the $card_type */ public function getCardType() { return $this->card_type; } /** * @return the $api_user */ public function getApiUser() { return $this->api_user; } /** * @return the $api_password */ public function getApiPassword() { return $this->api_password; } /** * @return the $code */ public function getCode() { return $this->code; } /** * @return the $msg */ public function getMsg() { return $this->msg; } /** * @return the $info_card */ public function getInfoCard() { return $this->info_card; } /** * @return the $transaction_id */ public function getTransactionId() { return $this->transaction_id; } /** * @return the $note */ public function getNote() { return $this->note; } /** * @param field_type $merchant_id */ public function setMerchantId($merchant_id) { $this->merchant_id = $merchant_id; } /** * @param field_type $pin */ public function setPin($pin) { $this->pin = $pin; } /** * @param field_type $seri */ public function setSeri($seri) { $this->seri = $seri; } /** * @param field_type $card_type */ public function setCardType($card_type) { $this->card_type = $card_type; } /** * @param field_type $api_user */ public function setApiUser($api_user) { $this->api_user = $api_user; } /** * @param field_type $api_password */ public function setApiPassword($api_password) { $this->api_password = $api_password; } /** * @param field_type $code */ public function setCode($code) { $this->code = $code; } /** * @param field_type $msg */ public function setMsg($msg) { $this->msg = $msg; } /** * @param field_type $info_card */ public function setInfoCard($info_card) { $this->info_card = $info_card; } /** * @param field_type $transaction_id */ public function setTransactionId($transaction_id) { $this->transaction_id = $transaction_id; } /** * @param field_type $note */ public function setNote($note) { $this->note = $note; } public function cardCharging() { $fields = array( 'merchant_id' => $this->merchant_id, 'pin' => $this->pin, 'seri' => $this->seri, 'card_type' => $this->card_type, 'note' => $this->note ); $ch = curl_init("https://vippay.vn/api/api/card"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 120); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_USERPWD, $this->api_user . ":" . $this->api_password); $result = curl_exec($ch); $result = json_decode($result); $this->code = $result->code; $this->msg = $result->msg; $this->info_card = $result->info_card; $this->transaction_id = $result->transaction_id; } } ?>