Qingming festival is coming. Can you get off work on time today?

Ajie had planned his trip to Bali with his girlfriend long before the holiday and booked his flight in advance. It happened the day before the holiday, due to the need of corporate hospitality to emergency launch a visitor reservation made small program meet the needs of independent appointments and visitors notice, since there is no experience through a small program to send notice to precipitate, from reading the document to the product release may requires a lot of time, this makes ajie made difficult, at 19:00 originally scheduled to take off the plane, he was able to catch up with?

Fortunately, after cloud function, cloud storage and cloud database, another artifact to improve development efficiency – cloud call online!

What is a cloud call?

Cloud call is simply the ability to call wechat API without Token. In the traditional wechat applets development, if the API of the server needs to be called, it is necessary to exchange the appID and Appsecret for the access_token, which is the global unique background interface of the wechat applets, and the validity period is only 2 hours. This credential is needed to start calling apis such as template messages, customer service messages, and so on. The birth of cloud call greatly simplifies the authentication step of calling wechat API, and realizes one-line code that is called and used immediately.

Why call from the cloud?

After using the cloud call capability of wechat applets, developers can —

1. One line of code calls the API

Cloud invocation allows most applets to be called without obtaining an Access_token. Developers only need to care about the business logic itself and the timing of the API invocation to truly implement a line of code to call the API.

2. There is no need to worry about voucher security

Interfaces that support cloud invocation can be invoked without obtaining access_token. In other words, developers can obtain natural, safe and reliable interface invocation conditions without caring about the custody and failure of access_token. All authentication mechanisms of interface invocation are handled by cloud development.

How do I use cloud invocation?

After ajie read the documentation of cloud call, he instantly understood the implementation method of cloud call. Based on the actual product requirements, the company’s expected small program needs to push template messages to users to notify them after users input reservation information and submit it.

In terms of wechat applets push template messages, the traditional implementation path is as follows: the user makes a reservation successfully – check whether the access_token is within the validity period – Obtain the access_token – call templateMessage. Send – push template messages.

The implementation path of cloud invocation is as follows: successful user reservation – templateMessage. Send-push templateMessage is invoked. There is no need to care about access_token acquisition, storage and invalidity.

In combination with the getWXContext method provided by wx-server-sdk to obtain the openid of the login user, call templatemessage. send method, pass in the receiver openid, templateMessage content, templateMessage id and other parameters, The template message is delivered. The core code for sending template messages is as follows:

After deploying the written cloud function to the cloud, users can receive template message notification after successful reservation. So far accomplished, self-test without error arraignment!

Ajie Qiao took advantage of the cloud call capability developed by cloud to eliminate the design of access_token acquisition, verification, storage and other related processing mechanisms, and completed the whole project in less than one afternoon. Finally arrived at the airport as scheduled, Ajie will be passed to the airport did not wait for a long girlfriend, looking at his girlfriend worship eyes, Ajie took his girlfriend’s hand happily toward the gate… (The story is pure fiction, if there are any similarities… That’s the same.)

Smart cloud development, no overtime is not a dream

The launch of cloud call will further reduce the development threshold of wechat small programs and improve the development efficiency. Access_token free API calls, one step closer to leaving work early!

In addition to cloud call, cloud development also provides free cloud functions, cloud database, cloud storage and Serverless (Serverless computing) capabilities, power micro channel small program developers!

(Cloud development entrance built into wechat developer tools)

At present, developers with wechat developer tool version >= 1.02.1903251 and cloud function WX-server-SDK >= 0.4.0 can directly use the cloud call ability. For specific usage methods, see “wechat Small program Development Document”, and you can poke the bottom of “Read the original text” direct.