Home  >  Article  >  Web Front-end  >  What is WeChat js

What is WeChat js

(*-*)浩
(*-*)浩Original
2019-06-01 13:06:094085browse

WeChat JS-SDK is a web development toolkit based on WeChat provided by WeChat public platform for web developers.

What is WeChat js

By using WeChat JS-SDK, web developers can use WeChat to efficiently use the capabilities of mobile phone systems such as taking pictures, selecting pictures, voice, and location, and at the same time, they can directly use WeChat WeChat's unique capabilities such as sharing, scanning, coupons, and payments provide WeChat users with a better web experience.

JSSDK usage steps

Step 1: Bind the domain name

First log in to the WeChat public platform and enter "Public Account Settings" Fill in the "JS interface security domain name" in the "Function Settings".

Note: After logging in, you can view the corresponding interface permissions in the "Developer Center".

Step 2: Introduce JS files

Introduce the following JS files on the page that needs to call the JS interface (https is supported): http://res.wx.qq .com/open/js/jweixin-1.4.0.js

If you need to further improve service stability, when the above resources are inaccessible, you can visit: http://res2.wx.qq.com /open/js/jweixin-1.4.0.js (supports https).

Note: Supports loading using AMD/CMD standard module loading method

Step 3: Inject permission verification configuration through the config interface

All need to use JS -The SDK page must first inject configuration information, otherwise it will not be called (the same URL only needs to be called once. The SPA web app that changes the URL can be called every time the URL changes. Currently, the Android WeChat client does not support pushState. H5 is a new feature, so using pushState to implement web app pages will cause signature failure. This problem will be fixed in Android 6.2).

wx.config({
    debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
    appId: '', // 必填,公众号的唯一标识
    timestamp: , // 必填,生成签名的时间戳
    nonceStr: '', // 必填,生成签名的随机串
    signature: '',// 必填,签名
    jsApiList: [] // 必填,需要使用的JS接口列表
});

Step 4: Handle successful verification through ready interface

wx.ready(function(){
    // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
});

Step 5: Handle failed verification through error interface

wx.error(function(res){
    // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。
});

The above is the detailed content of What is WeChat js. 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
Previous article:Why js needs constructorNext article:Why js needs constructor