function card_payment_item() { $json['error'] = ""; $json['errorShow'] = ""; $json['arrReturn'] = ""; $json['up_number'] = 0; $json['title'] = 0; if (!User::is_login()) { $json['error'] = "not_login"; echo json_encode($json); exit; } if (User::is_block()) { $json['error'] = "no_permission"; echo json_encode($json); exit; } $user = User::$current->data; $card_type = Url::get('card_type'); $card_code = Url::get('card_code'); $pay_full_name = Url::get('pay_full_name'); $pay_mobile = Url::get('pay_mobile'); $item_id = (int) Url::get('item_id', 0); $transaction_info = "Mua lượt up bằng thẻ cào ({$card_type}) cho tin co ID: {$item_id}, của {$pay_full_name} ({$user['user_name']}), SDT: {$pay_mobile}, Email: {$user['email']}"; //insert vao payment_cards $aryCard = array('user_id' => $user['id'], 'user_name' => $user['user_name'], 'email' => $user['email'], 'phone' => $pay_mobile, 'card_code' => $card_code, 'card_type' => $card_type, 'time_add' => TIME_NOW, 'order_info' => $transaction_info, 'error_text' => '', 'payment_status' => 0, 'order_code' => '', 'price' => 0, 'type' => 2); $cardId = DB::insert('payment_cards', $aryCard); if ($cardId) { $order_code = "card_{$cardId}"; DB::update('payment_cards', array('order_code' => $order_code), "id={$cardId}"); $arrReturn = SohaPay::doChargeCard($card_code, $card_type, $transaction_info, $order_code, $user['email'], $pay_mobile, CARD_MERCHANT_SITE_CODE, CARD_SECURE_CODE); if (!empty($arrReturn)) { //tao key cho memcache $key = 'errCard' . $user['id']; $error_text = SohaPay::getResponseDescriptionMobileCard($arrReturn['response_code']); $json['errorShow'] = SohaPay::showResponseMobileCard($arrReturn['response_code']); if ($arrReturn['response_code'] == 1) { //lấy giá trị thẻ nạp và số lượt up $price = $arrReturn['price']; $up_number = SohaPay::$card[$price]['value']; $json['up_number'] = $up_number; $sms_item_up_auto = array('item_id' => (int) $item_id, 'up_total' => $up_number, 'up_number' => $up_number, 'sms_number' => $this->check_mobile($pay_mobile), 'time' => TIME_NOW, 'status' => 1, 'note' => $transaction_info, 'type' => 3); //insert $sms_item_up_auto_id = DB::insert("sms_item_up_auto", $sms_item_up_auto); if ($sms_item_up_auto_id) { //lấy số lần nhập của user $numErr = AZMemcache::do_get("card:{$key}"); $numErr = $numErr ? $numErr : 1; //update trang thai thanh cong cho bang payment_card DB::update('payment_cards', array("sms_item_up_auto_id" => $sms_item_up_auto_id, "time_payment" => strtotime($arrReturn['payment_time']), "up_number" => $up_number, 'error_text' => $error_text, 'payment_status' => 1, 'order_code' => $order_code, 'price' => $price, 'num_err' => $numErr), "id={$cardId}"); //xoa cache if (MEMCACHE_ON) { AZMemcache::do_remove("card:{$key}"); } $json['arrReturn'] = $arrReturn; echo json_encode($json); exit; } } else { // Lỗi if (MEMCACHE_ON) { $numErr = AZMemcache::do_get("card:{$key}"); $numErr = $numErr ? $numErr : 1; AZMemcache::do_put("card:{$key}", $numErr + 1, 86400); } if ($numErr > 2 && $numErr < 5) { $json['errorShow'] .= '<br/>Bạn đã nhập sai ' . $numErr . ' lần liên tiếp. Nếu bạn nhập sai mã số 5 lần liên tiếp tài khoản của bạn sẽ bị khoá.<br><br>'; } if ($numErr >= 5 && !User::is_admin() && !User::is_root()) { $day_block = 1; $time_start = mktime(24, 0, 0, date('m'), date('d'), date('Y')); $time_expire = $time_start + $day_block * 24 * 3600; $reason_block = "Nhập sai mã thẻ điện thoại 5 lần liên tiếp"; if (DB::query("UPDATE user SET block_time={$time_expire} WHERE id = {$user['id']}")) { DB::insert('user_lock', array('time' => TIME_NOW, 'time_expire' => $time_expire, 'user_id' => $user['id'], 'user_name' => $user['user_name'], 'type' => 0, 'note' => $reason_block, 'admin_id' => 4, 'admin_name' => 'admin')); // Kiem duyet tin khi khoa thanh vien $arr_data = array('user_id' => $user['id'], 'reason_invalid' => 'Khóa thành viên nên khóa tất cả Topic, ' . $reason_block); $this->lockItemWhenLockAccount($arr_data, 1); // end kiem duyet tin khi khoa thanh vien } $json['errorShow'] .= '<br/>Bạn đã bị khoá tài khoản 1 ngày do nhập sai mã số 5 lần liên tiếp.<br><br>'; //xoa cache if (MEMCACHE_ON) { AZMemcache::do_remove("card:{$key}"); } User::LogOut(); } DB::update('payment_cards', array('error_text' => $error_text, 'payment_status' => 2, 'order_code' => $order_code, 'num_err' => $numErr), "id={$cardId}"); $json['error'] = 'error'; echo json_encode($json); exit; } } //if(!empty($arrReturn)) $json['error'] = 'error'; $json['errorShow'] = "Có lỗi hệ thống nạp card"; echo json_encode($json); exit; } //if($cardId) $json['error'] = 'error'; $json['errorShow'] = "Có lỗi kết nối với cơ sở dữ liệu"; echo json_encode($json); exit; }
static function doChargeCard($card_code, $card_type, $transaction_info, $order_code, $order_email, $order_mobile, $site_code, $secure_code) { // Mảng các tham số chuyển tới Soha Payment $arr_param = array('site_code' => strval($site_code), 'card_code' => strval($card_code), 'card_type' => strval($card_type), 'transaction_info' => strval($transaction_info), 'order_code' => strval($order_code), 'order_email' => strval($order_email), 'order_mobile' => strval($order_mobile), 'command' => 'doChargeMobileCard'); ksort($arr_param); /* Bước 2. Kiểm tra biến $redirect_url xem có '?' không, nếu không có thì bổ sung vào*/ if (SOHA_PAYMENT_QUERY_URL != 'https://pay.soha.vn/payment_query.php') { $query_url = 'https://pay.soha.vn/payment_query.php'; } else { $query_url = SOHA_PAYMENT_QUERY_URL; } if (strpos($query_url, '?') === false) { $query_url .= '?'; } else { if (substr($query_url, strlen($query_url) - 1, 1) != '?' && strpos($query_url, '&') === false) { // Nếu biến $redirect_url có '?' nhưng không kết thúc bằng '?' và có chứa dấu '&' thì bổ sung vào cuối $query_url .= '&'; } } /* Bước 3. tạo url*/ $first = true; $secure_code = $secure_code; foreach ($arr_param as $key => $value) { if ($first == true) { $query_url .= urlencode($key) . '=' . urlencode($value); $first = false; } else { $query_url .= '&' . urlencode($key) . '=' . urlencode($value); } $secure_code .= $value; } if (strlen($secure_code) > 0) { $query_url .= "&secure_hash=" . strtoupper(md5($secure_code)); } ob_start(); // initialise Client URL object $ch = curl_init(); // set the URL of the VPC curl_setopt($ch, CURLOPT_URL, $query_url); curl_setopt($ch, CURLOPT_POST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_exec($ch); // get response $response = ob_get_contents(); // turn output buffering off. ob_end_clean(); // close client URL curl_close($ch); $map = array(); $response = substr($response, 1); $pairArray = split("&", $response); foreach ($pairArray as $pair) { $param = split("=", $pair); $map[urldecode($param[0])] = urldecode($param[1]); } $map['shp_payment_response_description'] = SohaPay::getResponseDescriptionMobileCard($map['response_code']); return $map; }