In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you an analysis on how to carry out Wechat JS-SDK. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
Overview
Wechat JS-SDK is a web development kit based on Wechat provided by Wechat public platform for web developers.
By using Wechat JS-SDK, web developers can take advantage of Wechat's ability to efficiently use mobile systems such as photo, picture selection, voice, location and so on. At the same time, they can directly use Wechat's unique capabilities such as Wechat sharing, scanning, card coupons, and payment to provide Wechat users with a better web experience.
This document introduces how to use Wechat JS-SDK and related precautions for web developers.
JSSDK use step 1: bind a domain name
Log in to the Wechat public platform and enter the "function Settings" of "official account Settings" to fill in "JS API Security Domain name".
Note: after logging in, you can view the corresponding API permissions in the developer Center.
Step 2: introduce the JS file
Introduce the following JS file (https is supported) on the page that needs to call the JS API: http://res.wx.qq.com/open/js/jweixin-1.0.0.js
Note: AMD/CMD standard module loading method is supported.
Step 3: verify the configuration by injecting permissions through the config interface
All pages that need to use JS-SDK must first inject configuration information, otherwise they cannot be called (the same url only needs to be called once. The web app of the SPA that changes the url can be called each time the url changes. Currently, the Android Wechat client does not support the new H5 feature of pushState, so using pushState to implement web app pages will cause signature failure, which will be fixed in Android6.2).
Wx.config ({debug: true, / / enables debug mode. The returned values of all api called will be displayed in the alert on the client side. To view the parameters passed, you can open them on the PC side, and the parameter information will be typed out through log and printed only on the PC side. AppId:'', / / required, official account * marks timestamp:, / / required, timestamp for generating signature nonceStr:'', / / required, random string for generating signature signature:', / / required, signature, see Appendix 1 jsApiList: [] / / required, list of JS APIs to be used, list of all JS APIs see Appendix 2}) Step 4: successfully verify the wx.ready through the ready API processing (function () {/ / config information verification will execute the ready method. All API calls must be performed after the config API obtains the result. Config is an asynchronous operation on the client side, so if you need to call the relevant API when the page is loaded, you must call the relevant API in the ready function to ensure correct execution. Interfaces that are called only when triggered by the user can be called directly and do not need to be placed in the ready function. Step 5: verify the failure of wx.error through the error API (function (res) {/ / config information verification failure will execute the error function. If the signature expires and the verification fails, the specific error information can be viewed in the debug mode of config or in the returned res parameter. For SPA, you can update the signature here. }); description of API call
All APIs are called through wx objects (you can also use jWeixin objects). The parameter is an object. In addition to the parameters to be passed by each API itself, there are also the following common parameters:
Success: the callback function that is executed when the API is called successfully.
Fail: the callback function that is executed when the API call fails.
Complete: the callback function that is executed when the API call is completed, regardless of success or failure.
Cancel: the callback function when the user clicks cancel. Only part of the api with the user canceling operation will be used.
Trigger: listens to the method that is triggered when a button is clicked in Menu. This method supports only the relevant interfaces in Menu.
Note: do not try to use ajax asynchronous request in trigger to modify the content of this sharing, because the client sharing operation is a synchronous operation, and the return packet using ajax has not yet been returned.
The above functions all take a parameter of type object, in addition to the data returned by each interface itself, there is also a general property errMsg, whose value format is as follows:
When the call is successful: "xxx:ok", where xxx is the API name of the call
When the user cancels: "xxx:cancel", where xxx is the name of the calling API
When the call fails: the value is the specific error message
The above is the editor for you to share how to carry out Wechat JS-SDK analysis, if there happen to be similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.