123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567 |
- <?php
- namespace huoIdentify\controller;
- use huo\controller\common\CommonFunc;
- use huo\model\game\GameModel;
- use huo\model\member\MemberModel;
- use huoIdentify\logic\IdentifyDayDotLogic;
- use huoIdentify\logic\IdentifyDayIdotLogic;
- use huoIdentify\logic\IdentifyDayMotLogic;
- use huoIdentify\logic\IdentifyDotLogic;
- use huoIdentify\logic\IdentifyIdotLogic;
- use huoIdentify\logic\IdentifyMotLogic;
- use huoIdentify\model\IdentifyMemModel;
- use huolib\constant\CommonConst;
- use huolib\constant\GameConst;
- use huolib\constant\IdentifyConst;
- use huolib\constant\MemConst;
- use huolib\status\CommonStatus;
- use huolib\status\MemberStatus;
- use huolib\tool\StrUtils;
- use huolib\utils\IdentifyUtils;
- use think\Cookie;
- class Online {
- protected $app_id = 0;
- protected $mem_id = 0;
- protected $device_id = '';
- protected $id_card = '';
- protected $return_url = '';
- protected $identify_conf = [];
- protected $token = '';
- public function __construct($app_id, $mem_id, $device_id) {
- $this->setAppId($app_id);
- $this->setMemId($mem_id);
- $this->setDeviceId($device_id);
- $this->setIdCard();
- $this->identify_conf = (new IdentifyConf())->getConf();
- }
-
- public function heartOnline() {
- $app_id = $this->getAppId();
- $_game_auth = (new GameModel())->getIsAuthById($app_id);
-
- if (GameConst::GAME_IDENTIFY_IS_NO == $_game_auth) {
- return $this->return_url;
- }
-
- $this->updateOnlineTime();
-
- $this->checkLimit();
- return $this->return_url;
- }
-
- public function nonageCheck() {
- $_app_id = $this->getAppId();
- $_game_auth = (new GameModel())->getIsAuthById($this->getAppId());
-
- if (GameConst::GAME_IDENTIFY_IS_NO == $_game_auth) {
- $_code = CommonStatus::NO_ERROR;
- return ['code' => $_code, 'msg' => CommonStatus::getMsg($_code)];
- }
- $_id_card = $this->getIdCard();
-
- if (!empty($_id_card)) {
- $_age = IdentifyUtils::getAgeById($_id_card);
-
- if ($_age >= 18) {
- $_code = CommonStatus::NO_ERROR;
- return ['code' => $_code, 'msg' => CommonStatus::getMsg($_code)];
- }
-
- $_url = $this->checkUnderageLimitOnTheHour();
- $_code = MemberStatus::NO_ERROR;
- $_data = [];
- if (!empty($_url)) {
- $_code = MemberStatus::LOGIN_IS_OUT;
- $_data['url'] = $_url;
- }
- return ['code' => $_code, 'msg' => MemberStatus::getMsg($_code), 'data' => $_data];
- }
- $_code = CommonStatus::NO_ERROR;
- return ['code' => $_code, 'msg' => CommonStatus::getMsg($_code)];
- }
-
- public function getTimeLeft() {
- $_rdata = [
- 'time_left' => CommonConst::CONST_ZERO,
- 'bind_url' => ''
- ];
- $_game_auth = (new GameModel())->getIsAuthById($this->app_id);
-
- if (GameConst::GAME_IDENTIFY_IS_NO == $_game_auth) {
- return $_rdata;
- }
- if (empty($this->mem_id)) {
-
- return $_rdata;
- }
- $_mem_model = new MemberModel();
- $_status = $_mem_model->getStatus($this->mem_id);
- if (MemConst::STATUS_TRY != $_status) {
-
- return $_rdata;
- }
- $_mobile = $_mem_model->getMobileById($this->mem_id);
- if (!empty($_mobile)) {
-
- return $_rdata;
- }
- $_param = [
- 'app_id' => $this->app_id,
- 'device_id' => $this->device_id,
- 'token' => $this->getToken()
- ];
- $_rdata = [
- 'time_left' => CommonConst::CONST_ZERO,
- 'bind_url' => IdentifyConst::getBindMobileUrl($_param)
- ];
- $_unnamed_limit = $this->identify_conf['unnamed']['limit_time'];
- $_now_online_time = 0;
- $_mot_logic = new IdentifyMotLogic();
- $_mot_data = $_mot_logic->getInfoByMemId($this->mem_id);
- $_online_time = get_val($_mot_data, 'online_duration', CommonConst::CONST_ZERO);
- if ($_online_time >= $_now_online_time) {
- $_now_online_time = $_online_time;
- }
- if (!empty($this->device_id)) {
- $_dot_logic = new IdentifyDotLogic();
- $_dot_data = $_dot_logic->getInfoByDevice($this->device_id);
- $_online_time = get_val($_dot_data, 'online_duration', CommonConst::CONST_ZERO);
- if ($_online_time >= $_now_online_time) {
- $_now_online_time = $_online_time;
- }
- }
- $_diff_time = $_unnamed_limit - $_now_online_time;
- if ($_diff_time > CommonConst::CONST_ZERO) {
- $_rdata['time_left'] = ceil($_diff_time / CommonConst::CONST_MINUTE_SECONDS);
- }
- return $_rdata;
- }
-
- public function checkLimit() {
- $_id_card = $this->getIdCard();
-
- if (!empty($_id_card)) {
- $_age = IdentifyUtils::getAgeById($_id_card);
-
- if ($_age >= 18) {
- return '';
- }
-
- return $this->checkUnderageLimit();
- }
-
-
- $_identify_class = new Identify();
- $_in_progress_data = $_identify_class->getInProgressDataByMemApp($this->mem_id, $this->app_id);
- if (!empty($_in_progress_data)) {
- $_real_name = get_val($_in_progress_data, 'real_name', '');
- $_id_card = get_val($_in_progress_data, 'id_card', '');
- $_identify_class->updateIdentify($this->mem_id, 1, $_real_name, $_id_card, $this->app_id);
- return '';
- }
-
-
-
- $this->checkDeviceLimit();
- if (!empty($this->return_url)) {
- return $this->return_url;
- }
-
- $this->checkMemLimit();
- if (!empty($this->return_url)) {
- return $this->return_url;
- }
- return $this->return_url;
- }
-
- public function checkDeviceLimit() {
- $_app_id = $this->app_id;
- $_device_id = $this->device_id;
- $_mem_id = $this->mem_id;
- if (!empty($_device_id)) {
- $_dot_logic = new IdentifyDotLogic();
- $_dot_data = $_dot_logic->getInfoByDevice($_device_id);
- $_now_time = time();
-
- $_online_time = get_val($_dot_data, 'online_duration', CommonConst::CONST_ZERO);
- $_limit_day = $this->identify_conf['unnamed']['expired_day'];
- $_unnamed_limit = $this->identify_conf['unnamed']['limit_time'];
- if (($_online_time >= $_unnamed_limit) || ($_dot_data['next_allow_time'] > $_now_time)) {
-
- $_param = [
- 'app_id' => $_app_id,
- 'device_id' => $_device_id,
- 'token' => $this->getToken()
- ];
- $_identify_url = IdentifyConst::getIdentifyUrl($_param);
- if (!empty($_mem_id)) {
-
- $_mem_model = new MemberModel();
- $_mobile = $_mem_model->getMobileById($_mem_id);
- $_status = $_mem_model->getStatus($_mem_id);
- if (empty($_mobile) && MemConst::STATUS_TRY == $_status) {
-
- $_identify_url = IdentifyConst::getBindMobileUrl($_param);
- }
- }
- $this->return_url = $_identify_url;
-
- if (empty($_dot_data['next_allow_time'])) {
- $_dot_data['next_allow_time'] = $_now_time + ($_limit_day * CommonConst::CONST_DAY_SECONDS);
- $_dot_logic->updateByDevice($_dot_data, $_device_id);
- }
-
- if ($_unnamed_limit > $_online_time) {
- $_dot_data['next_allow_time'] = CommonConst::CONST_ZERO;
- $_dot_logic->updateByDevice($_dot_data, $_device_id);
- $this->return_url = '';
- }
-
- if (!empty($_dot_data['next_allow_time']) && $_dot_data['next_allow_time'] <= $_now_time) {
- $_dot_data['online_duration'] = CommonConst::CONST_ZERO;
- $_dot_data['next_allow_time'] = CommonConst::CONST_ZERO;
- $_dot_logic->updateByDevice($_dot_data, $_device_id);
- $this->return_url = '';
- }
- }
- }
- return $this->return_url;
- }
-
- public function checkMemLimit() {
- $_mem_id = $this->mem_id;
- $_app_id = $this->app_id;
- $_device_id = $this->device_id;
- if (!empty($_mem_id)) {
- $_mot_logic = new IdentifyMotLogic();
- $_mot_data = $_mot_logic->getInfoByMemId($_mem_id);
- $_now_time = time();
-
- $_online_time = get_val($_mot_data, 'online_duration', CommonConst::CONST_ZERO);
- $_limit_day = $this->identify_conf['unnamed']['expired_day'];
- $_unnamed_limit = $this->identify_conf['unnamed']['limit_time'];
- if (($_online_time >= $_unnamed_limit) || ($_mot_data['next_allow_time'] > $_now_time)) {
-
- $_param = [
- 'app_id' => $_app_id,
- 'device_id' => $_device_id,
- 'token' => session_id()
- ];
- $_identify_url = IdentifyConst::getIdentifyUrl($_param);
- if (!empty($_mem_id)) {
-
- $_mem_model = new MemberModel();
- $_mobile = $_mem_model->getMobileById($_mem_id);
- if (empty($_mobile)) {
- $_identify_url = IdentifyConst::getBindMobileUrl($_param);
- }
- }
- $this->return_url = $_identify_url;
-
- if (empty($_mot_data['next_allow_time'])) {
- $_mot_data['next_allow_time'] = $_now_time + ($_limit_day * CommonConst::CONST_DAY_SECONDS);
- $_mot_logic->updateByMemId($_mot_data, $_mem_id);
- }
-
- if ($_unnamed_limit > $_online_time) {
- $_mot_data['next_allow_time'] = CommonConst::CONST_ZERO;
- $_mot_logic->updateByMemId($_mot_data, $_mem_id);
- $this->return_url = '';
- }
-
- if (!empty($_mot_data['next_allow_time']) && $_mot_data['next_allow_time'] <= $_now_time) {
- $_mot_data['online_duration'] = CommonConst::CONST_ZERO;
- $_mot_data['next_allow_time'] = CommonConst::CONST_ZERO;
- $_mot_logic->updateByMemId($_mot_data, $_mem_id);
- $this->return_url = '';
- }
- }
- }
- return $this->return_url;
- }
-
- public function checkUnderageLimit() {
- $_now_time = time();
- $_is_allow_login = (new HolidaySet())->isAllowLogin();
- if (true === $_is_allow_login) {
-
- $_allow_start_time = $this->identify_conf['underage']['allow_start_time'];
- $_allow_start_time_minute
- = $this->identify_conf['underage']['allow_start_time_minute'];
- $_allow_end_time = $this->identify_conf['underage']['allow_end_time'];
- $_allow_end_time_minute = $this->identify_conf['underage']['allow_end_time_minute'];
- $_allow_start_time = mktime(
- $_allow_start_time, $_allow_start_time_minute, 0, date('m'), date('d'), date('Y')
- );
- $_allow_end_time = mktime($_allow_end_time, $_allow_end_time_minute, 0, date('m'), date('d'), date('Y'));
- $_allow_end_time -= CommonFunc::getHeartbeatTime();
- if ($_now_time > $_allow_start_time && $_now_time < $_allow_end_time) {
- return '';
- }
- }
- $_type = IdentifyConst::UNDERAGE_ALLOW_LOGIN_LIMIT;
- $_param = [
- 'app_id' => $this->app_id,
- 'token' => $this->getToken()
- ];
- $this->return_url = IdentifyConst::getUnderageLimitMsgUrl($_type, $_param);
- return $this->return_url;
- }
-
- public function checkUnderageLimitOnTheHour() {
- $_now_time = time();
- $_is_allow_login = (new HolidaySet())->isAllowLogin();
- if (true === $_is_allow_login) {
-
- $_allow_start_time = $this->identify_conf['underage']['allow_start_time'];
- $_allow_start_time_minute
- = $this->identify_conf['underage']['allow_start_time_minute'];
- $_allow_end_time = $this->identify_conf['underage']['allow_end_time'];
- $_allow_end_time_minute = $this->identify_conf['underage']['allow_end_time_minute'];
- $_allow_start_time = mktime(
- $_allow_start_time, $_allow_start_time_minute, 0, date('m'), date('d'), date('Y')
- );
- $_allow_end_time = mktime($_allow_end_time, $_allow_end_time_minute, 0, date('m'), date('d'), date('Y'));
- if ($_now_time > $_allow_start_time && $_now_time < $_allow_end_time) {
- return '';
- }
- }
- $_type = IdentifyConst::UNDERAGE_ALLOW_LOGIN_LIMIT;
- $_param = [
- 'app_id' => $this->app_id,
- 'token' => $this->getToken()
- ];
- $this->return_url = IdentifyConst::getUnderageLimitMsgUrl($_type, $_param);
- return $this->return_url;
- }
-
- public function updateOnlineTime() {
- $_app_id = $this->app_id;
- $_mem_id = $this->mem_id;
- $_id_card = $this->id_card;
- $_device_id = $this->device_id;
- $_heartbeat_time = CommonFunc::getHeartbeatTime();
- $_now_time = time();
- $_heart_time_cache = HeartTimeCache::ins();
- $_last_heart_time = $_heart_time_cache->getLastHeartTime($_app_id, $_mem_id, $_device_id);
- $_heart_time_cache->setLastHeartTime($_now_time, $_app_id, $_mem_id, $_device_id);
- $_diff_time = $_now_time - $_last_heart_time;
- if ($_diff_time > ($_heartbeat_time + 10)) {
-
- return;
- }
-
- if (!empty($_id_card)) {
- (new IdentifyDayIdotLogic())->updateOnlineTimeByIdCard($_heartbeat_time, $_id_card, $_mem_id);
- (new IdentifyIdotLogic())->updateOnlineTimeByIdCard($_heartbeat_time, $_id_card);
- }
-
- if (!empty($_device_id)) {
- (new IdentifyDayDotLogic())->updateOnlineTimeByDevice($_heartbeat_time, $_device_id, $_mem_id);
- if (empty($_id_card)) {
-
- (new IdentifyDotLogic())->updateOnlineTimeByDevice($_heartbeat_time, $_device_id);
- }
- }
-
- if (!empty($_mem_id)) {
- (new IdentifyDayMotLogic())->updateOnlineTimeByMemId($_heartbeat_time, $_mem_id);
- if (empty($_id_card)) {
-
- (new IdentifyMotLogic())->updateOnlineTimeByMemId($_heartbeat_time, $_mem_id);
- }
- }
- }
-
- public function getIdentifyUrl() {
- $_app_id = $this->app_id;
- $_id_card = $this->id_card;
- $_device_id = $this->device_id;
- if (!empty($_id_card)) {
- return '';
- }
- $_mem_status = (new MemberModel())->getStatus($this->mem_id);
- if (MemConst::STATUS_TRY == $_mem_status) {
-
- return '';
- }
- $_param = [
- 'app_id' => $_app_id,
- 'device_id' => $_device_id,
- 'token' => $this->getToken()
- ];
- $_identify_url = IdentifyConst::getIdentifyUrl($_param);
- return $_identify_url;
- }
-
- public function getAppId() {
- return $this->app_id;
- }
-
- public function setAppId($app_id) {
- $this->app_id = $app_id;
- }
-
- public function getMemId() {
- return $this->mem_id;
- }
-
- public function setMemId($mem_id) {
- $this->mem_id = $mem_id;
- }
-
- public function getDeviceId() {
- return $this->device_id;
- }
-
- public function setDeviceId($device_id) {
- if (empty($device_id)) {
- $device_id = $this->getHuoDeviceIdFromCookie();
- }
- $this->device_id = $device_id;
- }
-
- public function getIdCard() {
- return $this->id_card;
- }
-
- public function setIdCard($id_card = '') {
- if (empty($id_card) && !empty($this->mem_id)) {
- $id_card = (new IdentifyMemModel())->getIdCardByMemId($this->mem_id);
- }
- $this->id_card = $id_card;
- }
-
- public function getHuoDeviceIdFromCookie() {
- $_device_id = $this->getSdkDeviceId();
- if (empty($_device_id)) {
- $_device_id = StrUtils::genOrderId(0, 0, $this->mem_id, 'huoh5');
- $this->setSdkDeviceId($_device_id);
- }
- return $_device_id;
- }
-
- public function setSdkDeviceId($device_id) {
-
- $_expire = mktime(0, 0, 0, 1, 1, 2119);
- Cookie::set('HuoSdkDeviceId', $device_id, $_expire);
- }
-
- public function getSdkDeviceId() {
- return Cookie::get('HuoSdkDeviceId');
- }
-
- public function getToken() {
- if (empty($this->token)) {
- return session_id();
- }
- return $this->token;
- }
-
- public function setToken($token) {
- $this->token = $token;
- }
- }
|