Uniapp, as the hottest mobile terminal development technology recently, is a set of code that can be packaged into Android/iOS apps and small programs of various platforms. It can be said that there is no most convenient but more convenient.

It has been more than a month since GoEasy launched the DCloud Uniapp plugin market, and has received a lot of praise and praise from Uniapp developers. Xiaobian and GoEasy team will continue to work hard to provide Uniapp developers with the most simple and elegant API. Fast and reliable instant messaging service.

During this period, I have also received some questions from many friends. Such as:

1. What are the differences and advantages between GoEasy and Uniapp Websocket APIS?

The official WebSocket API of Uniapp is mainly used to communicate with your WebSocket service, so the premise of using Uniapp WebSocket is to build your own WebSocket service, and then communicate with it. This is a purely technical API. After setting up a network connection, there is still a lot of work to be done by yourself, such as:

  • You need to implement the heartbeat mechanism to maintain network connections and judge the network connection status of clients.

  • Need to realize the automatic reconnection of disconnection network;

  • You need to maintain the message list to ensure that the message can be resent when the network is disconnected and reconnected.

  • You need to maintain a list of clients;

  • .

And so on a lot of detailed and complicated work, such as websocket security mechanism and performance optimization;

In addition, the server side also has a lot of work to be completed by itself. If you are interested in building websocket by yourself, you can refer to this technical share “Building WebSocket message push service, several issues must be considered”.

GoEasy is a mature and stable WebSocket enterprise PAAS service platform, developers do not need to consider the construction of webSocket server, only need a few lines of code, can easily achieve websocket communication between client and client, server and client, do not need to consider performance, security, High availability cluster problems. Just focus on developing your business functionality.

GoEasy has built-in webSocket heartbeat, reconnection, message resending, history messages, and client login and logout alerts. Developers do not need to build webSocket services to handle cluster high availability, security, and performance issues. GoEasy has been running steadily for 5 years, supporting tens of millions of concurrent applications and successfully supporting important activities of many well-known enterprises, with proven security and reliability.

2. What scenarios are GoEasy mainly used in Uniapp development?

First of all, from the technical point of view, Uniapp supports all the technology Android, iOS and small programs, GoEasy is perfect support.

In terms of application scenarios, GoEasy can perfectly support all scenarios requiring Websocket communication:

  • Chat, IM, live barrage, user online and offline reminders, online user list

  • Scan to order, scan to login, scan to pay, scan to sign in, scan to print

  • Event reminder, work order, order real-time reminder

  • Online auction, online ordering, online seat selection real-time data display, real-time monitoring large screen, real-time financial market display, equipment monitoring system

  • Real-time location tracking, real-time delivery tracking, real-time logistics tracking

  • Remote drawing board, telemedicine, games, remote online teaching

  • .

3. Why is GoEasy’s documentation so simple? So simple I don’t even know how to use it

Isn’t simplicity bad? At GoEasy, the pursuit of API minimalism has been one of our priorities from day one. Strictly control the number of interfaces, is to reduce the cost of learning developers, in fact, is to let you cool ah! But that doesn’t stop GoEasy from perfectly supporting all webSocket im requirements.

Today xiaobian will teach you how to use GoEasy in Uniapp, the shortest time to achieve a Web instant messaging Demo.This demo has passed the small program, iOS and Android real machine test, the complete source code has been uploaded to Github, download, just need to change the code appKey into their own common key, you can experience. Download address:Github.com/GoEasySuppo…

1. Obtain appKey

Sign up for GoEasy (www.goeasy.io/), create an app, and get your AppKey

GoEasy provides two types of Appkeys:

Common key: can receive or send messages. The biggest difference is that it has write permission and can send messages. Suitable for client and server development with message sending requirements.

Subscriber key: can only receive messages, but cannot send messages. The biggest difference between a Common key and a Common key is that it has no write permission and can only receive messages. Can be used for some clients without sending requirements.

2. Get GoEasy SDK

Two ways:

DCloud Uniapp plugin market download: search GoEasy to download

It can also be downloaded directly from goeasy:

www.goeasy.io/cn/doc/clie…

Initialize the GoEasy object

In main.js, goEasy is initialized as a global object of Uniapp, which is convenient for all pages to be called, and avoids repeated New GoEasy objects in multiple pages.

Pass in a different Host depending on the region you selected when creating the GoEasy application in the background. If you select Hangzhou when creating the GoEasy application, then Host :”hangzhou.goeasy.io”. Select Singapore,host:”singapore.goeasy.io”.

If most of your users are in China, remember to choose Hangzhou when creating your app to get faster communication speed.

Prototype.$goEasy = new GoEasy({host: $goeasy = new goEasy ({host: $goeasy; "Hangzhou. Goeasy. IO ", appKey: "my_appkey", // replace your appKey onConnected: function() {console.log(' Connected successfully! ')}, onDisconnected: function() {console.log(' Disconnected! ')}, onConnectFailed: function(error) {console.log(' Connection failed or error! ')}});Copy the code

4. The UNIApp receives messages

This.$goEasy. Subscribe ({channel: "my_channel", // replace with your own channel onMessage: function (message) { alert("Channel:" + message.channel + " content:" + message.content); }});Copy the code

Many friends will ask where a channel comes from, how to create it, and what should be passed in?

According to your business requirements, the channel can be any string, except that it cannot contain Spaces and Chinese characters are not recommended. The channel only needs to be consistent with the sender of the message to receive the message. A channel can be the UUID of your live broadcast room or the unique representation of a user. It can be defined arbitrarily. A channel does not need to be created and can be discarded at will.

5. Uniapp sends messages

When sending a message, note that the channel must be the same as the subscriber channel; otherwise, the message cannot be received.

Publish ({channel: "my_channel", // replace your own channel message: "Hello, goEasy!" // Replace with the content of the message you want to send});Copy the code

This code source download:

Github.com/GoEasySuppo…

Miniprogram emphasizes:

If you want to package it as a wechat mini program, you need to configure a legitimate socket domain name on the wechat public account platform; otherwise, it cannot be used. Specific steps:

Visit mp.weixin.qq.com, enter WeChat public platform | small program – > Settings – > Settings – > server domain development

Add goeasy address: wx-hangzhou.goeasy. IO (remember wx-)

If you selected the Singapore region when creating the GoEasy app, add the address:

wx-singapore.goeasy.io

Q&a Time:

1. Can my server send messages? What languages are supported?

Any language can send messages by calling goeasy’s Rest API, and for your convenience, goeasy’s official documentation also includes Java, C#,NodeJS, PHP, Ruby, Python and other common languages to call the Rest API code. Get more details here:

www.goeasy.io/cn/doc/serv…

2. Can GoEasy send pictures, voice and video?

Of course, you can send the file by pushing the file path.

According to industry convention, whether MSN, wechat, QQ for pictures and videos, the usual practice is to push only the file path, but not the file itself. If you’re paying attention, when you receive pictures and videos, you wait a little while to see the message, because when you send it, only the path is sent.

GoEasy

1, uniAPP version of the direct broadcast chat room (support packaged into android /ios APP, wechat small program) : gitee.com/goeasy-io/G…

2, UNIAPP version of instant messaging IM (support packaged into Android /ios APP, wechat small program) : gitee.com/goeasy-io/G…

3, wechat small program version of instant messaging IM: gitee.com/goeasy-io/G…

4, VUE version of instant messaging IM: gitee.com/goeasy-io/G…

5, H5 version of instant messaging IM: gitee.com/goeasy-io/G…

6, H5 version of the direct broadcast chat room: gitee.com/goeasy-io/G…