Home > Web Front-end > JS Tutorial > Examples to explain how node.js implements WeChat JS-API encapsulation interface

Examples to explain how node.js implements WeChat JS-API encapsulation interface

巴扎黑
Release: 2017-09-07 10:18:13
Original
1690 people have browsed it

This article mainly introduces the sample code of node.js to implement the WeChat JS-API encapsulation interface. The editor thinks it is quite good, so I will share it with you now and give it as a reference. Let’s follow the editor and take a look.

Wechat JS-API interface

Function:

Used to manage and obtain the access_token produced by WeChat JSSDK, jsapi_ticket and signature

Installation


npm i wechat_interaction_jsapi
Copy after login

Init


let Jsapi = require("wechat_interaction_jsapi");
Copy after login

Usage

WECHAT_APPID, WECHAT_APPSECRET are the developer id and password respectively, which can be found in WeChat Public Platform->Development->Basic Configuration


const jssdk = new Jsapi(WECHAT_APPID, WECHAT_APPSECRET);
Copy after login

1. Get access_token, return the promise object, the resolve callback returns string


jssdk.getAccessToken().then(
  re => console.log(re)
).catch(err => console.error(err));
Copy after login

2. Get jsapi_ticket, return the promise object, the resolve callback returns string


jssdk.getJsApiTicket().then(
  re => console.log(re)
).catch(err => console.error(err));
Copy after login

3. Obtain the JS-SDK permission verification signature, return the promise object, and the resolve callback returns json


jssdk.getSignPackage(url).then(
  re => console.log(JSON.stringify(re))
).catch(err => console.error(err));
Copy after login

Flowchart

1. The first method (parameters appear repeatedly and are clearly organized)

2. The second method (Parameters do not appear repeatedly and the order is not clear)

Front-end calling method

1. Refer to the official documentation

https://mp .weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115

2. Notes:

(1) Confirm that the whitelist has been configured: WeChat Public Platform->Development- >Basic configuration->ip whitelist

(2) Confirm that the JS interface security domain name has been configured: WeChat public platform->Settings->Official account configuration->JS interface security domain name

The above is the detailed content of Examples to explain how node.js implements WeChat JS-API encapsulation interface. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template