* @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; } }