Micro-Letter JS Interface Summary and use of detailed _javascript skills

Source: Internet
Author: User

Basic description

Instructions for use

1. Introduction of JS File
In the need to call the JS interface page to introduce the following JS file, (support HTTPS): Http://res.wx.qq.com/open/js/jweixin-1.0.0.js

Note: Supports loading using the Amd/cmd standard module loading method

2. Injection Config Config interface
All pages that need to use JSSDK must first inject configuration information, or they will not be able to invoke (the same URL needs to be invoked only once, and the Web app for the spa that changes the URL can be invoked each time the URL changes).

Copy Code code as follows:

Wx.config ({
Debug:true,//Turn on debug mode, call the return value of all APIs will be in the client alert, to see the incoming parameters, can be opened on the PC side, the parameter information will be typed through the log, only on the PC side will print.
AppId: ',//required, unique identification of public number
Timestamp:,//required, generate signature timestamp
NONCESTR: ',//must fill, generate signed random string
Signature: ",//must be filled in, signed, see Appendix 1
Jsapilist: []//must fill in, need to use the JS interface list, all JS interface list See Appendix 2
});

3. Verify through the Ready interface

Copy Code code as follows:

Wx.ready (function () {

Config information is validated after the Ready method is executed, all interface calls must be the result of the Config interface, config is a client's asynchronous operation, so if you need to call the relevant interface when the page is loaded, The relevant interfaces must be called in the ready function to ensure proper execution. For interfaces that are invoked when a user fires, they can be called directly and do not need to be placed in the ready function.
});

4. Verify failure Error interface

Copy Code code as follows:

Wx.error (function (res) {
Config information validation failure performs an error function, such as a signature expiration that causes validation to fail, a specific error message that can be viewed in debug mode of Config, or in the returned res parameter, where spa can update the signature.
});

Interface Invocation Description
All interfaces are invoked through the WX object (which can also be used with the Jweixin object), which is an object that, in addition to the parameters that each interface needs to pass, has the following general parameters:

Success: A callback function that executes when an interface call succeeds.
Fail: A callback function that executes when an interface call fails.
Complete: A callback function that executes when an interface call completes, regardless of success or failure.
Cancel: When the user clicks on the cancellation function, only some of the user's cancellation APIs will be used.
Trigger: A method that triggers when the button clicks on the menu, which supports only the relevant interfaces in menu.

Each of these functions comes with a parameter, the type is an object, in addition to the data returned by each interface itself, there is a common attribute errmsg, whose value is formatted as follows:

When the call succeeds: "Xxx:ok" where xxx is the calling interface name
When user cancels: "Xxx:cancel", where xxx is the name of the interface called
When a call fails: its value is a specific error message

Base interface
Determines whether the current client version supports the specified JS interface

Copy Code code as follows:

