WeChat JS-SDK Description-Open Interface Description

WeChat JS-SDK Description-Open Interface Description

Basic interface

Determine whether the current client version supports the specified JS interface

  1. wx.checkJsApi({
  2. jsApiList: ['chooseImage'], // List of JS interfaces that need to be detected. For a list of all JS interfaces, see Appendix 2.
  3. success: function(res) {
  4. // Return as a key-value pair, true for available APIs and false for unavailable APIs
  5. // For example: {"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
  6. });

Note: checkJsApi is a reserved interface newly introduced in client 6.0.2. All interfaces opened in the first phase can be detected without using checkJsApi.

Sharing interface

Please be careful not to engage in any illegal behavior such as inducing sharing. For any behavior of inducing sharing, the public account interface permissions will be permanently revoked. For detailed rules, please see: Frequently Asked Questions about Moments Management.

Get the "Share to Moments" button click status and customize the sharing content interface

  1. wx.onMenuShareTimeline({
  2. title: '', // Share title
  3. link: '', // Share link
  4. imgUrl: '', // share icon
  5. success: function () {
  6. //Callback function executed after the user confirms sharing
  7. },
  8. cancel: function () {
  9. //Callback function executed after the user cancels sharing
  10. }
  11. });

Get the "Share with Friends" button click status and customize the sharing content interface

  1. wx.onMenuShareAppMessage({
  2. title: '', // Share title
  3. desc: '', // Share description
  4. link: '', // Share link
  5. imgUrl: '', // share icon
  6. type: '', // Sharing type, music, video or link, if not filled in, the default is link
  7. dataUrl: '', // If type is music or video, a data link must be provided, empty by default
  8. success: function () {
  9. //Callback function executed after the user confirms sharing
  10. },
  11. cancel: function () {
  12. //Callback function executed after the user cancels sharing
  13. }
  14. });

Get the "Share to QQ" button click status and customize the sharing content interface

  1. x.onMenuShareQQ({
  2. title: '', // Share title
  3. desc: '', // Share description
  4. link: '', // Share link
  5. imgUrl: '' // Share icon
  6. success: function () {
  7. //Callback function executed after the user confirms sharing
  8. },
  9. cancel: function () {
  10. //Callback function executed after the user cancels sharing
  11. }
  12. });

Get the "Share to Tencent Weibo" button click status and customize the sharing content interface

  1. wx.onMenuShareWeibo({
  2. title: '', // Share title
  3. desc: '', // Share description
  4. link: '', // Share link
  5. imgUrl: '' // Share icon
  6. success: function () {
  7. //Callback function executed after the user confirms sharing
  8. },
  9. cancel: function () {
  10. //Callback function executed after the user cancels sharing
  11. }
  12. });

Graphics interface

Interface for taking photos or selecting pictures from mobile phone albums

  1. wx.chooseImage({
  2. success: function (res) {
  3. var localIds = res .localIds; // Returns the local ID list of the selected photo. The localId can be used as the src attribute of the img tag to display the image.
  4. }
  5. });

Preview image interface

  1. wx.previewImage({
  2. current: '', // Currently displayed image link
  3. urls: [] // List of image links to be previewed
  4. });

Upload picture interface

  1. wx.uploadImage({
  2. localId: '', // The local ID of the image to be uploaded, obtained by the chooseImage interface
  3. isShowProgressTips: 1, // Default is 1, show progress tips
  4. success: function (res) {
  5. var serverId = res .serverId; // Returns the server ID of the image
  6. }
  7. });

Note: The uploaded image is valid for 3 days. You can use the WeChat multimedia interface to download the image to your own server. The serverId obtained here is media_id. Please refer to the document../12/58bfcfabbd501c7cd77c19bd9cfa8354.html. The frequency limit of the multimedia file download interface is currently 10,000 times. If you need to increase the frequency, please email [email protected] with the subject of [Apply for multimedia interface call quantity]. Please briefly describe your project, attach a product experience link, and explain the number of users and usage.

Download image interface

  1. wx.downloadImage({
  2. serverId: '', // The server ID of the image to be downloaded, obtained by the uploadImage interface
  3. isShowProgressTips: 1, // Default is 1, show progress tips
  4. success: function (res) {
  5. var localId = res .localId; // Returns the local ID of the downloaded image
  6. }
  7. });

Audio Interface

Start recording interface

  1. wx.startRecord();

Stop recording interface

  1. wx.stopRecord({
  2. success: function (res) {
  3. var localId = res .localId;
  4. }
  5. });

Monitor recording automatic stop interface

  1. wx.onVoiceRecordEnd({
  2. // The complete callback will be executed when the recording time exceeds one minute without stopping
  3. complete: function (res) {
  4. var localId = res .localId;
  5. }
  6. });

Play voice interface

  1. wx.playVoice({
  2. localId: '' // The local ID of the audio to be played, obtained by the stopRecord interface
  3. });

Pause playback interface

  1. wx.pauseVoice({
  2. localId: '' // The local ID of the audio to be paused, obtained by the stopRecord interface
  3. });

Stop Playing Interface

  1. wx.stopVoice({
  2. localId: '' // The local ID of the audio to be stopped, obtained by the stopRecord interface
  3. });

Monitor the voice playback completion interface

  1. wx.onVoicePlayEnd({
  2. success: function (res) {
  3. var localId = res .localId; // Returns the local ID of the audio
  4. }
  5. });

Upload voice interface

  1. wx.uploadVoice({
  2. localId: '', // The local ID of the audio to be uploaded, obtained by the stopRecord interface
  3. isShowProgressTips: 1, // Default is 1, show progress tips
  4. success: function (res) {
  5. var serverId = res .serverId; // Returns the server ID of the audio
  6. }
  7. });

Note: The uploaded voice is valid for 3 days. You can use the WeChat multimedia interface to download the voice to your own server. The serverId obtained here is media_id. Please refer to the document../12/58bfcfabbd501c7cd77c19bd9cfa8354.html. The frequency limit of the multimedia file download interface is currently 10,000 times. If you need to increase the frequency, please email [email protected] with the subject of [Apply for multimedia interface call quantity]. Please briefly describe your project, attach a product experience link, and explain the number of users and usage.

Download Voice Interface

  1. wx.downloadVoice({
  2. serverId: '', // The server ID of the audio to be downloaded, obtained from the uploadVoice interface
  3. isShowProgressTips: 1, // Default is 1, show progress tips
  4. success: function (res) {
  5. var localId = res .localId; // Returns the local ID of the audio
  6. }
  7. });

Smart Interface

Recognize audio and return recognition result interface

  1. wx.translateVoice({
  2. localId: '', // The local ID of the audio to be identified, obtained from the recording related interface
  3. isShowProgressTips: 1, // Default is 1, show progress tips
  4. success: function (res) {
  5. alert(res.translateResult); // Speech recognition result
  6. }
  7. });

Device Information

Get network status interface

  1. wx.getNetworkType({
  2. success: function (res) {
  3. var networkType = res .networkType; // Returns network type 2g, 3g, 4g, wifi
  4. }
  5. });

Location

Use WeChat built-in map to view location interface

  1. wx.openLocation({
  2. latitude: 0, // latitude, floating point number, range is 90 ~ -90
  3. longitude: 0, // Longitude, floating point number, range is 180 ~ -180.
  4. name: '', // location name
  5. address: '', // Address details
  6. scale: 1, // Map zoom level, integer value, ranging from 1 to 28. The default is the maximum
  7. infoUrl: '' // The hyperlink displayed at the bottom of the viewing location interface, you can click to jump
  8. });

Get geographic location interface

  1. wx.getLocation({
  2. success: function (res) {
  3. var latitude = res .latitude; // Latitude, floating point number, range is 90 ~ -90
  4. var longitude = res .longitude; // Longitude, floating point number, range is 180 ~ -180.
  5. var speed = res .speed; // speed in meters per second
  6. var accuracy = res .accuracy; // Position accuracy
  7. }
  8. });

<<:  WeChat JS-SDK Description (1)

>>:  WeChat JS-SDK Description-Open Interface Description (2)

Recommend

Zhuge Liang managed to fool the Eastern Wu just by talking?

Mixed Knowledge Specially designed to cure confus...

About improving operational conversion rate (Part 1)

When users use a product, there are always two op...

A seagull that always wanted to eat some fries swallowed a cell phone one day

There’s a popular cartoon you must have seen: The...

7 Benefits of Data Visualization

Data visualization refers to the presentation of ...

What knowledge do you need to learn to be a programmer?

Anyone who asks this question should be beaten, d...

16 practical tips hidden deep in iPhone, 5-year-old users only know 3 of them

Every time iOS welcomes a major system update, th...

Dismantling the entire process of Yuanqi Forest's layout of private domain

Purpose of case analysis: The number of followers...

A must-read for flu season! The latest flu vaccination guide for 2022 is here

Recently, the Chinese Center for Disease Control ...