Home > Web Front-end > JS Tutorial > body text

node.js implements encapsulation of WeChat interface

php中世界最好的语言
Release: 2018-04-18 13:35:53
Original
1935 people have browsed it

This time I will bring you node.js to implement the encapsulation of the WeChat interface, node.js to implement the encapsulation of the WeChat interface. What are the precautions, the following is a practical case, let's come together take a look.

In everyone’s use of node.js, many people will encounter using node.js to implement WeChat JS-API encapsulated interface operations, and many people still don’t know how to implement it. , the following article will introduce to you the implementation method and code, and those who are interested can learn about it together.

Wechat JS-API interface

Function:

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

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, and 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, and 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

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

github:https://github.com/xjnotxj/wechat_interaction_jsapi

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:



The above is the detailed content of node.js implements encapsulation of WeChat 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!