[PHP开发APP接口]①④--版本升级接口演示二

修改代码

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);
    }
$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{
            Response::show(400,'版本信息获取失败!');
        }

common.php

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(402, '没有权限');
        }

    }


    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);
    }

}

init.php

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 {
                //is_upload为0表示不用升级
                $versionUpgrade['is_upload'] = 0;
            }
            return Response::show(200, '版本升级信息获取成功!', $versionUpgrade);
        } else {
            Response::show(400, '版本信息获取失败!');
        }
    }
}

$init = new Init();
$init->index();

?>

test.html


设备号:
版本号:
小版本号:
APP类型:
encrypt_did:

response.php

 $code,
            'message' => $message,
            '$data' => $data
        );

        if ($type == 'json') {
            self::json($code, $message, $data);
            ecit;
        } else if ($type == 'array') {
            var_dump($result);
        } else if ($type == 'xml') {
            self::xmlEncode($code, $message, $data);
        } else {
            //TODO
        }
    }


    public static function json($code, $message = '', $data = array())
    {
        if (!is_numeric($code)) {
            return "";
        } else {
            $result = array(
                'code' => $code,
                'message' => $message,
                'data' => $data
            );
            $str = json_encode($result);
            echo preg_replace("#\\\u([0-9a-f]{4})#ie", "iconv('UCS-2BE', 'UTF-8', pack('H4', '\\1'))", $str);
            exit;
        }
    }

    public static function xmlEncode($code, $message, $data = array())
    {
        if (!is_numeric($code)) {
            return "";
        }

        $result = array(
            'code' => $code,
            'message' => $message,
            'data' => $data,
        );

        header("Content-Type:text/xml");//指定页面类型
        $xml = "";
        $xml .= "";
        $xml .= self::xmlToEncode($result);
        $xml .= "";
        echo $xml;
    }

    public static function xmlToEncode($data)
    {
        $xml = $attr = "";
        foreach ($data as $key => $value) {
            if (is_numeric($key)) {
                $attr = "id='{$key}'";
                $key = "item ";
            }
            $xml .= "<{$key}{$attr}>";
            $xml .= is_array($value) ? self::xmlToEncode($value) : $value;
            $xml .= "";
        }
        return $xml;
    }
}

?>
Paste_Image.png
[PHP开发APP接口]①④--版本升级接口演示二_第1张图片
Paste_Image.png
Paste_Image.png

你可能感兴趣的:([PHP开发APP接口]①④--版本升级接口演示二)