Wx.checkjsapi ({
Jsapilist: [' chooseimage ']//need to detect the JS interface list, all JS interface list See Appendix 2,
Success:function (res) {
Returns as a key-value pair, the available API value is true, and cannot be used as false
such as: {"Checkresult": {"Chooseimage": true}, "ErrMsg": "Checkjsapi:ok"}

});

Sharing interface

Get "Share to Circle" button click Status and custom Share content interface

Copy Code code as follows:

Wx.onmenusharetimeline ({
Title: ',//share titles
Link: ',//share links
Imgurl: ",//Share icon
Success:function () {
callback function executed after user confirms share
},
Cancel:function () {
callback function executed after user cancels sharing
}
});

Get "Share to Friend" button click Status and custom Share content interface

Copy Code code as follows:

Wx.onmenushareappmessage ({
Title: ',//share titles
Desc: ",//Share description
Link: ',//share links
Imgurl: ",//Share icon
Type: ',//share types, music, video or link, do not fill in the default link
Dataurl: ',//if type is music or video, provide data link, default is null
Success:function () {
callback function executed after user confirms share
},
Cancel:function () {
callback function executed after user cancels sharing
}
});

Get "Share to QQ" button click State and custom Sharing content interface

Copy Code code as follows:

WX.ONMENUSHAREQQ ({
Title: ',//share titles
Desc: ",//Share description
Link: ',//share links
Imgurl: '//Share icon
Success:function () {
callback function executed after user confirms share
},
Cancel:function () {
callback function executed after user cancels sharing
}
});

Get "share to Tencent Weibo" button click Status and custom Share content interface

Copy Code code as follows:

Wx.onmenushareweibo ({
Title: ',//share titles
Desc: ",//Share description
Link: ',//share links
Imgurl: '//Share icon
Success:function () {
callback function executed after user confirms share
},
Cancel:function () {
callback function executed after user cancels sharing
}
});

Image interface

Take a picture or select an interface from a mobile album

Copy Code code as follows:

Wx.chooseimage ({
Success:function (res) {
var localids = Res.localids; Returns a list of local IDs for the selected photos, localid can display pictures as the SRC attribute of the IMG tag
}
});

Preview Picture Interface

Copy Code code as follows:

Wx.previewimage ({
Current: ',//link to the currently displayed picture
URLs: []//List of picture links to preview
});

Upload Image interface

Copy Code code as follows:

Wx.uploadimage ({
Localid: ',//The local ID of the picture that needs to be uploaded, obtained by the Chooseimage interface
isshowprogresstips:1//defaults to 1, showing progress tips
Success:function (res) {
var serverid = Res.serverid; Returns the server-side ID of a picture
}
});

Note: Use the micro-letter download multimedia file interface Download uploaded pictures, the ServerID is media_id, reference documents. /12/58bfcfabbd501c7cd77c19bd9cfa8354.html

Download Picture interface

Copy Code code as follows:

Wx.downloadimage ({
ServerID: ',//the server-side ID of the picture that needs to be downloaded, obtained by the Uploadimage interface
isshowprogresstips:1//defaults to 1, showing progress tips
Success:function (res) {
var localid = Res.localid; Returns the local ID after the picture is downloaded
}
});

Audio interface

Start Recording interface

Copy Code code as follows:

Wx.startrecord ();

Stop Recording Interface

Copy Code code as follows:

Wx.stoprecord ({
Success:function (res) {
var localid = Res.localid;
}
});

Monitor audio to automatically stop the interface

Copy Code code as follows:

Wx.onvoicerecordend ({
A complete callback is performed when the recording time exceeds one minute without stopping
Complete:function (res) {
var localid = Res.localid;
}
});

Play Voice interface

Copy Code code as follows:

Wx.playvoice ({
Localid: '//local ID of the audio to be played, obtained by the Stoprecord interface
});

Pause Playback Interface

Copy Code code as follows:

Wx.pausevoice ({
Localid: '//local ID of audio to be paused, obtained by Stoprecord interface
});


Stop Playback Interface

Copy Code code as follows:

Wx.stopvoice ({
Localid: '//local ID of audio to be stopped, obtained by Stoprecord interface
});

Monitor Voice Playback Complete interface

Copy Code code as follows:

Wx.onvoiceplayend ({
ServerID: ',//the server-side ID of the audio to be downloaded, obtained by the Uploadvoice interface
Success:function (res) {
var localid = Res.localid; Returns the local ID of the audio
}
});

Upload Voice interface

Copy Code code as follows:

Wx.uploadvoice ({
Localid: ',//local ID of the audio to be uploaded, obtained by the Stoprecord interface
isshowprogresstips:1//defaults to 1, showing progress tips
Success:function (res) {
var serverid = Res.serverid; Returns the server-side ID of the audio
}
});

Note: The use of micro-letter download multimedia file interface to download the voice of the upload, the ServerID is media_id, reference documents. /12/58bfcfabbd501c7cd77c19bd9cfa8354.html

Download Voice interface

Copy Code code as follows:

Wx.downloadvoice ({
ServerID: ',//the server-side ID of the audio to be downloaded, obtained by the Uploadvoice interface
isshowprogresstips:1//defaults to 1, showing progress tips
Success:function (res) {
var localid = Res.localid; Returns the local ID of the audio
}
});

Intelligent interface

Identify the audio and return the recognition result interface

Copy Code code as follows:

Wx.translatevoice ({
Localid: ',//local ID of the audio to be identified, obtained by the recording-related interface
Isshowprogresstips:1,//defaults to 1, showing progress tips
Success:function (res) {
alert (Res.translateresult); Results of speech recognition
}
});

Device information

Get Network State interface

Copy Code code as follows:

Wx.getnetworktype ({
Success:function (res) {
var networktype = Res.networktype; Return network type 2g,3g,4g,wifi
}
});

Location

Use the micro-letter built-in map to view the location interface

Copy Code code as follows:

Wx.openlocation ({
latitude:0,//latitude, floating-point number, range 90 ~-90
longitude:0,//longitude, floating-point number, range 180 ~-180.
Name: ',//location name
Address: ",//Details
Scale:1,//Map zoom level, reshape value, range from 1~28. Default to Maximum
Infourl: "//The hyperlink displayed at the bottom of the view position interface, click to jump
});

Get the Geography interface

Copy Code code as follows:

Wx.getlocation ({
timestamp:0,//Position signature timestamp, available only if a compatible 6.0.2 version is required
NONCESTR: ',//position signature random string, available only before compatible 6.0.2 versions are required
Addrsign: ',//location signature, available only prior to compatibility with 6.0.2 versions, as detailed in Appendix 4
Success:function (res) {
var longitude = res.longitude; Latitude, floating-point number, range 90 ~-90
var latitude = res.latitude; Longitude, floating-point number, range 180 ~-180.
var speed = Res.speed; Speed, measured in meters per second
var accuracy = res.accuracy; Position accuracy
}
});

Interface operation

Copy Code code as follows:

Hide the upper right corner menu interface
Wx.hideoptionmenu ();
Display the upper right corner menu interface
Wx.showoptionmenu ();
Closes the current page window interface
Wx.closewindow ();
Bulk Hide Function Button interface
Wx.hidemenuitems ({
Menulist: []//To hide menu items, all menus are shown in appendix 3
});
Bulk Display Function Button interface
Wx.showmenuitems ({
Menulist: []//To display the menu items, all menu items see Appendix 3
});
Hide all non-basic button interfaces
Wx.hideallnonbasemenuitem ();
Show All Function button interfaces
Wx.showallnonbasemenuitem ();
Micro-letter Sweep
To adjust the micro-letter sweep interface
Wx.scanqrcode ({
Desc: ' Scanqrcode desc ',
needresult:0,//defaults to 0, scan results by micro-letter processing, 1 direct return scan results,
ScanType: ["QRCode", "BarCode"],//can specify a sweep two-dimensional code or a one-dimensional code, the default both have
Success:function () {
var result = Res.resultstr; When the Needresult is 1 o'clock, the result of the sweep code returns
}
});

Harvest Address

Edit Receipt Address interface

Copy Code code as follows:

Wx.editaddress (
timestamp:0,//Position signature timestamp, available only if a compatible 6.0.2 version is required
NONCESTR: ',//position signature random string, available only before compatible 6.0.2 versions are required
Addrsign: ',//location signature, available only prior to compatibility with 6.0.2 versions, as detailed in Appendix 4
Success:function (res) {
var userName = Res.username; Consignee name
var telnumber = Res.telnumber; Consignee Telephone
var postalCode = Res.postalcode; Zip
var provincename = Res.provincename; GB receiving address first level address
var cityname = Res.cityname; GB receiving address second level address
var countryname = Res.countryname; GB receiving address third level address
var address = res.address; Detailed delivery address information
var nationalcode = Res.nationalcode; Delivery address Country Code
}
});

