示例#1
0
 public function actionBuchangGem()
 {
     glog::info(json_encode($_REQUEST), 'addgem');
     glog::info(json_encode($_SERVER), 'addgem');
     $hour = date("H");
     if ($hour < 10 || $hour > 21) {
         // 10:00 ~ 21:59 才能使用这个接口,防止阿里云的云盾自动发起回调...
         // 有没有更好的处理方法...
         return $this->response(array('s' => 'ERROR', 'msg' => '操作时间不合法'));
     }
     $keys = array('section_id', 'product_id', 'platform', 'operator', 'optime');
     $params = array();
     foreach ($keys as $key) {
         ${$key} = trim(self::getParam($key));
         if (empty(${$key})) {
             $msg = "need param [{$key}]";
             glog::info($msg, 'addgem');
             return $this->response(array('s' => 'ERROR', 'msg' => $msg));
         }
         $params[$key] = ${$key};
     }
     $now = time();
     if ($now - $params['optime'] > 60 || $params['optime'] - $now > 60) {
         return $this->response(array('s' => 'ERROR', 'msg' => '操作已过期'));
     }
     $pid = self::getParam('pid');
     if ($pid) {
         $um = model_LoginUser::searchUniq('pid', $pid);
         if (!$um) {
             return $this->response(array('ErrorCode' => 0, 'ErrorDesc' => "用户[{$pid}]不存在"));
         }
         $uid = $um->id();
     } else {
         $uid = self::getParam('uid');
     }
     if (empty($uid)) {
         return $this->response(array('s' => 'ERROR', 'msg' => "需要UID参数"));
     }
     if ($params['platform'] != P_PLATFORM) {
         return $this->response(array('s' => StatusCode::error, 'msg' => "平台信息不匹配"));
     }
     if ($product_id == 'custom') {
         if (!in_array(P_PLATFORM, array('qqandroid', 'kunlun'))) {
             return $this->response(array('s' => StatusCode::error, 'msg' => P_PLATFORM . "平台不支持自定义额度支付"));
         }
         $params['cash'] = trim(self::getParam('cash'));
         if (!is_numeric($params['cash']) || $params['cash'] <= 0) {
             return $this->response(array('s' => StatusCode::error, 'msg' => "自定义额度{$params['cash']}不合法"));
         }
     } else {
         $payment_config = getApp()->getPaymentConifg();
         if (!isset($payment_config[$product_id])) {
             $msg = "product_id[{$product_id}] not exists";
             glog::info($msg, 'addgem');
             return $this->response(array('s' => 'ERROR', 'msg' => $msg));
         }
     }
     // 验证参数
     if (0 && !isset($_REQUEST['__no_sig__']) && !$this->verify_signature($params, 'qxs%Mt6v@nVdUb9d')) {
         return $this->response(array('s' => 'ERROR', 'msg' => "signature verification failed"));
     }
     PL_Session::$usecookie = false;
     $_REQUEST['cid'] = PL_Session::gencid($uid, $section_id);
     $player = getApp()->getPlayer();
     $mon = getApp()->getPaymentMongoConnection();
     $mongoid = new MongoID();
     $transaction_id = $mongoid->{'$id'};
     // 生成新的订单信息
     $payment_info = $player->createPaymentInfo($product_id);
     if ($product_id == 'custom') {
         $payment_info['cash'] = $params['cash'];
         if (P_PLATFORM == 'kunlun') {
             $payment_info['sumGem'] = $payment_info['cash'] * 15;
         }
     }
     $payment_info['transaction_id'] = $transaction_id;
     $payment_info['create_t'] = getApp()->now;
     $payment_info['source'] = 'buchang';
     $payment_info['msg'] = $params['operator'] . "给玩家补偿未到账的支付,";
     $old_vip = $payment_info['_vip'];
     $old_gem = $payment_info['ogem'];
     // 订单上次处理异常 或者 新的订单
     $ret = $player->process_payment($payment_info);
     if ($ret['s'] == StatusCode::ok) {
         $msg = "transaction [{$transaction_id}] processed";
         glog::info($msg, 'addgem');
         if (1) {
             $gem_add_and_reward = $ret['info']['gem_add_and_reward'];
             // 补发传书
             $msg = array('type' => 'system', 'key' => uniqid(), 'time' => getApp()->now, 'content' => "您未到账的{$gem_add_and_reward}元宝已经补发到账,祝您游戏愉快~");
             model_Chat::sendMsg($msg, $uid, 'origin', $section_id);
         } else {
             $gem_add_and_reward = $ret['info']['gem_add_and_reward'];
             $reward_gem = ceil($gem_add_and_reward * 0.1);
             // 补发传书
             $msg = array('type' => 'system', 'key' => uniqid(), 'time' => getApp()->now, 'content' => "您未到账的{$gem_add_and_reward}元宝已经补发到账,现在额外补偿您{$reward_gem}元宝,祝您游戏愉快~");
             $awards = array(array('tag' => 'gem', 'num' => $reward_gem));
             $msg['status'] = 'award';
             $cdkey = model_Cdkey::gen($awards, "{$reward_gem}元宝");
             $msg['cdkey'] = $cdkey;
             model_Chat::sendMsg($msg, $uid, 'origin', $section_id);
         }
         // 发邮件
         $login_model = new model_LoginUser($uid);
         $login_model->get(array('pid' => 1, 'email' => 1));
         $pid = $login_model['pid'];
         $email = $login_model['email'];
         $login_model->opOne('buchange_gem_t', getApp()->now);
         $login_model->save();
         $new_gem = $player->numberGet('base', 'gem');
         $new_vip = $player->numberGet('vip', 'lvl');
         $platform = P_PLATFORM;
         $name = $player->stringGet('base', 'name');
         $cash = $payment_config[$product_id]['cash'];
         $operator = $params['operator'];
         $subject = "[{$operator}]BuChangChongZhi[{$platform}][{$section_id}][{$uid}][{$cash} yuan]";
         $time = date("Y-m-d H:i:s");
         $content = "操作时间: {$time} \n";
         $content .= "操作人:{$operator}\n平台: {$platform}\nPID:{$pid}\nemail:{$email}\nUID:{$uid}\n分区:{$section_id}\n门派名:{$name}\n";
         $content .= "充值前:\nvip:{$old_vip}\ngem:{$old_gem}\n";
         $content .= "充值后:\nvip:{$new_vip}\ngem:{$new_gem}\n";
         model_Util::sendemail('*****@*****.**', $subject, $content);
         return $this->response(array('s' => 'OK', 'msg' => $msg, 'ret' => $ret));
     } else {
         $msg = "transaction[{$transaction_id}] failed," . $ret['msg'];
         glog::info($msg, 'addgem');
         return $this->response(array('s' => 'ERROR', 'msg' => $msg, 'ret' => $ret));
     }
 }
