Today's notes are mainly to record the last one of the key points of knowledge, app client version upgrade interface development.
The development of the app is mainly updated by great and divine users, and the updated process should look like this:
Turn on app--request Initialize interface init.php--detect need to update---no--home
---yes--update
When initializing the interface, the client is required to send several data:
APP_ID Client ID, such as: 1, Android phone 2,iphone mobile phone
VERSION_ID Large version number ID
Version_mini minor version number ID
Did user client information (this data is obtained by the client engineer)
Encrypt_did did encrypted string (did plus key in app device data table, then MD5)
<!doctype html>
forgot to say that a database table is needed, two tables are required here. A table that records the updated version information, records the device ID, version number information, and so on. Another table is the information of recorded devices, such as Android phone information, Android pad information and so on, the version information table has a foreign key app_id, associated with the device information table of the primary key.
<?php/* Equipment Information table, which records the information of various clients create table if not EXISTS ' app_table ' ( ' app_id ' smallint (6) not NULL AUTO_INCREMENT COMMENT ' primary key ', ' name ' varchar ( NOT NULL COMMENT ' device name ', ' is_encryption ' tinyint (1) NOT NULL COMMENT ' encryption ', ' key ' varchar ( NOT NULL COMMENT ' encrypt key ', ' image_size ' text NOT NULL COMMENT ' Store ', ' create_time ' int according to JSON ( One) NOT NULL COMMENT ' Add time ', ' Update_time ' int (11) NOT NULL COMMENT ' modified time ', ' status ' tinyint (1) not null comment ' status 1 normal 0 delete ', primary key (' app_id ') ) engine=myisam default charset=utf8 comment= ' app device table ' auto_ increment=2 ; version upgrade information table with various versions of information create table if not exists ' Version_upgrade ' ( ' ID ' smallint (4) NOT NULL AUTO_INCREMENT COMMENT ' primary key ', ' app_id ' smallint (4) NOT NULL COMMENT ' Client device ID ', ' version_id ' smallint (4) NOT NULL COMMENT ' Large version ID ', ' Version_mini ' mediumint (8) NOT NULL COMMENT ' minor version ', ' Version_code ' varchar (Ten) NOT NULL COMMENT ' version 1.2 ', ' TyPE ' tinyint (4) NOT NULL COMMENT ' Whether upgrade 1 is 0 no ', ' apk_ URL ' varchar (255) NOT NULL COMMENT ' Download link address ', ' Upgrade_point ' varchar (255) NOT NULL COMMENT ' Upgrade tips ', ' Status ' tinyint (4) NOT NULL, ' Create_time ' int ( One) NOT NULL COMMENT ' Add time ', ' Update_time ' int (11) NOT NULL COMMENT ' Modified time ', primary key (' id ') ) engine=myisam default charset=utf8 comment= ' software upgrade information sheet ' Auto_increment=2 ;*/?>
creates a base class for processing the requested init.php, and makes various judgments in the method check () of the underlying class, such as whether the client device exists, whether encryption is required, whether there are permission updates, and so on.
<?php /************************************* version Upgrade interface Development Basic class * Learn PHP small ant * Blog http://my.oschina.net/ woshixiaomayi/blog*************************************///the interface response class//code content written before loading please refer to http://my.oschina.net/ Woshixiaomayi/blog/517384require_once ('./response.php ');//The DB Class/code content written before loading please refer to http://my.oschina.net/ Woshixiaomayi/blog/518295require_once ('./db.php '); Class common{//post submitted data public $param;// The information details of the client device public $app;//confirm the device version information, permissions, etc. public function check () {//post submitted data consolidation, one line is too long, separate to write \ (^o^)/ ~ $app _id=isset ($_post[' app_id ') "$_post[' app_id ']:"; $this->param[' app_id ']= $app _id; $version _id=isset ($_ post[' version_id ')? $_post[' version_id ': '; $this->param[' version_id ']= $version _id; $did =isset ($_post[' did ') $_post[' did ']: "; $this->param[' did ']= $did; $version _mini=isset ($_post[' Version_mini '])? $_post[' Version_ Mini ']: '; $this->param[' Version_mini ']= $version _mini $encrypt _did=isset ($_post[' Encrypt_did '])? $_post[' Encrypt_did ': '; $this->param[' Encrypt_Did ']= $encrypt _did;//to determine if the app_id and version_id data types are correct if (!is_numeric ($app _id) or !is_numeric ($version _id)) {return response::show (400, ' data not valid ');} Determine if encryption is required to handle $this->app= $this->getapp (), if (! $this->app) {return response::show (400, ' the app does not exist ');} /* To determine whether there is permission, the way to determine the permissions, 1, whether the need to encrypt processing 2, sent over Encrypt_did and the server generated values consistent */if ($this->app[' is_encryption '] & & $this->param[' Encrypt_did '] != md5 ($did . $this->app[' key ')) {return response::show (405, ' You have no permissions ');}} Get the device Information Public function getapp () {///These days this paragraph has been written rotten, do not write comments try{$connect =db::getinstance () Connect ();} catch (exception $e) {//error message returned to App Return response::show (' Mysql not connect ');} $sql = "select * from app_table where app_id=". $this->param[' app_id '; $result =mysql_ Query ($sql, $connect); Return mysql_fetch_assoc ($result);}} ?>
Create the init.php and send the data to this script to do the processing.
<?php/********************************** Single-case model development DB Library * PHP small ant * Blog http://my.oschina.net/woshixiaomayi/blog****** Load base class, make version judgment Require_once ('./common.php '); class Init extends Common{public function index () {//This method $this->check () in the base class;}} $obj =new Init (); $obj->index ();?>
Processing the request data sent by the client, basically finished, and tomorrow, the whole version of the upgrade function finished, estimating the content of the app interface development is over. Learning this also took a lot of time (~ ̄▽ ̄) ~
Small Ant Learning App Interface Development (9)--app Version Upgrade interface Method--processing the request data sent by the client