Problem description

In the public number and back-end interface are not ready under the premise of how to debug JS-SDK related interface? This article shows you how to resolve the parameters required for wx.config.

wx.config({
  debug: true.// If debug mode is enabled, the return value of all API calls will be displayed in the client alert. If you want to view the parameters passed in, you can open it in the PC, and the parameter information will be printed in the log.
  appId: ' '.// Mandatory, the unique identifier of the public account
  timestamp:,// Mandatory to generate the timestamp of the signature
  nonceStr: ' '.// Mandatory to generate a random string of signatures
  signature: ' '.// Mandatory, signature
  jsApiList: [] // Mandatory, a list of JS interfaces to be used
});
Copy the code

Public account preparation

To access jS-SDK, you need to configure the public account information. You can apply for the official test account in the test account management

The Intranet penetrates the domain name accessible to the Internet

  1. Download ngrock
  2. Locate the downloaded file and execute./ngrock http 8080(8080 is the project running port)
  3. The browser accesses the obtained domain name to check whether the project content can be accessed normally

Configure the JS domain name whitelist

Configure the whitelist in the SECURE domain name of the JS interface. The domain name is the IP address obtained in the previous step

Get the Access Token

The request interface is as follows. Access token can be obtained directly in the browser concatenation request, and AppID and Secret can be obtained in the test number

https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
Copy the code

Access to Js Ticket

The request interface is as follows. You can directly obtain js ticket by concatenating the request in the browser. The access token is the content obtained in the previous step

https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=jsapi
Copy the code

The signature

Use the wechat JS signature tool to complete the signature. Js ticket is the content obtained in the previous step, and other fields can be configured at will

Introduction of js – SDK

<script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
Copy the code

Configuration initialization

All configurations have been obtained and can be directly configured through wx.config (please refer to the above one by one).

wx.config({
  debug: true.// If debug mode is enabled, the return value of all API calls will be displayed in the client alert. If you want to view the parameters passed in, you can open it in the PC, and the parameter information will be printed in the log.
  appId: 'wx67d99aa823b30aad'.// Mandatory, the unique identifier of the public account
  timestamp: '1618020077'.// Mandatory to generate the timestamp of the signature
  nonceStr: 'test'.// Mandatory to generate a random string of signatures
  signature: '2c3b95b3c8b2a2d701688e979d8815d63017dee0'.// Mandatory, signature
  jsApiList: ['getLocation'] // Mandatory, a list of JS interfaces to be used
});
Copy the code

Use JS-SDK capabilities

wx.ready(() = > {
    wx.getLocation({
        // ...})});Copy the code

Wechat public number development tool browse