示例#2
0
 function actionSendMsgToAwardUsers()
 {
     $uid_secs = self::getParam('uid_secs');
     $content = self::getParam('content');
     $desc = self::getParam('desc');
     $items = self::getParam('items');
     $task_num = self::getParam('num');
     error_log("====接受到奖励信息==" . json_encode($uid_secs));
     if (!$uid_secs) {
         return;
     }
     foreach ((array) $items as $value) {
         $tag = $value['tag'];
         $num = intval($value['num']);
         if ($tag == 'gem' && $num > 100000) {
             echo "error, 元宝不能大于100000";
             exit;
         }
     }
     $key = uniqid();
     $msg = array('key' => $key, 'time' => app()->now, 'content' => $content, 'type' => 'system');
     //福利号总服务器地址
     $all_config = (include_once ROOT . "/admin/view/public_const_config.php");
     //设置作废福利号接口
     $server_url = $all_config['server_api_url'] . "?action=setRepeal&mod=admin";
     $DEBUG = true;
     foreach ((array) $uid_secs as $uid => $sec) {
         //if( $uid != 3879133 )continue;//temp
         //error_log("send[$uid][$sec]");
         //check 是否合服 改变UID
         $sec_config = getApp()->getSectionConfig($sec);
         if (isset($sec_config['merge'])) {
             $uid = "{$sec}_{$uid}";
             $sec = $sec_config['merge'];
         }
         if ($DEBUG) {
             error_log("开始发送元宝:{$uid}--{$sec}");
         }
         $player = new model_Player($uid, $sec);
         $player->getFields(array('level', 'test_status', 'login_t', 'gem'));
         $level = $player->numberGet("base", "level");
         $gem = $player->objectGet("base", "gem");
         $login = $player->objectGet("base", "login_t");
         //只执行一次  执行一次没有句号的描述 就可以将大于20w的置为20w
         $bool = $content == "鉴于掌门对武林做出了卓越贡献,特此奖励掌门一些物件,方便行走江湖,还望掌门笑纳" ? true : false;
         if ($bool && $gem > 200000) {
             //当前元宝大于20w 且 不是单次发送 将该玩家元宝置为20w 不给发此次元宝
             error_log("change_gem:uid:{$uid},{$sec},gem:{$gem}");
             $player->numberPut('base', 'gem', 200000);
             $player->commit();
             if ($DEBUG) {
                 error_log("error.20w");
             }
             continue;
         }
         if ($task_num != 1 && $gem > 50000) {
             //现有元宝数量大于N不给发 且 不是单次发送
             if ($DEBUG) {
                 error_log("{$gem}元宝大于5w,{$task_num}");
             }
             continue;
         }
         if ($_SERVER['REQUEST_TIME'] - $login > 10 * 86400) {
             //10天没登陆 设置为作废福利号
             model_Util::send_post($server_url, array('uid' => $uid, 'sec' => $sec));
             if ($DEBUG) {
                 error_log("大于10天没登录");
             }
             continue;
         }
         foreach ($items as $key => $value) {
             $tag = $value['tag'];
             $num = intval($value['num']);
             if ($tag == 'qiyu_zhidian') {
                 $zhidian_lvl = max(1, $level * 3 - 34);
                 for ($i = 0; $i < $num; $i++) {
                     $items[] = array('tag' => 'qiyu_zhidian', 'level' => $zhidian_lvl, 'num' => 1);
                 }
                 unset($items[$key]);
             }
         }
         if ($DEBUG) {
             error_log("====={$value['tag']}={$value['num']}");
         }
         if ($value['tag'] == 'gem') {
             if ($DEBUG) {
                 error_log("enter");
             }
             $player->checkVipUpgradeAward($value['num']);
             $player->commit();
         }
         if (is_array($items) && count($items) > 0) {
             $msg['status'] = 'award';
             #$msg['content'].="\n$desc";
             $cdkey = model_Cdkey::gen($items, $desc, 1, 'def');
             $msg['cdkey'] = $cdkey;
         }
         $r = model_Chat::sendMsg($msg, $uid, 'origin', $sec);
     }
 }
