Home Backend Development PHP Tutorial Use the Appcan client to automatically update the PHP version number (full)_php example

Use the Appcan client to automatically update the PHP version number (full)_php example

May 16, 2016 pm 08:09 PM

During the project development process, I encountered automatic updates on the app side. I consulted relevant information and sorted out the method for the Appcan client to automatically update the PHP version number. The specific code is explained below.

Server files: update.php, version.php, version.xml

update.php content:

PHP

<&#63;php
define('CIN', true);
$oldver = $_REQUEST['ver'];//客户端传过来的版本号
$platform = $_REQUEST['platform'];//客户端的平台
$info = simplexml_load_file('version.xml');
$iphone_filename=$info->news['iphone_filename']; //iphone下载文件
$android_filename=$info->news['android_filename']; //androiad下载文件
$version=$info->news['version']; //版本号
if ($version>$oldver)
{
  switch ($platform)
  {
    case "0"://iphone
      echo "<&#63;xml version=\"1.0\" encoding=\"utf-8\"&#63;>";
      echo "<results>";
      echo "<updateFileName>i2ty</updateFileName>";//客户端名字
      echo "<updateFileUrl>itunesURL</updateFileUrl>";//返回给客户端的下载地址
      echo "<fileSize>0</fileSize>";//文件大小
      echo "<version>".$version."</version>";//版本信息
      echo "</results>";
      break;
    case "1"://android
      echo "<&#63;xml version=\"1.0\" encoding=\"utf-8\"&#63;>";
      echo "<results>";
      echo "<updateFileName>i2ty</updateFileName>";//客户端名字
      echo "<updateFileUrl>http://i2ty.com/app/".$android_filename."</updateFileUrl>";//返回给客户端的下载地址
      echo "<fileSize>0</fileSize>";//文件大小
      echo "<version>".$version."</version>";//版本信息
      echo "</results>";
      break;
  }
}
&#63;>
Copy after login

version.php content:

PHP

<&#63;php
define('CIN', true);
$result['vtitle']="更新";
$result['vcontent']="新版本有更新喔!~新增功能修复各种错误";
print_r(json_encode($result));
&#63;>
version.xml 内容:
PHP
<&#63;xml version="1.0" encoding="utf-8" &#63;>
<root desc="Login">
 <news version="00.00.0001" iphone_filename="i2ty.ipa"  android_filename="i2ty.apk" />
