6 years ago (2015-04-21)  Software development |   First to comment  9 
post score 0 times, average 0.0

After learning one month of Android, I wrote a few small programs and I always felt that something was missing.Seeing that the software on the general market provides software update services, most guests want to have a virtual host. Can they build a software update server by themselves?Baidu took a look at “relying on virtual hosts to provide software update services for self-made APPs.” Unfortunately, searching for Baidu has not found a solution yet. To implement software updates, there must be a comparison between the latest software version number published on the server and the version currently used on the client.If the version number is the same, the user is prompted to "currently the latest version"; if the latest version published on the server is higher than the one used by the user, the "version update" is prompted and the download function is provided, and the installation is automatically performed after the download is completed.To get the latest version number, you must read the database. If you directly connect the database directly with the user's password, this is undoubtedly insecure, because if you decompile or crack your software, your database will be desperate.So, the solution I came up with was to use PHP as an API on the server side and use the API request method to get the latest version number and version description and download address.After a few weeks of struggle, here are my specific implementation steps:

Relying on Web Hosting to Provide Software Update Service for Home-made APPs (1) - Using PHP to Make APIs

1. Create a new software database table, add the software ID, version number, download address, version description and other columns;

The SQL statement is as follows:

  The database table created is named: mysoftware, and the structure is as shown in the figure: Relying on Web Hosting to Provide Software Update Service for Homemade APPs (1)

2.PHP calls the database to return a JSON format string

I created a new folder named "api" in my virtual machine root directory and two php files under the "api" folder: update.php and db_connect.php. Which db_connect.php is a PHP file connected to the database, which records the database connection database name, user name, host, password, encoding format, the code is as follows:

  You can access the PHP URL to test if the file is correct. Update.php is a PHP file that returns a JSON string.Its role is to retrieve the contents of the software database table and return data through the GET method. The code is as follows:

  In this file, pass the "http://wangbaiyuan.cn/api/update.php?id=1" GET method to accept the value, and then call the db_connect.php file to connect to the database, execute $string = "select * from My_software where sw_id=".$id; statement, and then parse the result to return the standard JSON format string.Which jsons_encode function you can refer to my previous article: PHP using json_encode conversion array Chinese garbled to understand; Below I made a successful visit to http://wangbaiyuan.cn/api/update.php?id=1 of the web content:


{"sw_id":"1","sw_name":"BY address book","sw_version":"1.2","sw_url":"http ://wangbaiyuan.cn/api/software/Contactss_1_2.apk","sw_description":" 1.BY address book, is an app developed by Wang Baiyuan and used as an Android development introductory test;n 2. Calling on own virtual The API built on the database on the host implements the version update function;n 3. Use some new Android technology."}

You may be excited when you see this string. You may think that the following is the work of parsing JSON data according to different platforms.

Relying on virtual host to provide software update service for self-made APP (2) - Android parsing API data

In the next section, I will use the Android example to explain how to parse JSON data to provide a software update service for self-made APPs. Check out the next section.

Code download


This article has been printed on copyright and is protected by copyright laws. It must not be reproduced without permission.If you need to reprint, please contact the author or visit the copyright to obtain the authorization. If you feel that this article is useful to you, you can click the "Sponsoring Author" below to call the author!

Reprinted Note Source: Baiyuan's Blog>>https://wangbaiyuan.cn/en/virtual-hosts-provide-app-update-services-a-2.html

Post comment


No Comment


Forget password?