Author: Thomas Oster (thomas.oster@rwth-aachen.de)
コード例 #1
0
ファイル: Api.php プロジェクト: sendya/shadowsocks-panel
 /**
  * 淘宝自动发货API
  * 创建卡号
  *
  * @JSON
  */
 public function createCard()
 {
     $CURR_KEY = $_SERVER['HTTP_AUTHORIZATION'];
     if (!$CURR_KEY) {
         header("HTTP/1.1 405 Method Not Allowed");
         exit;
     }
     $KEY = Option::get('SYSTEM_API_KEY');
     if ($KEY == null) {
         $KEY = password_hash(Utils::randomChar(12) . time(), PASSWORD_BCRYPT);
         Option::set('SYSTEM_API_KEY', $KEY);
     }
     $CURR_KEY = str_replace('Basic ', '', $CURR_KEY);
     $CURR_KEY = md5($CURR_KEY . ENCRYPT_KEY);
     $KEY = md5($KEY . ENCRYPT_KEY);
     if (strtoupper($KEY) == strtoupper($CURR_KEY)) {
         $card = new Card();
         $card->card = substr(hash("sha256", time() . Utils::randomChar(10)) . time(), 1, 26);
         $card->add_time = time();
         $card->type = intval(trim($_POST['type']));
         $card->info = trim($_POST['info']);
         $card->status = 1;
         $card->save();
         return array('error' => 0, 'message' => 'success', 'card' => $card);
     } else {
         return array('error' => 1, 'message' => 'Bad Request');
     }
 }
コード例 #2
0
 public function setTags(\Model\Card $c, array $itags)
 {
     //remove all empty tags, create 2 arrays
     //containing trimmed tag and lower-case trimmed tag
     $ltags = array();
     $tags = array();
     foreach ($itags as $t) {
         $t = trim($t);
         if ($t != "") {
             $ltags[] = strtolower($t);
             $tags[] = $t;
         }
     }
     $this->em->beginTransaction();
     //find all tags, which have to be removed
     $toRemove = array();
     foreach ($c->getTags() as $t) {
         if (!in_array(strtolower($t->getName()), $ltags)) {
             $toRemove[] = $t;
         }
     }
     foreach ($toRemove as $t) {
         $c->removeTag($t);
     }
     //find all tags which have to be added
     $newtags = array();
     foreach ($tags as $t) {
         foreach ($c->getTags() as $tt) {
             if (strtolower($tt->getName()) == strtolower($t)) {
                 continue 2;
             }
         }
         //not found
         $newtags[] = $t;
     }
     $tm = new TagsManager();
     foreach ($newtags as $t) {
         //try to find existing tag
         $tag = $tm->findByName(strtolower($t));
         if ($tag == null) {
             $tag = $tm->createTag($t, "#00ff00");
         }
         $c->addTag($tag);
     }
     $this->em->flush();
     $this->em->commit();
 }
