Online.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. <?php
  2. /**
  3. * OnlineController.php UTF-8
  4. * 在线时长处理控制器
  5. *
  6. * @date : 2019/11/29 20:54
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : chenbingling <cbl@huosdk.com>
  10. * @version : HUOSDK 8.5
  11. */
  12. namespace huoIdentify\controller;
  13. use huo\controller\common\CommonFunc;
  14. use huo\model\game\GameModel;
  15. use huo\model\member\MemberModel;
  16. use huoIdentify\logic\IdentifyDayDotLogic;
  17. use huoIdentify\logic\IdentifyDayIdotLogic;
  18. use huoIdentify\logic\IdentifyDayMotLogic;
  19. use huoIdentify\logic\IdentifyDotLogic;
  20. use huoIdentify\logic\IdentifyIdotLogic;
  21. use huoIdentify\logic\IdentifyMotLogic;
  22. use huoIdentify\model\IdentifyMemModel;
  23. use huolib\constant\CommonConst;
  24. use huolib\constant\GameConst;
  25. use huolib\constant\IdentifyConst;
  26. use huolib\constant\MemConst;
  27. use huolib\status\CommonStatus;
  28. use huolib\status\MemberStatus;
  29. use huolib\tool\StrUtils;
  30. use huolib\utils\IdentifyUtils;
  31. use think\Cookie;
  32. class Online {
  33. protected $app_id = 0; //当前游戏id
  34. protected $mem_id = 0; //当前玩家id
  35. protected $device_id = ''; //当前设备id
  36. protected $id_card = ''; //当前证件号
  37. protected $return_url = ''; //要返回的url
  38. protected $identify_conf = []; //实名认证配置
  39. protected $token = ''; //请求token
  40. public function __construct($app_id, $mem_id, $device_id) {
  41. $this->setAppId($app_id);
  42. $this->setMemId($mem_id);
  43. $this->setDeviceId($device_id);
  44. $this->setIdCard();
  45. $this->identify_conf = (new IdentifyConf())->getConf();
  46. }
  47. /**
  48. * 在线
  49. *
  50. * @return string $url 实名认证地址或提示信息地址
  51. */
  52. public function heartOnline() {
  53. $app_id = $this->getAppId();
  54. $_game_auth = (new GameModel())->getIsAuthById($app_id);
  55. /* 不需要实名不做任何处理 */
  56. if (GameConst::GAME_IDENTIFY_IS_NO == $_game_auth) {
  57. return $this->return_url;
  58. }
  59. /* 统计时长 */
  60. $this->updateOnlineTime();
  61. /* 校验是否限制 */
  62. $this->checkLimit();
  63. return $this->return_url;
  64. }
  65. /***
  66. * 实名校验和未成年校验,未通过校验的需要退出登陆
  67. */
  68. public function nonageCheck() {
  69. $_app_id = $this->getAppId();
  70. $_game_auth = (new GameModel())->getIsAuthById($this->getAppId());
  71. /* 不需要实名不做任何处理 */
  72. if (GameConst::GAME_IDENTIFY_IS_NO == $_game_auth) {
  73. $_code = CommonStatus::NO_ERROR;
  74. return ['code' => $_code, 'msg' => CommonStatus::getMsg($_code)];
  75. }
  76. $_id_card = $this->getIdCard();
  77. /* 已实名 */
  78. if (!empty($_id_card)) {
  79. $_age = IdentifyUtils::getAgeById($_id_card);
  80. // 成年玩家不限制
  81. if ($_age >= 18) {
  82. $_code = CommonStatus::NO_ERROR;
  83. return ['code' => $_code, 'msg' => CommonStatus::getMsg($_code)];
  84. }
  85. // 校验未成年玩家限制
  86. $_url = $this->checkUnderageLimitOnTheHour();
  87. $_code = MemberStatus::NO_ERROR;
  88. $_data = [];
  89. if (!empty($_url)) {
  90. $_code = MemberStatus::LOGIN_IS_OUT;
  91. $_data['url'] = $_url;
  92. }
  93. return ['code' => $_code, 'msg' => MemberStatus::getMsg($_code), 'data' => $_data];
  94. }
  95. $_code = CommonStatus::NO_ERROR;
  96. return ['code' => $_code, 'msg' => CommonStatus::getMsg($_code)];
  97. }
  98. /**
  99. * 获取剩余体验时长和绑定手机url
  100. */
  101. public function getTimeLeft() {
  102. $_rdata = [
  103. 'time_left' => CommonConst::CONST_ZERO,
  104. 'bind_url' => ''
  105. ];
  106. $_game_auth = (new GameModel())->getIsAuthById($this->app_id);
  107. /* 不需要实名不做任何处理 */
  108. if (GameConst::GAME_IDENTIFY_IS_NO == $_game_auth) {
  109. return $_rdata;
  110. }
  111. if (empty($this->mem_id)) {
  112. /* 未登录返回空 */
  113. return $_rdata;
  114. }
  115. $_mem_model = new MemberModel();
  116. $_status = $_mem_model->getStatus($this->mem_id);
  117. if (MemConst::STATUS_TRY != $_status) {
  118. /* 非试玩玩家不需要提示绑定手机 */
  119. return $_rdata;
  120. }
  121. $_mobile = $_mem_model->getMobileById($this->mem_id);
  122. if (!empty($_mobile)) {
  123. /* 已绑定手机返回空 */
  124. return $_rdata;
  125. }
  126. $_param = [
  127. 'app_id' => $this->app_id,
  128. 'device_id' => $this->device_id,
  129. 'token' => $this->getToken()
  130. ];
  131. $_rdata = [
  132. 'time_left' => CommonConst::CONST_ZERO,
  133. 'bind_url' => IdentifyConst::getBindMobileUrl($_param)
  134. ];
  135. $_unnamed_limit = $this->identify_conf['unnamed']['limit_time']; //后台配置未实名试玩时长
  136. $_now_online_time = 0;
  137. $_mot_logic = new IdentifyMotLogic();
  138. $_mot_data = $_mot_logic->getInfoByMemId($this->mem_id);
  139. $_online_time = get_val($_mot_data, 'online_duration', CommonConst::CONST_ZERO);
  140. if ($_online_time >= $_now_online_time) {
  141. $_now_online_time = $_online_time;
  142. }
  143. if (!empty($this->device_id)) {
  144. $_dot_logic = new IdentifyDotLogic();
  145. $_dot_data = $_dot_logic->getInfoByDevice($this->device_id);
  146. $_online_time = get_val($_dot_data, 'online_duration', CommonConst::CONST_ZERO);
  147. if ($_online_time >= $_now_online_time) {
  148. $_now_online_time = $_online_time;
  149. }
  150. }
  151. $_diff_time = $_unnamed_limit - $_now_online_time;
  152. if ($_diff_time > CommonConst::CONST_ZERO) {
  153. $_rdata['time_left'] = ceil($_diff_time / CommonConst::CONST_MINUTE_SECONDS);
  154. }
  155. return $_rdata;
  156. }
  157. /**
  158. * 校验是否登陆或需要实名处理
  159. */
  160. public function checkLimit() {
  161. $_id_card = $this->getIdCard();
  162. /* 已实名 */
  163. if (!empty($_id_card)) {
  164. $_age = IdentifyUtils::getAgeById($_id_card);
  165. // 成年玩家不限制
  166. if ($_age >= 18) {
  167. return '';
  168. }
  169. // 校验未成年玩家限制
  170. return $this->checkUnderageLimit();
  171. }
  172. /* Modified by chenbingling BEGIN 2021/9/3 ISSUES:#15622 产品需求 心跳查询实名认证信息,有认证中数据不弹窗,并提交实名信息到cp*/
  173. /* 查询游实名认证中的数据则不弹窗 */
  174. $_identify_class = new Identify();
  175. $_in_progress_data = $_identify_class->getInProgressDataByMemApp($this->mem_id, $this->app_id);
  176. if (!empty($_in_progress_data)) {
  177. $_real_name = get_val($_in_progress_data, 'real_name', '');
  178. $_id_card = get_val($_in_progress_data, 'id_card', '');
  179. $_identify_class->updateIdentify($this->mem_id, 1, $_real_name, $_id_card, $this->app_id);
  180. return '';
  181. }
  182. /* END 2021/9/3 ISSUES:#15622 */
  183. /* 校验未实名限制 */
  184. // 校验设备限制
  185. $this->checkDeviceLimit();
  186. if (!empty($this->return_url)) {
  187. return $this->return_url;
  188. }
  189. // 校验玩家限制
  190. $this->checkMemLimit();
  191. if (!empty($this->return_url)) {
  192. return $this->return_url;
  193. }
  194. return $this->return_url;
  195. }
  196. /**
  197. * 校验设备限制
  198. */
  199. public function checkDeviceLimit() {
  200. $_app_id = $this->app_id;
  201. $_device_id = $this->device_id;
  202. $_mem_id = $this->mem_id;
  203. if (!empty($_device_id)) {
  204. $_dot_logic = new IdentifyDotLogic();
  205. $_dot_data = $_dot_logic->getInfoByDevice($_device_id);
  206. $_now_time = time();
  207. /* 在线时长 */
  208. $_online_time = get_val($_dot_data, 'online_duration', CommonConst::CONST_ZERO);
  209. $_limit_day = $this->identify_conf['unnamed']['expired_day']; //后台配置下次可玩间隔15天
  210. $_unnamed_limit = $this->identify_conf['unnamed']['limit_time']; //后台配置未实名试玩时长
  211. if (($_online_time >= $_unnamed_limit) || ($_dot_data['next_allow_time'] > $_now_time)) {
  212. /* 达到限制时长或者在限制登陆期间返回实名验证url */
  213. $_param = [
  214. 'app_id' => $_app_id,
  215. 'device_id' => $_device_id,
  216. 'token' => $this->getToken()
  217. ];
  218. $_identify_url = IdentifyConst::getIdentifyUrl($_param);
  219. if (!empty($_mem_id)) {
  220. /* 获取玩家是否已绑定手机 */
  221. $_mem_model = new MemberModel();
  222. $_mobile = $_mem_model->getMobileById($_mem_id);
  223. $_status = $_mem_model->getStatus($_mem_id);
  224. if (empty($_mobile) && MemConst::STATUS_TRY == $_status) {
  225. /* 试玩账号没有绑定手机才需要弹窗 */
  226. $_identify_url = IdentifyConst::getBindMobileUrl($_param);
  227. }
  228. }
  229. $this->return_url = $_identify_url;
  230. /* 设置下次可访问时间 */
  231. if (empty($_dot_data['next_allow_time'])) {
  232. $_dot_data['next_allow_time'] = $_now_time + ($_limit_day * CommonConst::CONST_DAY_SECONDS);
  233. $_dot_logic->updateByDevice($_dot_data, $_device_id);
  234. }
  235. /* 若调整了限制时间,则重置下次可访问时间 */
  236. if ($_unnamed_limit > $_online_time) {
  237. $_dot_data['next_allow_time'] = CommonConst::CONST_ZERO;
  238. $_dot_logic->updateByDevice($_dot_data, $_device_id);
  239. $this->return_url = '';
  240. }
  241. /* 若达到下次可访问时间,则重置在线时长和下次可访问时间 */
  242. if (!empty($_dot_data['next_allow_time']) && $_dot_data['next_allow_time'] <= $_now_time) {
  243. $_dot_data['online_duration'] = CommonConst::CONST_ZERO;
  244. $_dot_data['next_allow_time'] = CommonConst::CONST_ZERO;
  245. $_dot_logic->updateByDevice($_dot_data, $_device_id);
  246. $this->return_url = '';
  247. }
  248. }
  249. }
  250. return $this->return_url;
  251. }
  252. /**
  253. * 校验玩家限制
  254. */
  255. public function checkMemLimit() {
  256. $_mem_id = $this->mem_id;
  257. $_app_id = $this->app_id;
  258. $_device_id = $this->device_id;
  259. if (!empty($_mem_id)) {
  260. $_mot_logic = new IdentifyMotLogic();
  261. $_mot_data = $_mot_logic->getInfoByMemId($_mem_id);
  262. $_now_time = time();
  263. /* 在线时长 */
  264. $_online_time = get_val($_mot_data, 'online_duration', CommonConst::CONST_ZERO);
  265. $_limit_day = $this->identify_conf['unnamed']['expired_day']; //后台配置下次可玩间隔15天
  266. $_unnamed_limit = $this->identify_conf['unnamed']['limit_time']; //后台配置未实名试玩时长
  267. if (($_online_time >= $_unnamed_limit) || ($_mot_data['next_allow_time'] > $_now_time)) {
  268. /* 达到限制时长或者在限制登陆期间返回实名验证url */
  269. $_param = [
  270. 'app_id' => $_app_id,
  271. 'device_id' => $_device_id,
  272. 'token' => session_id()
  273. ];
  274. $_identify_url = IdentifyConst::getIdentifyUrl($_param);
  275. if (!empty($_mem_id)) {
  276. /* 获取玩家是否已绑定手机 */
  277. $_mem_model = new MemberModel();
  278. $_mobile = $_mem_model->getMobileById($_mem_id);
  279. if (empty($_mobile)) {
  280. $_identify_url = IdentifyConst::getBindMobileUrl($_param);
  281. }
  282. }
  283. $this->return_url = $_identify_url;
  284. /* 设置下次可访问时间 */
  285. if (empty($_mot_data['next_allow_time'])) {
  286. $_mot_data['next_allow_time'] = $_now_time + ($_limit_day * CommonConst::CONST_DAY_SECONDS);
  287. $_mot_logic->updateByMemId($_mot_data, $_mem_id);
  288. }
  289. /* 若调整了限制时间,则重置下次可访问时间 */
  290. if ($_unnamed_limit > $_online_time) {
  291. $_mot_data['next_allow_time'] = CommonConst::CONST_ZERO;
  292. $_mot_logic->updateByMemId($_mot_data, $_mem_id);
  293. $this->return_url = '';
  294. }
  295. /* 若达到下次可访问时间,则重置在线时长和下次可访问时间 */
  296. if (!empty($_mot_data['next_allow_time']) && $_mot_data['next_allow_time'] <= $_now_time) {
  297. $_mot_data['online_duration'] = CommonConst::CONST_ZERO;
  298. $_mot_data['next_allow_time'] = CommonConst::CONST_ZERO;
  299. $_mot_logic->updateByMemId($_mot_data, $_mem_id);
  300. $this->return_url = '';
  301. }
  302. }
  303. }
  304. return $this->return_url;
  305. }
  306. /**
  307. * 校验未成年玩家限制--新版本 未成年用户仅限在周五、周六、周日及法定节假日每日20:00-21:00登录游戏
  308. */
  309. public function checkUnderageLimit() {
  310. $_now_time = time();
  311. $_is_allow_login = (new HolidaySet())->isAllowLogin();
  312. if (true === $_is_allow_login) {
  313. /* 允许登陆的日子,需判断是否在允许登陆的时间 每日 20:00 - 21:00 */
  314. $_allow_start_time = $this->identify_conf['underage']['allow_start_time']; //后台配置获取,今日允许登陆开始时间
  315. $_allow_start_time_minute
  316. = $this->identify_conf['underage']['allow_start_time_minute']; //后台配置获取,今日允许登陆开始时间
  317. $_allow_end_time = $this->identify_conf['underage']['allow_end_time']; //后台配置获取,今日允许登陆结束时间
  318. $_allow_end_time_minute = $this->identify_conf['underage']['allow_end_time_minute']; //后台配置获取,今日允许登陆结束时间
  319. $_allow_start_time = mktime(
  320. $_allow_start_time, $_allow_start_time_minute, 0, date('m'), date('d'), date('Y')
  321. );
  322. $_allow_end_time = mktime($_allow_end_time, $_allow_end_time_minute, 0, date('m'), date('d'), date('Y'));
  323. $_allow_end_time -= CommonFunc::getHeartbeatTime(); /* 减去心跳间隔时间 */
  324. if ($_now_time > $_allow_start_time && $_now_time < $_allow_end_time) {
  325. return '';
  326. }
  327. }
  328. $_type = IdentifyConst::UNDERAGE_ALLOW_LOGIN_LIMIT;
  329. $_param = [
  330. 'app_id' => $this->app_id,
  331. 'token' => $this->getToken()
  332. ];
  333. $this->return_url = IdentifyConst::getUnderageLimitMsgUrl($_type, $_param);
  334. return $this->return_url;
  335. }
  336. /**
  337. * 校验未成年玩家限制--新版本 未成年用户仅限在周五、周六、周日及法定节假日每日20:00-21:00登录游戏
  338. */
  339. public function checkUnderageLimitOnTheHour() {
  340. $_now_time = time();
  341. $_is_allow_login = (new HolidaySet())->isAllowLogin();
  342. if (true === $_is_allow_login) {
  343. /* 允许登陆的日子,需判断是否在允许登陆的时间 每日 20:00 - 21:00 */
  344. $_allow_start_time = $this->identify_conf['underage']['allow_start_time']; //后台配置获取,今日允许登陆开始时间
  345. $_allow_start_time_minute
  346. = $this->identify_conf['underage']['allow_start_time_minute']; //后台配置获取,今日允许登陆开始时间
  347. $_allow_end_time = $this->identify_conf['underage']['allow_end_time']; //后台配置获取,今日允许登陆结束时间
  348. $_allow_end_time_minute = $this->identify_conf['underage']['allow_end_time_minute']; //后台配置获取,今日允许登陆结束时间
  349. $_allow_start_time = mktime(
  350. $_allow_start_time, $_allow_start_time_minute, 0, date('m'), date('d'), date('Y')
  351. );
  352. $_allow_end_time = mktime($_allow_end_time, $_allow_end_time_minute, 0, date('m'), date('d'), date('Y'));
  353. if ($_now_time > $_allow_start_time && $_now_time < $_allow_end_time) {
  354. return '';
  355. }
  356. }
  357. $_type = IdentifyConst::UNDERAGE_ALLOW_LOGIN_LIMIT;
  358. $_param = [
  359. 'app_id' => $this->app_id,
  360. 'token' => $this->getToken()
  361. ];
  362. $this->return_url = IdentifyConst::getUnderageLimitMsgUrl($_type, $_param);
  363. return $this->return_url;
  364. }
  365. /***
  366. * 统计时长
  367. */
  368. public function updateOnlineTime() {
  369. $_app_id = $this->app_id;
  370. $_mem_id = $this->mem_id;
  371. $_id_card = $this->id_card;
  372. $_device_id = $this->device_id;
  373. $_heartbeat_time = CommonFunc::getHeartbeatTime(); //系统设置心跳间隔,一个心跳时长
  374. $_now_time = time();
  375. $_heart_time_cache = HeartTimeCache::ins();
  376. $_last_heart_time = $_heart_time_cache->getLastHeartTime($_app_id, $_mem_id, $_device_id);
  377. $_heart_time_cache->setLastHeartTime($_now_time, $_app_id, $_mem_id, $_device_id);
  378. $_diff_time = $_now_time - $_last_heart_time;
  379. if ($_diff_time > ($_heartbeat_time + 10)) {
  380. /* 心跳间隔超过一个心跳时长认为是重新登陆的不增加统计时长 */
  381. return;
  382. }
  383. /*统计实名认证信息时长*/
  384. if (!empty($_id_card)) {
  385. (new IdentifyDayIdotLogic())->updateOnlineTimeByIdCard($_heartbeat_time, $_id_card, $_mem_id);
  386. (new IdentifyIdotLogic())->updateOnlineTimeByIdCard($_heartbeat_time, $_id_card);
  387. }
  388. /* 统计设备时长 */
  389. if (!empty($_device_id)) {
  390. (new IdentifyDayDotLogic())->updateOnlineTimeByDevice($_heartbeat_time, $_device_id, $_mem_id);
  391. if (empty($_id_card)) {
  392. /* 只有未实名的才需要累计设备时长 */
  393. (new IdentifyDotLogic())->updateOnlineTimeByDevice($_heartbeat_time, $_device_id);
  394. }
  395. }
  396. /* 统计玩家每日时长 */
  397. if (!empty($_mem_id)) {
  398. (new IdentifyDayMotLogic())->updateOnlineTimeByMemId($_heartbeat_time, $_mem_id);
  399. if (empty($_id_card)) {
  400. /* 只有未实名的才需要累计玩家时长 */
  401. (new IdentifyMotLogic())->updateOnlineTimeByMemId($_heartbeat_time, $_mem_id);
  402. }
  403. }
  404. }
  405. /**
  406. * 获取实名认证url
  407. */
  408. public function getIdentifyUrl() {
  409. $_app_id = $this->app_id;
  410. $_id_card = $this->id_card;
  411. $_device_id = $this->device_id;
  412. if (!empty($_id_card)) {
  413. return '';
  414. }
  415. $_mem_status = (new MemberModel())->getStatus($this->mem_id);
  416. if (MemConst::STATUS_TRY == $_mem_status) {
  417. /* 试玩用户不需要弹出实名 */
  418. return '';
  419. }
  420. $_param = [
  421. 'app_id' => $_app_id,
  422. 'device_id' => $_device_id,
  423. 'token' => $this->getToken()
  424. ];
  425. $_identify_url = IdentifyConst::getIdentifyUrl($_param);
  426. return $_identify_url;
  427. }
  428. /**
  429. * @return int
  430. */
  431. public function getAppId() {
  432. return $this->app_id;
  433. }
  434. /**
  435. * @param int $app_id
  436. */
  437. public function setAppId($app_id) {
  438. $this->app_id = $app_id;
  439. }
  440. /**
  441. * @return int
  442. */
  443. public function getMemId() {
  444. return $this->mem_id;
  445. }
  446. /**
  447. * @param int $mem_id
  448. */
  449. public function setMemId($mem_id) {
  450. $this->mem_id = $mem_id;
  451. }
  452. /**
  453. * @return string
  454. */
  455. public function getDeviceId() {
  456. return $this->device_id;
  457. }
  458. /**
  459. * @param string $device_id
  460. */
  461. public function setDeviceId($device_id) {
  462. if (empty($device_id)) {
  463. $device_id = $this->getHuoDeviceIdFromCookie();
  464. }
  465. $this->device_id = $device_id;
  466. }
  467. /**
  468. * @return string
  469. */
  470. public function getIdCard() {
  471. return $this->id_card;
  472. }
  473. /**
  474. * @param string $id_card
  475. */
  476. public function setIdCard($id_card = '') {
  477. if (empty($id_card) && !empty($this->mem_id)) {
  478. $id_card = (new IdentifyMemModel())->getIdCardByMemId($this->mem_id);
  479. }
  480. $this->id_card = $id_card;
  481. }
  482. /**
  483. * 从cookie获取一个自定义device_id
  484. */
  485. public function getHuoDeviceIdFromCookie() {
  486. $_device_id = $this->getSdkDeviceId();
  487. if (empty($_device_id)) {
  488. $_device_id = StrUtils::genOrderId(0, 0, $this->mem_id, 'huoh5');
  489. $this->setSdkDeviceId($_device_id);
  490. }
  491. return $_device_id;
  492. }
  493. /**
  494. * 设置永久标识作为 device_id
  495. *
  496. * @param string $device_id
  497. */
  498. public function setSdkDeviceId($device_id) {
  499. /* 过期时间设为100年 */
  500. $_expire = mktime(0, 0, 0, 1, 1, 2119);
  501. Cookie::set('HuoSdkDeviceId', $device_id, $_expire);
  502. }
  503. /**
  504. * 获取永久biaos
  505. */
  506. public function getSdkDeviceId() {
  507. return Cookie::get('HuoSdkDeviceId');
  508. }
  509. /**
  510. * @return string
  511. */
  512. public function getToken() {
  513. if (empty($this->token)) {
  514. return session_id();
  515. }
  516. return $this->token;
  517. }
  518. /**
  519. * @param string $token
  520. */
  521. public function setToken($token) {
  522. $this->token = $token;
  523. }
  524. }