App版本升级接口

  • Post author:
  • Post category:其他


版本升级表:

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接口开发》



版权声明:本文为fishermanmax原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。