Gamepack.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <?php
  2. /**
  3. * Gamepack.php UTF-8
  4. * 分包处理
  5. *
  6. * @date : 2017/11/30 15:19
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\controller\game;
  13. use huo\controller\common\Base;
  14. use huo\controller\request\Request;
  15. use huolib\status\CommonStatus;
  16. class Gamepack extends Base {
  17. private $agentgame = '';
  18. private $pinyin = '';
  19. private $prj_id = 0;
  20. private $image_url = '';
  21. private $redirect_url = '';
  22. private $down_url = '';
  23. private $app_id = 0;
  24. private $agent_id = 0;
  25. private $mac_cnt = 3;
  26. private $system = 3;/* 3 android 4 ios 5 h5 */
  27. private $disk_num = '';
  28. private $ver_id = 0;
  29. /**
  30. * Gamepack constructor.
  31. *
  32. * @param int $app_id
  33. * @param int $agent_id
  34. * @param string $pinyin
  35. * @param string $agentgame
  36. * @param int $disk_num
  37. * @param string $image
  38. * @param string $redirect_url
  39. * @param string $ipa_url
  40. */
  41. function __construct(
  42. $app_id,
  43. $agent_id = 0,
  44. $pinyin = '',
  45. $agentgame = '',
  46. $disk_num = 0,
  47. $image = '',
  48. $redirect_url = '',
  49. $ipa_url = ''
  50. ) {
  51. $this->pinyin = $pinyin;
  52. $this->agentgame = $agentgame;
  53. $this->prj_id = uniqid(config('prj_id'));
  54. $this->image_url = $image;
  55. $this->redirect_url = $redirect_url;
  56. $this->down_url = $ipa_url;
  57. $this->app_id = $app_id;
  58. $this->agent_id = $agent_id;
  59. $this->disk_num = $disk_num;
  60. }
  61. /**
  62. * @return array
  63. */
  64. public function getErrorMsg() {
  65. $_arr = [
  66. '-6' => lang('forbidden'),
  67. '-5' => lang('not_exist'),
  68. '-4' => lang('validate_error'),
  69. '-3' => lang('param error'),
  70. '-2' => lang('pack_error'),
  71. '-1' => lang('no_auth'),
  72. '2' => lang('pack_exist'),
  73. '1' => lang('pack success'),
  74. '0' => lang('SUCCESS'),
  75. ];
  76. return $_arr;
  77. }
  78. /**
  79. * 打包
  80. *
  81. * @return array|bool
  82. */
  83. function pack() {
  84. if (empty($this->app_id)) {
  85. return $this->huoError('400', lang('param error'));
  86. }
  87. if (!empty($this->ver_id)) {
  88. $this->pinyin = $this->pinyin.DS.$this->ver_id;
  89. }
  90. $_opt = md5(md5($this->pinyin.$this->agentgame).'resub');
  91. $_initial = base64_encode($this->pinyin);
  92. $_agent_game = base64_encode($this->agentgame);
  93. $_opt = base64_encode($_opt);
  94. $_data_string = array(
  95. 'p' => $_initial,
  96. 'a' => $_agent_game,
  97. 'o' => $_opt,
  98. 'image' => $this->image_url,
  99. 'rurl' => $this->redirect_url,
  100. 'ipa_url' => $this->down_url,
  101. );
  102. $_data_string = json_encode($_data_string);
  103. if ($_SERVER['SERVER_ADDR'] == '120.25.152.57') {
  104. $_url = str_replace('/sdkgame/', '', DOWNSITE)."/sub.php";
  105. } else {
  106. $_url = DOWNIP."/sub.php";
  107. }
  108. $_cnt = 0;
  109. $_return_content = -100;
  110. while (1) {
  111. $_return_content = base64_decode(Request::httpJsonpost($_url, $_data_string));
  112. if (0 < $_return_content || $this->mac_cnt == $_cnt) {
  113. break;
  114. }
  115. $_cnt++;
  116. }
  117. if (3 == $this->system) {
  118. $_url = $this->pinyin.DS.$this->agentgame.'.apk';
  119. } elseif (4 == $this->system) {
  120. $_url = $this->pinyin.DS.$this->agentgame.'.plist';
  121. }
  122. if (is_numeric($_return_content)) {
  123. $_msg_arr = $this->getErrorMsg();
  124. $_data = null;
  125. if (1 == $_return_content) {
  126. $_data = ['url' => $_url];
  127. }
  128. $_code = $_return_content;
  129. $_msg = $_msg_arr["$_return_content"];
  130. return $this->huoError($_code, $_msg, $_data);
  131. }
  132. $_data = json_decode($_return_content, true);
  133. if (is_array($_data)) {
  134. $_data['url'] = $_url;
  135. $_code = CommonStatus::NO_ERROR;
  136. return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_data);
  137. } else {
  138. $_code = CommonStatus::INNER_ERROR;
  139. return $this->huoError($_code, CommonStatus::getMsg($_code));
  140. }
  141. }
  142. /**
  143. * @return string
  144. */
  145. public function getVerId() {
  146. return $this->ver_id;
  147. }
  148. /**
  149. * @param int $ver_id
  150. */
  151. public function setVerId($ver_id) {
  152. $this->ver_id = $ver_id;
  153. }
  154. /**
  155. * @return string
  156. */
  157. public function getAgentgame() {
  158. return $this->agentgame;
  159. }
  160. /**
  161. * @param string $agentgame
  162. */
  163. public function setAgentgame($agentgame) {
  164. $this->agentgame = $agentgame;
  165. }
  166. /**
  167. * @return string
  168. */
  169. public function getPinyin() {
  170. return $this->pinyin;
  171. }
  172. /**
  173. * @param string $pinyin
  174. */
  175. public function setPinyin($pinyin) {
  176. $this->pinyin = $pinyin;
  177. }
  178. /**
  179. * @return int|string
  180. */
  181. public function getPrjId() {
  182. return $this->prj_id;
  183. }
  184. /**
  185. * @param int|string $prj_id
  186. */
  187. public function setPrjId($prj_id) {
  188. $this->prj_id = $prj_id;
  189. }
  190. /**
  191. * @return string
  192. */
  193. public function getImageUrl() {
  194. return $this->image_url;
  195. }
  196. /**
  197. * @param string $image_url
  198. */
  199. public function setImageUrl($image_url) {
  200. $this->image_url = $image_url;
  201. }
  202. /**
  203. * @return string
  204. */
  205. public function getRedirectUrl() {
  206. return $this->redirect_url;
  207. }
  208. /**
  209. * @param string $redirect_url
  210. */
  211. public function setRedirectUrl($redirect_url) {
  212. $this->redirect_url = $redirect_url;
  213. }
  214. /**
  215. * @return string
  216. */
  217. public function getDownUrl() {
  218. return $this->down_url;
  219. }
  220. /**
  221. * @param string $down_url
  222. */
  223. public function setDownUrl($down_url) {
  224. $this->down_url = $down_url;
  225. }
  226. /**
  227. * @return int
  228. */
  229. public function getAppId() {
  230. return $this->app_id;
  231. }
  232. /**
  233. * @param int $app_id
  234. */
  235. public function setAppId($app_id) {
  236. $this->app_id = $app_id;
  237. }
  238. /**
  239. * @return int
  240. */
  241. public function getAgentId() {
  242. return $this->agent_id;
  243. }
  244. /**
  245. * @param int $agent_id
  246. */
  247. public function setAgentId($agent_id) {
  248. $this->agent_id = $agent_id;
  249. }
  250. /**
  251. * @return int
  252. */
  253. public function getMacCnt() {
  254. return $this->mac_cnt;
  255. }
  256. /**
  257. * @param int $mac_cnt
  258. */
  259. public function setMacCnt($mac_cnt) {
  260. $this->mac_cnt = $mac_cnt;
  261. }
  262. /**
  263. * @return int
  264. */
  265. public function getSystem() {
  266. return $this->system;
  267. }
  268. /**
  269. * @param int $system
  270. */
  271. public function setSystem($system) {
  272. $this->system = $system;
  273. }
  274. /**
  275. * @return int|string
  276. */
  277. public function getDiskNum() {
  278. return $this->disk_num;
  279. }
  280. /**
  281. * @param int|string $disk_num
  282. */
  283. public function setDiskNum($disk_num) {
  284. $this->disk_num = $disk_num;
  285. }
  286. }