1. 程式人生 > >App版本升級介面

App版本升級介面

版本升級表:

DROP TABLE IF EXISTS `version_upgrade`;
CREATE TABLE `version_upgrade` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `app_id` int(11) NOT NULL DEFAULT '0' COMMENT '客戶端id',
  `version_id` int(11) DEFAULT '0' COMMENT '大版本id',
  `version_mini` int(11) DEFAULT '0' COMMENT '小版本id',
  `version_code` varchar(11) DEFAULT NULL,
  `type` tinyint(1) DEFAULT NULL COMMENT '升級,不升級,強制升級',
  `apk_url` varchar(255) DEFAULT NULL,
  `upgrade_point` varchar(255) DEFAULT NULL COMMENT '升級提示',
  `status` tinyint(2) DEFAULT NULL,
  `create_time` int(11) DEFAULT NULL,
  `update_time` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

app資訊表:
DROP TABLE IF EXISTS `app`;
CREATE TABLE `app` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(10) NOT NULL,
  `is_encryption` tinyint(1) NOT NULL,
  `key` varchar(20) NOT NULL DEFAULT '0',
  `image_size` text,
  `create_time` int(11) NOT NULL COMMENT '建立時間',
  `update_time` int(11) NOT NULL COMMENT '更新時間',
  `status` tinyint(1) DEFAULT '1',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

通過app的版本資訊與伺服器資訊對比,看是否要進行版本升級
public function index(){
		$this->check();
		$versionUpgrade = $this->getversionUpgrade($this->app['id']);
		if($versionUpgrade){
			if($versionUpgrade['type'] && $this->params['version_id'] < $versionUpgrade['version_id']){
				$versionUpgrade['is_upload'] = $versionUpgrade['type'];
			}else{
				$versionUpgrade['is_upload'] = 0;
			}
			return Response::show(200,'版本升級資訊獲取成功',$versionUpgrade);
		}else{
			return Response::show(400,'版本升級資訊獲取失敗');
		}
	}	


check方法檢查app各項資訊:

public function check(){
		$this->params['app_id']		  = $appId 		 = isset($_POST['app_id']) ? $_POST['app_id']:'';
		$this->params['version_id']   = $versionId   = isset($_POST['version_id']) ? $_POST['version_id']:'';
		$this->params['version_mini'] = $versionMini = isset($_POST['version_mini']) ? $_POST['version_mini']:'';
		$this->params['did'] 		  = $did 		 = isset($_POST['did']) ? $_POST['did']:'';
		$this->params['encrypt_did']  = $encryptDid  = isset($_POST['encrypt_did']) ? $_POST['encrypt_did']:'';
		if(!is_numeric($appId) || !is_numeric($versionId)){
			return Response::show(401,'引數不合法');
		}
		//判斷app是否需要加密
		
		$this->app = $this->getApp($appId);
		if(!$this->app){
			return Response::show(402,'app_id不存在');
		}
		if($this->app['is_encryption'] && $encryptDid != md5($did.$this->app['key'])){
			return Response::show(403,'沒有許可權');
		}
	}
	public function getApp($id){
		$sql = "SELECT * FROM `app` WHERE id = ".$id." AND status = 1 limit 1";
		$connect = Db::getInstance()->connect();
		$result = mysql_query($sql,$connect);
		return mysql_fetch_assoc($result);
	}

	public function getversionUpgrade($appId){
		$sql = "SELECT * FROM `version_upgrade` WHERE app_id = ".$appId." AND status = 1 limit 1";
		$connect = Db::getInstance()->connect();
		$result = mysql_query($sql,$connect);
		return mysql_fetch_assoc($result);
	}

以上內容有參考暮課網視訊教程《PHP介面開發》