Home >WeChat Applet >Mini Program Development >Use DeviceOne to implement WeChat applet functions
The WeChat mini program is about to be launched, and it has become very popular even before it is launched. Based on the huge platform of WeChat, small programs are bound to have great success. However, it cannot completely replace the App, and the App must be developed. If we want to implement a mini program based on our own APP that contains WeChat-like functions, how should we implement it? Let’s first take a look at the technical features of mini programs.
## Characteristics of mini programs
1. Cross-platform, WeChat is like JRE, implemented on different operating systems, so mini programs on WeChat are like java programs running on JRE, Thus achieving cross-platform. In addition, the adaptation problem of multi-platform and multi-model is solved.
2. The experience is good. Loading HTML in webview is the easiest cross-platform method, but the experience on mobile phones is too poor. Mini programs have nothing to do with web development or h5. Its UI and operating mechanism are completely native, so the experience is much better than the public account.
3. No installation required, just scan the QR code. In fact, there will still be downloads, but the downloaded data is so small that users cannot notice it at all. For example, if you develop a small program with 10 pages, when users scan it, they will only download a few files on the home page, which may be less than 1k, and they will be cached locally and in memory after downloading.
In fact, one of the biggest advantages is that WeChat is the application with the highest viscosity for a large number of users. Mini programs based on it are easy to promote, so we won’t talk about it here for now.
Let’s take a look at the shortcomings:
1. It can only be based on the WeChat entrance. This is obvious. The current news is that it is impossible to have an entry method for small programs on the desktop. I don’t know if it will be supported in the future. .
2. You can only use the functions provided by the WeChat application, and cannot use other third-party functions such as maps, payments, statistics, etc. WeChat has all these functions and does them very well, but diversification can take advantage of long-term technological development.
3. Mini programs have limited capabilities. Limited UI and limited functions cannot cope with complex interactions and business requirements. In addition, developers cannot extend its basic functions.
DeviceOne can not only have the above advantages, but also avoid the above disadvantages. Everyone will definitely question this. Let’s first briefly introduce DeviceOne’s instructions for the above points, and then look at an example.
## Features of DeviceOne
1. Cross-platform, using js or lua as the development language, written once, and published to android, ios and windows platforms. And it also automatically adapts to various models.
2. The experience is good. From UI to functions, deviceone is completely native and has nothing to do with HTML. So it is a native experience effect.
3. No installation is required. We can analyze this carefully from the following example.
4. It is not based on a fixed framework App, which means you can make your own WeChat program. Let’s call it the main program for now. It can have its own icon, its own entrance, and then load your Small program defined by yourself. Including the main program, it is completely hot-upgradeable, just as convenient as updating the small program.
5. Deviceone has completely made app development into cross-platform components, dividing developers into two parts: business developers who develop apps and native developers who develop native components.
5.1 Those who develop apps do not need to understand android and ios, and do not need to have android and ios development environments. They only need js to develop apps
5.2 Those who develop components do not need to understand and understand Based on the business requirements of the specific app, you only need to develop cross-platform UI and functional components that can be reused. Therefore, any third-party component can be integrated, such as Baidu Map, Amap, Alipay or WeChat Pay.
6. Deviceone's components have extended functions. Currently, the official provides more than 100 components, and other developers provide more than 30 components. Based on the deviceone platform, other native developers can continuously expand the component store.
## Examples similar to small programs
Look at the running renderings first
This is an application of deviceone dynamic loading component API example. We call it the main program, which itself was developed using deviceone. The do_App, do_Global and so on listed in the list are all components of deviceone. Each component corresponds to a new program and is a small example to demonstrate the function of this component. We call it a small program, but it is essentially different from the main program. the difference.
The operating mechanism is very simple:
1. When the program starts, it obtains a json from a web service, which contains information about multiple components, including name, file size, url for downloading the applet, and file md5 value.
2. Compare whether the local old md5 is the same as the new md5. If they are different, it will prompt that there is an update. You can download the latest mini program by clicking the update button. There is no QR code scan to download the home page of the mini program. , a simple modification can do that.
3. Click a line to open a new page, load the mini program, exit the page, and close the mini program.
The basic code is as follows:
var http = mm("do_Http"); // 显示等待窗口 var waittingLayer = require("source://modules/waittingLayer/call"); waittingLayer.invoke({ hint : "请稍后" }); var src = "data://" + data.id + ".zip"; http.url = data.url; http.on("result", function(d) { sm("do_Storage").unzip(src, "data://temp/" + data.id, function(_d, e) { var updatesrc = "data://temp/" + data.id + "/source/view"; sm("do_App").update([ updatesrc ], "source://view", function() { sm("do_Page").fire("installed", data.id); // 隐藏等待窗口 var waittingLayer = require("source://modules/waittingLayer/call"); waittingLayer.invoke({ close : true }); }) }) }) http.download(src);
## Summary
It feels very simple, but it is of great significance. In addition to the small program being easy to update, the main program is also easy to update. The principles are exactly the same. This can be used for 2 basic purposes.
1. To implement hot update of the program, all business logic and pages of deviceone are text files, including js code and ui files (json description), so natural updates are very easy.
2. For larger applications or enterprises, the business can be completed independently by different development teams and departments, and then managed by an overall framework App to achieve standardization of application development and management. Moreover, deviceone has powerful cloud packaging capabilities, and compilation and packaging can also be managed in a standard way.
The last thing I want to say is that deviceone is not just an idea and practice. It has been a product that has been officially in operation for more than a year. It has provided many services to many individuals and companies on the Internet, and has launched many online products for individuals and enterprises. Applications.
For more information on using DeviceOne to implement WeChat applet functions, please pay attention to the PHP Chinese website for related articles!