CheckUpdate.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. /* * **************************************************
  3. * 此代码为员工在公司工作期间创作.
  4. * 使用权和所有权归属于公司和员工共有.
  5. * 收益的权利归属于公司.
  6. * ——石家庄龙游科技有限公司
  7. * ************************************************** */
  8. namespace loyalsoft;
  9. include_once __DIR__ . '/../../main.php';
  10. class UpdateRetInfo {
  11. public $err = 0;
  12. public $msg = "";
  13. public $newVer = "";
  14. public $cdn = "";
  15. /**
  16. * @var string 整包更新地址
  17. */
  18. public $fullDownloadPage = "";
  19. /**
  20. * @var \sm_clientVersionHistory 版本信息
  21. */
  22. public $versionInfo = null;
  23. }
  24. /**
  25. * 检查更新(基于和王解的update模块的约定)
  26. * @author gwang
  27. * @version 1.0.0 Created by wanggangzero at 2020.4.27 13:48:33.
  28. */
  29. class CheckUpdate {
  30. /**
  31. * 打印消息并且停止游戏
  32. */
  33. const HaltWithMsg = false;
  34. const Md5_file = "UpdateFile";
  35. static function CDN_Root() {
  36. return match (PLAT) {
  37. default => "https://loyalsoft.oss-cn-shanghai.aliyuncs.com/ylsj/Res/" # 外网CDN
  38. };
  39. }
  40. /**
  41. * 检查客户端版本是否需要强制更新
  42. * @param Req $req
  43. * @return int ErrCode
  44. */
  45. public static function Check() {
  46. $clientVer = self::GetClientVersion(); # 客户端基带版本号
  47. $platform = self::GetClientPlatform(); # 客户端平台(安卓/IOS)
  48. $ret = new UpdateRetInfo(); # 返回值
  49. $url = self::CDN_Root() . self::Md5_file . $platform . ".json"; # 资源文件MD5列表
  50. $lisJson = HttpUtil::makeRequest($url, array(), array(), array(), "get"); # 取CDN上版本列表
  51. if (isset($lisJson["result"]) && $lisJson["result"]) {
  52. $fileList = JsonUtil::decode($lisJson["msg"]);
  53. $newVer = $fileList->Version; # 取出最新版本号
  54. $channel = self::GetClientChannel(); # 取出客户端的渠道字符串
  55. $ret->versionInfo = GameConfig::clientVersionHistory_getItem($newVer);
  56. $ret->newVer = $newVer;
  57. $ret->cdn = self::CDN_Root();
  58. $ret->fullDownloadPage = self::GetFullDownloadPage($channel);
  59. if (self::HaltWithMsg # # 显示消息并且退出游戏
  60. ) {
  61. $ret->msg = "sorry, x点到y服务暂停.";
  62. $ret->err = ErrCode::clientPrintMsg_Halt;
  63. } else
  64. if ($clientVer < 22 # 临时代码 2021.8.20 后面更新的时候需要注释掉
  65. // || ($newVer - $clientVer) >= 10 # # 版本号差异大于10=>整包更
  66. ) {
  67. $ret->err = ErrCode::clientversionlow_err; # 返回错误码,强制更新1
  68. $ret->msg = "游戏已经发布新版本,只有更新才能进入游戏。是否立即更新?";
  69. } else if (($newVer - $clientVer) > 0) { # # 修订版本号不一致, 提示更新
  70. $ret->err = ErrCode::clientnewversion_msg;
  71. $ret->msg = "需要更新部分资源文件,是否立即更新?";
  72. } else {
  73. $ret->err = ErrCode::ok; # 平安无事
  74. $ret->msg = "平安无事";
  75. }
  76. } else { # 检查更新失败
  77. $ret->err = 1031;
  78. $ret->msg = "检查更新失败!";
  79. }
  80. return $ret; # 返回
  81. }
  82. /**
  83. * 读取参数中的客户端版本
  84. * @return int
  85. */
  86. static function GetClientVersion() {
  87. $valueMap = query_paras(); // array
  88. // $valueMap = array('clientVer' => 22, 'plat' => 'Android', 'channel' => 'TapTap');
  89. if (!is_array($valueMap)) {
  90. exit("无参数");
  91. }
  92. $clientVer = "";
  93. if (isset($valueMap["clientVer"])) {
  94. $clientVer = urldecode($valueMap['clientVer']);
  95. } else {
  96. exit("缺少参数 'clientVer'!");
  97. }
  98. return intval($clientVer);
  99. }
  100. /**
  101. * 读取参数中的客户端平台(Android/IOS)
  102. * @return string
  103. */
  104. static function GetClientPlatform() {
  105. $valueMap = query_paras(); // array
  106. // $valueMap = array('clientVer' => 22, 'plat' => 'Android', 'channel' => 'TapTap');
  107. if (!is_array($valueMap)) {
  108. exit("无参数");
  109. }
  110. $plat = "";
  111. if (isset($valueMap["plat"])) {
  112. $plat = urldecode($valueMap['plat']);
  113. } else {
  114. exit("缺少参数 'plat'!");
  115. }
  116. return $plat;
  117. }
  118. /**
  119. * 读取参数中的客户端渠道(Taptap/Apple/yyb/UC/huawei/xiaomi/vivo/oppo...)
  120. * @return string
  121. */
  122. static function GetClientChannel() {
  123. $valueMap = query_paras(); // array
  124. // $valueMap = array('clientVer' => 22, 'plat' => 'Android', 'channel' => 'TapTap');
  125. if (!is_array($valueMap)) {
  126. exit("无参数");
  127. }
  128. $plat = "";
  129. if (isset($valueMap["channel"])) {
  130. $plat = urldecode($valueMap['channel']);
  131. } else {
  132. exit("缺少参数 'channel'!");
  133. }
  134. return $plat;
  135. }
  136. /**
  137. * 获取对应渠道的整包下载地址
  138. * @param type $channel
  139. * @return string
  140. */
  141. static function GetFullDownloadPage($channel) {
  142. $url = "https://loyalsoft.oss-cn-shanghai.aliyuncs.com/ylsj/and/com.loyalsoft.ylsj-50.apk"; # taptap
  143. switch ($channel) {
  144. case "yyb";
  145. $url = "https://loyalsoft.oss-cn-shanghai.aliyuncs.com/ylsj/and_yyb/com.tencent.tmgp.ylsjtx_59.apk"; # 腾讯
  146. break;
  147. default :
  148. $url = "https://www.taptap.com/developer/221344"; # taptap测试服
  149. break;
  150. }
  151. return $url;
  152. }
  153. }
  154. echo(JsonUtil::encode(CheckUpdate::Check())); # 打印json给客户端