PHP開発APPインタフェース学習ノートとまとめ-APPインタフェース例[6]バージョンアップインタフェース開発
14473 ワード
appが暗号化する必要があるかどうかを判定する:appテーブルのstatusフィールドによって、暗号化された文字列はappテーブルのkeyフィールドであると判定する.
取得したクライアントとサーバ側(データベーステーブルの対応するフィールド)のバージョン番号が一致しない場合、data['is_upload']=1に戻ってアップグレードするかどうかをプロンプトします.一致するとdata['is_upload']=0に戻り、アップグレードを要求しません.
common.phpにおけるgetAppメソッドは,キャッシュ(静的/Redisなど)を追加することができる.
common.php処理インタフェースパブリックビジネス
init.php処理バージョンのアップグレード
init.htmlテストインタフェース
取得したクライアントとサーバ側(データベーステーブルの対応するフィールド)のバージョン番号が一致しない場合、data['is_upload']=1に戻ってアップグレードするかどうかをプロンプトします.一致するとdata['is_upload']=0に戻り、アップグレードを要求しません.
common.phpにおけるgetAppメソッドは,キャッシュ(静的/Redisなど)を追加することができる.
common.php処理インタフェースパブリックビジネス
<?php
/**
*
*/
require_once('./response.php');
require_once('./db.php');
class Common {
public $params;
public $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);
}
/**
*
* @param string $imageUrl
* @param string $size
*/
public function setImage($imageUrl, $size) {
if(!$imageUrl) {
return '';
}
if(!$size) {
return $imageUrl;
}
$type = substr($imageUrl, strrpos($imageUrl, '.'));
if(!$type) {
return '';
}
$path = substr($imageUrl, 0, strrpos($imageUrl, '.'));
return $path . '_' . $size . $type;
}
}
init.php処理バージョンのアップグレード
<?php
require_once('./common.php');
class Init extends Common {
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, ' ');
}
}
}
$init = new Init();
$init->index();
init.htmlテストインタフェース
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action="init.php" method="post">
APP :<input type="text" name='app_id'>
:<input type="text" name='version_id'>
<input type="submit" value=' '>
</form>
</body>
</html>