示例#3
0
 /**
  * 检查参数签名
  */
 function authSig($request)
 {
     $method = $request['m'];
     $param = $request['p'];
     if ($param['signature']) {
         $signature = $param['signature'];
         unset($param['signature']);
         $keys = array_keys($param);
         sort($keys);
         $s = '';
         foreach ($keys as $key) {
             $value = $param[$key];
             if (is_string($value) || is_numeric($value) || is_bool($value)) {
                 $s .= '&' . $key . '=' . $value;
             }
         }
         $s = substr($s, 1) . $method . P_VERSION . '~@#1xdaf,dmuopamie%%123.';
         $mysig = md5($s);
         if ($mysig != $signature) {
             glog::info("签名不对[{$mysig}]!=[{$signature}], " . json_encode($request), 'sign');
             return array('s' => StatusCode::invalid_siginature, 'msg' => 'invalid signature');
         }
         $timestamp = $param['timestamp'];
         if ($method == 'System.login') {
             // 手机设备时间和服务器时间可能有差异,所以第一次请求 System.login 时不验证时间。
             return false;
         }
         // 1. 对 timestamp 做验证 与 服务器当前时间相差太多的 认为是不合法的请求
         $now = getApp()->now;
         if (abs($now - $timestamp) > 300) {
             $ts1 = date('Y-m-d H:i:s', $now);
             $ts2 = date('Y-m-d H:i:s', $timestamp);
             glog::info("请求时间异常 server[{$ts1}], client[{$ts2}], " . json_encode($request), 'sign');
             return false;
             return array('s' => StatusCode::invalid_request_time, 'msg' => 'invalid timestamp');
         }
         // 2. 记录用户上次调用这个接口的时间戳,如果新的 timestamp <= old_timestamp 则认为是不合法的请求
         $uid = getApp()->getuid();
         $section_id = getApp()->getsec();
         if ($uid && $section_id) {
             if (model_Util::inBlacklist($uid)) {
                 //黑名单访问,禁止
                 glog::info("黑名单中玩家[{$uid}]访问分区[{$section_id}] " . json_encode($request), 'blacklist');
                 return array('s' => StatusCode::invalid_request_time, 'msg' => "uid[{$uid}] is in blacklist");
             }
             try {
                 $redis = DbConfig::getRedis('cache');
                 $timestamp_key = "sig_{$section_id}_{$uid}_{$method}";
                 $old_timestamp = $redis->get($timestamp_key);
                 if (is_numeric($old_timestamp)) {
                     // 手机端网络超时后重试,后台可能会收到两次同样时间戳的请求 所以 $timestamp == $old_timestamp 还是很有可能的
                     if ($timestamp < $old_timestamp) {
                         $ts1 = date('Y-m-d H:i:s', $old_timestamp);
                         $ts2 = date('Y-m-d H:i:s', $timestamp);
                         glog::info("请求时间异常, 上次请求[{$ts1}], 本次请求[{$ts2}], " . json_encode($request), 'sign');
                         return false;
                         return array('s' => StatusCode::outdated_siginature, 'msg' => 'outdated signature', 'debug' => "old_timestamp: {$old_timestamp}");
                     } else {
                         $redis->multi();
                         $redis->set($timestamp_key, $timestamp);
                         $redis->expire($timestamp_key, 360);
                         $redis->exec();
                         return false;
                     }
                 } else {
                     $redis->multi();
                     $redis->set($timestamp_key, $timestamp);
                     $redis->expire($timestamp_key, 360);
                     $redis->exec();
                     return false;
                 }
             } catch (Exception $ex) {
                 error_log("无法连接 cache redis ");
                 return false;
             }
         }
         return false;
     }
     glog::info("没有签名," . json_encode($request), 'sign');
     return array('s' => StatusCode::invalid_siginature, 'msg' => 'no signature');
 }
