search
HomeBackend DevelopmentPHP TutorialUse Appcan client to automatically update PHP version number (full), appcan version number_PHP tutorial

Use Appcan client to automatically update the PHP version number (full), appcan version number

In the process of project development, I encountered automatic updates on the app side. I checked the relevant information and then put Appcan The method for the client to automatically update the PHP version number is sorted out. 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;>

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);//弹出提示框,是否确定更新
      }
    }
}

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1041327.htmlTechArticleUse Appcan client to automatically update the PHP version number (full), the appcan version number is encountered during the project development process The client automatically updates, consulted the relevant information and then automatically updated the Appcan client...
Statement
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
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

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

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment