search
HomeWeChat AppletWeChat DevelopmentExample analysis of developing WeChat applet using hprose

How to use hprose to develop WeChat applet? Let me introduce it to you below:

1. Download the WeChat applet development tool and install it

If you already have the WeChat applet development tool, there is no need to download it. Download the development tool: mp.weixin.qq .com/debug/wxadoc/dev/devtools/devtools.html?t=1474644083132

2. Download hprose-html5 or hprose-js

Download address: hprose-html5 or hprose-js .
It is recommended to use the hprose-html5 version. This version is smaller, supports binary data transmission, and is faster.

You can use git clone to download, or you can just download the files in the dist directory,

3. Take the hprose-html5 version as an example:

hprose-html5.src. js is the source version and hprose-html5.js is the compressed version

Both versions can be used. It is recommended to use the source version during the debugging phase. But do not use the hprose-html5.min.js version. This version is a compressed version and does not support compilation in WeChat mini programs.

After that, you can copy them to the utils directory of the WeChat applet you created (just copy one of them), and then rename it hprose.js (this step is optional, just for later When citing, the names are consistent).

Next, open the pages/index/index.js file.

Add at the beginning:

var hprose = require('../../utils/hprose.js');

Then add the following code to the onLoad event:

var client = hprose.Client.create("http://www.hprose.com/example/", ["hello"]);     
    client.hello("world", function(result) 
    {       
    console.log(result);     
    });

The overall look is like this:

//index.js 
var hprose = require('../../utils/hprose.js'); //获取应用实例
var app = getApp() Page({   
data: {     
motto: 'Hello World',     
userInfo: {}  
 },  
  //事件处理函数   
 bindViewTap: function() 
 {     
 wx.navigateTo({       
 url: '../logs/logs' 
     })   
 },   
 onLoad: function () {    
  console.log('onLoad')     
  var client = hprose.Client.create("http://www.hprose.com/example/", ["hello"]);     
  client.hello("world", function(result) 
  {       
  console.log(result);     
  });     var that = this     
  //调用应用实例的方法获取全局数据     
  app.getUserInfo(function(userInfo){       
  //更新数据       
  that.setData({         
  userInfo:userInfo      
   })     
   })   
   } 
   })

Then click Compile and run. If there is no problem with your network, you will see in the debugging console:

Example analysis of developing WeChat applet using hprose

It’s that simple, you can use hprose to develop WeChat applet .

The above is the detailed content of Example analysis of developing WeChat applet using hprose. For more information, please follow other related articles on the PHP Chinese website!

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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.