</root>
index.html 客户端:
PHP
window.uexOnload = function(type){   
    if (!type) {
      update();
    }
var flag_sdcard = 1;
var updateurl = '';//下载新apk文件地址
var filepath2 = "/sdcard/";//保存到sd卡
var fileName = '';//新版本文件名
var platform = '';//平台版本
function update()
{  
    //安卓版 ,显示下载进度 (step:7)
    uexDownloaderMgr.onStatus = function(opId, fileSize, percent, status) {
        if (status == 0) {
            // 下载中...
            Log('download percent ' + percent + '%');
            uexWindow.toast('1', '5', '正在下载'+localStorage.app_title+'新版,请稍后。进度:' + percent + '%', '');
        } else if (status == 1) {// 下载完成.
            uexWindow.closeToast();
            uexDownloaderMgr.closeDownloader('14');//关闭下载对象
            uexWidget.installApp(filepath2+fileName);// 安装下载apk文件
        } else {
            uexWindow.toast('1', '5', '下载出错,请关闭'+localStorage.app_title+'再次运行.', '');
        }
    };
    //安卓版 ,创建下载对象回调函数(step:6)
    uexDownloaderMgr.cbCreateDownloader = function(opId, dataType, data) {
        Log('uexDownloaderMgr.cbCreateDownloader data='+data);
        if (data == 0) {
            //updateurl是通过调用cbCheckUpdate回调后,放入全局变量的
            uexDownloaderMgr.download('14', updateurl, filepath2+fileName, '0');//开始下载apk文件
        } else if (data == 1) { 
            ;
        } else {
            ;
        }
    };
    //提示更新模态框按钮事件回调函数,判断用户选择更新还是取消 (step:5)
    uexWindow.cbConfirm = function(opId, dataType, data) {
        Log('uexWindow.cbConfirm ');
        //调用对话框提示函数
        if (data == 0) {
            //用户点击稍后按钮,不进行更新
        } else {
            //用户点击确定按钮,进行更新
            if (platform == 0) {
                //苹果版更新,通过浏览器加载appstore路径
                uexWidget.loadApp(updateurl,'','');
                //uexWidget.loadApp("", "", updateurl);//旧方法 已经不可以使用了。
            } else if (platform == 1) {
                //安卓版更新,通过创建下载对象进行下载                
                uexDownloaderMgr.createDownloader("14");
            } else {
                ;
            }
        }
    };
    //调用检查更新回调函数,请求成功后,弹出模态框让用户选择是否现在更新(step:4)
    uexWidget.cbCheckUpdate = function(opCode, dataType, jsonData) {        
        Log('jsonData='+jsonData);
        var obj = eval('(' + jsonData + ')');
        if (obj.result == 0) {
            // tips = "更新地址是:" + obj.url + "<br>文件名:" + obj.name + "<br>文件大小:" +
            // obj.size + "<br>版本号:" + obj.version;
            updateurl = obj.url;
            fileName = obj.name+".apk";
            getVersionContent();
            // var value = "稍后;更新";
            // var mycars = value.split(";");
            // uexWindow.confirm('', '当前有新版本,是否更新&#63;', mycars);//弹出提示框,是否确定更新
        } else if (obj.result == 1) {
            //苹果
            //alert("更新地址是:" + obj.url + "<br>文件名:" + obj.name + "<br>文件大小:" +
            //obj.size + "<br>版本号:" + obj.version)
            ;// tips = "当前版本是最新的";alert(tips);
        } else if (obj.result == 2) {            
            ;// tips = "未知错误";alert(tips);
        } else if (obj.result == 3) {            
            ;// tips = "参数错误";alert(tips);
        }
    };
    //检查是否已经存在sd卡的回调函数(step:3)
    uexFileMgr.cbIsFileExistByPath = function(opCode, dataType, data) {
        Log('uexFileMgr.cbIsFileExistByPath flag_sdcard='+flag_sdcard+' , data='+data);
        if (flag_sdcard == 0) {
            if (data == 0) {
                Log('sdcard不存在,根据具体情况处理');
            } else {
                //执行检查更新
                uexWidget.checkUpdate();//根据config.xml里面配置的检查更新地址发起http请求
            }
            flag_sdcard = 1;
        } 
    };
    //获取平台版本回调函数,确定是客户端是那个平台的客户端 (step:2)
    uexWidgetOne.cbGetPlatform = function(opId, dataType, data) {
        Log('uexWidgetOne.cbGetPlatform ');
        //获取系统版本信息回调函数
        platform = data;
        Log('platform= '+platform);
        if (data == 0) {
            // 是iphone
            uexWidget.checkUpdate();// 直接调用检查更新,检查更新地址在config.xml里面有配置
        } else if (data == 1) {
            // 是android
            flag_sdcard = 0;
            uexFileMgr.isFileExistByPath('/sdcard/');//先判断是否存在sd卡,再调用checkUpdate来进行更新
        } else {
            // 是平台
        }
    };
    uexWidgetOne.getPlatform();//获取平台版本 (step:1)
}
function Log(s) {
    uexLog.sendLog(s);
}
function getVersionContent(){
    var url = web_url+"version.php";
    uexXmlHttpMgr.onData = getvSuccess;
    uexXmlHttpMgr.open(777, "get", url,"");
    uexXmlHttpMgr.send(777); 
}
function getvSuccess(opid,status,result){
    if (status == -1) {
      uexWindow.toast("0","5","连接不上网络^_^哦","3000");
    }
    if(status==1){
    uexXmlHttpMgr.close(777);
    uexWindow.closeToast();
    if(result=="[]"){uexWindow.toast("0","5","无","2000");}
    else{
      var con=eval('(' + result + ')')
      var value = "稍后;更新";
      var mycars = value.split(";");
      uexWindow.confirm(con.vtitle, con.vcontent, mycars);//弹出提示框,是否确定更新
      }
    }
}
Copy after login

Finally, the app’s config.xml file configuration update address is filled in as:

http://www.i2ty.com/update.php

App update tips:

The content of the pop-up window can be customized according to the content of the version.php file.

The above content is how this article explains how to use the Appcan client to automatically update the PHP version number. I hope it will be helpful to everyone.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

See all articles