コード例 #3
0
ファイル: Card.php プロジェクト: sendya/shadowsocks-panel
 /**
  * 激活(使用)卡号
  * @JSON
  */
 public function activation()
 {
     $user = User::getUserByUserId(User::getCurrent()->uid);
     $result = array('error' => 1, 'message' => '该卡已经被使用或不存在。');
     if ($_POST['actCard'] != null) {
         $actCard = htmlspecialchars(trim($_POST['actCard']));
         $card = Mcard::queryCard($actCard);
         if (!$card || !$card->status) {
             return $result;
         }
         $custom_transfer_level = json_decode(Option::get('custom_transfer_level'), true);
         $custom_transfer_repeat = json_decode(Option::get('custom_transfer_repeat'), true);
         /* 0-套餐卡 1-流量卡 2-测试卡 3-余额卡 */
         if ($card->type == 0) {
             if ($user->plan == 'Z' && $user->transfer > $user->flow_up + $user->flow_down) {
                 $result['message'] = '您的流量套餐尚未使用完毕。无法转换到 ' . Utils::planAutoShow($card->info) . ' 套餐';
                 return $result;
             }
             //判断账户卡号类型是否一致 一致则无视系统叠加开关进行 叠加时间
             $user->payTime = time();
             if ($user->flow_up + $user->flow_down < $user->transfer) {
                 $user->enable = 1;
             } else {
                 $user->enable = 0;
             }
             $cardDay = 31;
             if (is_numeric($card->expireTime)) {
                 $cardDay = intval($card->expireTime);
             }
             $expireTime = 0;
             if ($user->plan == $card->info) {
                 // 卡片与账户类型相等
                 if ($user->expireTime > time()) {
                     $expireTime = $user->expireTime + 3600 * 24 * $cardDay;
                     // 到期时间 = 当前账户到期时间+卡片时间
                 } else {
                     $expireTime = time() + 3600 * 24 * $cardDay;
                     // 到期时间 = 当前系统续费时间+卡片时间
                 }
             } else {
                 if ($user->expireTime < time() || !$custom_transfer_repeat) {
                     $expireTime = time() + 3600 * 24 * $cardDay;
                     // 到期时间 = 不叠加原时间 (当前系统续费时间+卡片时间)
                 } else {
                     $expireTime = $user->expireTime + 3600 * 24 * $cardDay;
                     // 到期时间 = 当前账户到期时间+卡片时间
                 }
             }
             $user->expireTime = $expireTime;
             $user->plan = $card->info;
             $user->transfer = Utils::GB * intval($custom_transfer_level[$user->plan]);
             $result['message'] = '您的账户已升级到 ' . Utils::planAutoShow($user->plan) . ' ,共有流量 ' . Utils::flowAutoShow($user->transfer) . ', 已用 ' . Utils::flowAutoShow($user->flow_down + $user->flow_up) . ', 到期时间:' . date('Y-m-d H:i:s', $user->expireTime);
         } elseif ($card->type == 1) {
             if ($user->plan == 'Z') {
                 $user->transfer += intval($card->info) * Utils::GB;
                 // 如果之前是 流量 套餐,则递增
             } else {
                 $user->transfer = intval($card->info) * Utils::GB;
                 // 如果之前是 普通套餐,则清空总流量并设定新流量
                 $user->flow_up = 0;
                 $user->flow_down = 0;
             }
             if ($user->flow_up + $user->flow_down < $user->transfer) {
                 $user->enable = 1;
             } else {
                 $user->enable = 0;
             }
             $user->plan = 'Z';
             // 强制设定为Z
             $user->expireTime = strtotime("+1 year");
             // 账户可用时间增加一年
             $result['message'] = '您的账户已经激活固定流量套餐,共有流量' . Utils::flowAutoShow($user->transfer) . ' ,该流量到期时间 ' . date('Y-m-d H:i:s', $user->expireTime) . ', 感谢您的使用(注意:流量使用完毕前无法通过套餐卡转换为套餐包月用户)';
         } elseif ($card->type == 2) {
             $user_test_day = Option::get('user_test_day') ?: 7;
             if ($user->plan != 'A') {
                 return array('error' => 1, 'message' => '喂喂,你不是测试账户诶? 没办法帮你续命。');
             }
             $user->plan = 'A';
             $user->payTime = time();
             if ($user->expireTime < time()) {
                 $user->expireTime = time() + 3600 * 24 * intval($user_test_day);
                 // 到期时间
             } else {
                 $user->expireTime = $user->expireTime + 3600 * 24 * intval($user_test_day);
                 // 到期时间
             }
             $user->transfer = Utils::GB * intval($custom_transfer_level[$user->plan]);
             $user->flow_down = 0;
             $user->flow_up = 0;
             $user->enable = 1;
             $result['message'] = '您的账户已经激活测试套餐,共有流量' . Utils::flowAutoShow($user->transfer) . ' ,到期时间 ' . date('Y-m-d H:i:s', $user->expireTime) . ', 感谢您的使用';
         } elseif ($card->type == 3) {
             // 余额卡
             $user->money += intval($card->info);
             $user->save();
             $result['message'] = '余额充值成功,您当前余额为 ' . $user->money . ' 元';
         }
         $card->destroy();
         // 将此卡片禁止
         $user->save();
         $_SESSION['currentUser'] = $user;
         // 将用户信息更新到 session 中.
     }
     return $result;
 }
コード例 #4
0
ファイル: Card.php プロジェクト: sendya/shadowsocks-panel
 /**
  * 导出卡号
  */
 public function export()
 {
     $cards = MCard::queryAll(1);
     $file_name = '卡号列表_' . time() . '.csv';
     $data = '#ID,卡号,类型,参数(套餐卡:套餐类型 / 流量卡:流量(GB) / 试用卡:天数 / 余额卡:充值金额(元)),添加时间,状态' . "\n";
     foreach ($cards as $card) {
         switch ($card->type) {
             case 0:
                 $type = '套餐卡';
                 break;
             case 1:
                 $type = '流量卡';
                 break;
             case 2:
                 $type = '测试卡';
                 break;
             case 3:
                 $type = '余额卡';
                 break;
             default:
                 $type = '-';
                 break;
         }
         $data .= $card->id . ',' . $card->card . ',' . $type . ',' . $card->info . ',' . date('Y-m-d H:i:s', $card->add_time) . ',' . '可用' . "\n";
     }
     header("Content-type:text/csv;charset=utf-8");
     header("Content-Disposition:attachment;filename=" . $file_name);
     header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
     header('Expires:0');
     header('Pragma:public');
     $data = iconv('utf-8', 'gb2312', $data);
     echo $data;
     exit;
 }