123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- <?php
- /**
- * Gamepack.php UTF-8
- * 分包处理
- *
- * @date : 2017/11/30 15:19
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huo\controller\game;
- use huo\controller\common\Base;
- use huo\controller\request\Request;
- use huolib\status\CommonStatus;
- class Gamepack extends Base {
- private $agentgame = '';
- private $pinyin = '';
- private $prj_id = 0;
- private $image_url = '';
- private $redirect_url = '';
- private $down_url = '';
- private $app_id = 0;
- private $agent_id = 0;
- private $mac_cnt = 3;
- private $system = 3;/* 3 android 4 ios 5 h5 */
- private $disk_num = '';
- private $ver_id = 0;
- /**
- * Gamepack constructor.
- *
- * @param int $app_id
- * @param int $agent_id
- * @param string $pinyin
- * @param string $agentgame
- * @param int $disk_num
- * @param string $image
- * @param string $redirect_url
- * @param string $ipa_url
- */
- function __construct(
- $app_id,
- $agent_id = 0,
- $pinyin = '',
- $agentgame = '',
- $disk_num = 0,
- $image = '',
- $redirect_url = '',
- $ipa_url = ''
- ) {
- $this->pinyin = $pinyin;
- $this->agentgame = $agentgame;
- $this->prj_id = uniqid(config('prj_id'));
- $this->image_url = $image;
- $this->redirect_url = $redirect_url;
- $this->down_url = $ipa_url;
- $this->app_id = $app_id;
- $this->agent_id = $agent_id;
- $this->disk_num = $disk_num;
- }
- /**
- * @return array
- */
- public function getErrorMsg() {
- $_arr = [
- '-6' => lang('forbidden'),
- '-5' => lang('not_exist'),
- '-4' => lang('validate_error'),
- '-3' => lang('param error'),
- '-2' => lang('pack_error'),
- '-1' => lang('no_auth'),
- '2' => lang('pack_exist'),
- '1' => lang('pack success'),
- '0' => lang('SUCCESS'),
- ];
- return $_arr;
- }
- /**
- * 打包
- *
- * @return array|bool
- */
- function pack() {
- if (empty($this->app_id)) {
- return $this->huoError('400', lang('param error'));
- }
- if (!empty($this->ver_id)) {
- $this->pinyin = $this->pinyin.DS.$this->ver_id;
- }
- $_opt = md5(md5($this->pinyin.$this->agentgame).'resub');
- $_initial = base64_encode($this->pinyin);
- $_agent_game = base64_encode($this->agentgame);
- $_opt = base64_encode($_opt);
- $_data_string = array(
- 'p' => $_initial,
- 'a' => $_agent_game,
- 'o' => $_opt,
- 'image' => $this->image_url,
- 'rurl' => $this->redirect_url,
- 'ipa_url' => $this->down_url,
- );
- $_data_string = json_encode($_data_string);
- if ($_SERVER['SERVER_ADDR'] == '120.25.152.57') {
- $_url = str_replace('/sdkgame/', '', DOWNSITE)."/sub.php";
- } else {
- $_url = DOWNIP."/sub.php";
- }
- $_cnt = 0;
- $_return_content = -100;
- while (1) {
- $_return_content = base64_decode(Request::httpJsonpost($_url, $_data_string));
- if (0 < $_return_content || $this->mac_cnt == $_cnt) {
- break;
- }
- $_cnt++;
- }
- if (3 == $this->system) {
- $_url = $this->pinyin.DS.$this->agentgame.'.apk';
- } elseif (4 == $this->system) {
- $_url = $this->pinyin.DS.$this->agentgame.'.plist';
- }
- if (is_numeric($_return_content)) {
- $_msg_arr = $this->getErrorMsg();
- $_data = null;
- if (1 == $_return_content) {
- $_data = ['url' => $_url];
- }
- $_code = $_return_content;
- $_msg = $_msg_arr["$_return_content"];
- return $this->huoError($_code, $_msg, $_data);
- }
- $_data = json_decode($_return_content, true);
- if (is_array($_data)) {
- $_data['url'] = $_url;
- $_code = CommonStatus::NO_ERROR;
- return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_data);
- } else {
- $_code = CommonStatus::INNER_ERROR;
- return $this->huoError($_code, CommonStatus::getMsg($_code));
- }
- }
- /**
- * @return string
- */
- public function getVerId() {
- return $this->ver_id;
- }
- /**
- * @param int $ver_id
- */
- public function setVerId($ver_id) {
- $this->ver_id = $ver_id;
- }
- /**
- * @return string
- */
- public function getAgentgame() {
- return $this->agentgame;
- }
- /**
- * @param string $agentgame
- */
- public function setAgentgame($agentgame) {
- $this->agentgame = $agentgame;
- }
- /**
- * @return string
- */
- public function getPinyin() {
- return $this->pinyin;
- }
- /**
- * @param string $pinyin
- */
- public function setPinyin($pinyin) {
- $this->pinyin = $pinyin;
- }
- /**
- * @return int|string
- */
- public function getPrjId() {
- return $this->prj_id;
- }
- /**
- * @param int|string $prj_id
- */
- public function setPrjId($prj_id) {
- $this->prj_id = $prj_id;
- }
- /**
- * @return string
- */
- public function getImageUrl() {
- return $this->image_url;
- }
- /**
- * @param string $image_url
- */
- public function setImageUrl($image_url) {
- $this->image_url = $image_url;
- }
- /**
- * @return string
- */
- public function getRedirectUrl() {
- return $this->redirect_url;
- }
- /**
- * @param string $redirect_url
- */
- public function setRedirectUrl($redirect_url) {
- $this->redirect_url = $redirect_url;
- }
- /**
- * @return string
- */
- public function getDownUrl() {
- return $this->down_url;
- }
- /**
- * @param string $down_url
- */
- public function setDownUrl($down_url) {
- $this->down_url = $down_url;
- }
- /**
- * @return int
- */
- public function getAppId() {
- return $this->app_id;
- }
- /**
- * @param int $app_id
- */
- public function setAppId($app_id) {
- $this->app_id = $app_id;
- }
- /**
- * @return int
- */
- public function getAgentId() {
- return $this->agent_id;
- }
- /**
- * @param int $agent_id
- */
- public function setAgentId($agent_id) {
- $this->agent_id = $agent_id;
- }
- /**
- * @return int
- */
- public function getMacCnt() {
- return $this->mac_cnt;
- }
- /**
- * @param int $mac_cnt
- */
- public function setMacCnt($mac_cnt) {
- $this->mac_cnt = $mac_cnt;
- }
- /**
- * @return int
- */
- public function getSystem() {
- return $this->system;
- }
- /**
- * @param int $system
- */
- public function setSystem($system) {
- $this->system = $system;
- }
- /**
- * @return int|string
- */
- public function getDiskNum() {
- return $this->disk_num;
- }
- /**
- * @param int|string $disk_num
- */
- public function setDiskNum($disk_num) {
- $this->disk_num = $disk_num;
- }
- }
|