示例#4
0
 /**
  * 抢亲 发奖
  */
 private static function awardQiangQin($award_config, $tag, $my_num = 0, $player_pos = array(), &$player, $config, &$log, $rank, $uid, $sec)
 {
     if (empty($award_config)) {
         $awards = array();
     } else {
         $awards = $award_config['awards' . $tag];
     }
     $send_awards = array();
     if ($tag == 3) {
         if ($my_num >= 2000) {
             foreach ($awards as $value) {
                 if ($value['tag'] == 102001) {
                     $is_have = $player->objectGet('peoples', 102001);
                     //没有王语嫣
                     if (empty($is_have)) {
                         //$object = array('tag'=>102001,'level'=>1,'create_t'=>$now);
                         //$player->objectPut('peoples',102001,$object);
                         $send_awards[] = array('tag' => $value['tag'], 'num' => $value['num']);
                     } else {
                         //有王语嫣发魂魄
                         //$player->numberIncr('soul',112001,1000);
                         $send_awards[] = array('tag' => 112001, 'num' => 1000);
                     }
                 } else {
                     //加道具
                     //$player->addItem($value['tag'],$value['num']);
                     $send_awards[] = array('tag' => $value['tag'], 'num' => $value['num']);
                 }
             }
         }
     } else {
         foreach ($awards as $value) {
             //$player->addItem($value['tag'],$value['num']);
             $send_awards[] = array('tag' => $value['tag'], 'num' => $value['num']);
         }
     }
     // 如果是最后一次奖励既24点奖励,根据比例返回一定元宝
     if ($tag == 3 && !empty($my_num)) {
         // 防止小数点,返回比例是500 表示 50%返还
         if (!empty($award_config)) {
             $return_gem = ceil($my_num * $award_config['fanhuan'] / 1000);
         } else {
             $return_gem = ceil($my_num * 50 / 1000);
         }
         //$player->rewardGem($return_gem,'燕子坞抢亲活动奖励');
         $send_awards[] = array('tag' => 'gem', 'num' => $return_gem);
     }
     $date_rever = array('12:00', '21:00', '24:00');
     $value = array('msg_date' => $date_rever[$tag - 1], 'msg_rank' => $rank + 1, 'msg_awards' => model_Util::returnMsgStr($send_awards));
     $content = model_Translate::getTrans("tid#act_yanziwu_before20_msg", $value);
     //echo $content."\n";
     //发传书奖励
     model_Award::awardToUser($uid, $sec, $content, $send_awards);
     echo "{$uid}-{$sec}-{$content}奖励如下:\n";
     print_r($send_awards);
     $log['uid'] = $uid;
     $log['sec'] = $sec;
     $log['tag'] = $tag;
     $log['rank'] = $rank;
     $log['player_pos'] = $player_pos;
     $log['my_num'] = $my_num;
     $log['awards'] = $send_awards;
 }