Get the nearest delivery address interface

Copy Code code as follows:

Wx.getlatestaddress ({
timestamp:0,//Position signature timestamp, available only if a compatible 6.0.2 version is required
NONCESTR: ',//position signature random string, available only before compatible 6.0.2 versions are required
Addrsign: ',//location signature, available only prior to compatibility with 6.0.2 versions, as detailed in Appendix 4
Success:function (res) {
var userName = Res.username; Consignee name
var telnumber = Res.telnumber; Consignee Telephone
var postalCode = Res.postalcode; Zip
var provincename = Res.provincename; GB receiving address first level address
var cityname = Res.cityname; GB receiving address second level address
var countryname = Res.countryname; GB receiving address third level address
var address = res.address; Detailed delivery address information
var nationalcode = Res.nationalcode; Delivery address Country Code
}
});

Little Faith Store

Jump micro-Credit Product page interface

Copy Code code as follows:

Wx.openproductspecificview ({
ProductId: ',//Product ID
ViewType: '//0. Default value, general merchandise details page 1. Sweep the Merchandise Details page 2. Shop Details page
});

Micro-credit card voucher

Adjust the coupon list for the store and get the user selection list

Copy Code code as follows:

Wx.choosecard ({
Shopid: ',//Store ID
Cardtype: ',//card voucher type
Cardid: ',//coupon ID
timestamp:0,//card voucher signature Timestamp
NONCESTR: ",//Card voucher signature Random string
Cardsign: ",//Card voucher signature, see Appendix 6
Success:function (res) {
var cardlist= res.cardlist; User-selected Coupon list information
}
});

Bulk Add Card interface

Copy Code code as follows:

Wx.addcard ({
Cardlist: [{
Cardid: ',
Cardext: '
The card list you want to add
Success:function (res) {
var cardlist = res.cardlist; Added coupon list information
}
});

To view the card coupon interface in a micro-credit card package

Copy Code code as follows:

Wx.opencard ({
Cardlist: [{
Cardid: ',
Code: "
}]//need to open the card list
});

Micro-Credit Payment

Initiate a micro-letter payment Request

Copy Code code as follows:

Wx.choosewxpay ({
timestamp:0,//payment signature Timestamp
NONCESTR: ',//payment signature random string
Package: ',//order Details extension string, see Appendix 5
Paysign: ',//payment signature, see Appendix 5
});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.