WeChat JS-SDK interface list and problem explanation

WeChat JS-SDK interface list and problem explanation

List of all JS interfaces

Version 1.0.0 Interface

onMenuShareTimeline

onMenuShareAppMessage

onMenuShareQQ

onMenuShareWeibo

startRecord

stopRecord

onVoiceRecordEnd

playVoice

pauseVoice

stopVoice

onVoicePlayEnd

uploadVoice

downloadVoice

chooseImage

previewImage

uploadImage

downloadImage

translateVoice

getNetworkType

openLocation

getLocation

hideOptionMenu

showOptionMenu

hideMenuItems

showMenuItems

hideAllNonBaseMenuItem

showAllNonBaseMenuItem

closeWindow

scanQRCode

chooseWXPay

openProductSpecificView

addCard

chooseCard

openCard

List of all menu items

Basic Class

Report: "menuItem:exposeArticle"

Adjust font: "menuItem:setFont"

Day mode: "menuItem:dayMode"

Night Mode: "menuItem:nightMode"

Refresh: "menuItem:refresh"

View public account (added): "menuItem:profile"

View public account (not added): "menuItem:addContact"

Communication

Send to a friend: "menuItem:share:appMessage"

Share to Moments: "menuItem:share:timeline"

Share to QQ: "menuItem:share:qq"

Share to Weibo: "menuItem:share:weiboApp"

Favorites: "menuItem:favorite"

Share to FB: "menuItem:share:facebook"

Protection

Debug: "menuItem:jsDebug"

Edit Tag: "menuItem:editTag"

Delete: "menuItem:delete"

Copy link: "menuItem:copyUrl"

Original page: "menuItem:originPage"

Reading mode: "menuItem:readMode"

Open in QQ Browser: "menuItem:openWithQQBrowser"

Open in Safari: "menuItem:openWithSafari"

Email: "menuItem:share:email"

Some special public accounts: "menuItem:share:brand"

Card voucher extension field and signature generation algorithm

Cards and coupons api_ticket

The card voucher api_ticket is a temporary ticket used to call card voucher related interfaces. It is valid for 7200 seconds and is obtained through access_token. It should be distinguished from jsapi_ticket. Since the number of API calls to obtain the card voucher api_ticket is very limited, frequent refreshes of the card voucher api_ticket will limit API calls and affect your own business. Developers must cache the card voucher api_ticket globally in their own services.

Refer to the following document to obtain access_token (valid for 7200 seconds, developers must cache access_token globally in their own services): ../15/54ce45d8d30b6bf6758f68d2e95bc627.html

Use the access_token obtained in the first step to request the card coupon api_ticket using the http GET method (valid for 7200 seconds, developers must cache the card coupon api_ticket globally in their own services): https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=wx_card

CardExt extension field description

cardExt itself is a JSON string, which is the unique information assigned by the merchant to the card voucher, and contains the following fields:

Fields Is this field required? illustrate
code no The specified card code can only be redeemed once. It is required for cards with the use_custom_code field set to true, but not required for non-custom codes .
OpenID no Specify the recipient's openid. Only this user can receive the card. This field must be filled in for cards with the bind_openid field set to true. This field does not need to be filled in for non-custom openids .
timestamp yes Timestamp, the number of seconds from 00:00:00 on January 1, 1970 to the present, which is the current time, and needs to be converted into a string format;

Generated by the merchant and passed in.

signature yes Signature: The merchant signs the parameters in the interface list in the specified way, using SHA1. For the specific signature scheme, see below. The merchant signs according to the specification and passes it in.
balance no The red envelope balance is in cents. The red envelope type is required (LUCKY_MONEY), and other card or coupon types are not required .

Signature Description

Sort the values ​​of api_ticket (special note: api_ticket is more secure than appsecret and is compatible with appsecret used in old versions of documents as signature credentials), timestamp, card_id, code, openid, and balance in lexicographic order.

Concatenate all parameter strings into one string, encrypt it with sha1, and get the signature.

The timestamp in signature and the timestamp in card_ext must be consistent.

If in the data example, code=23456, timestamp=141231233, card_id=345667, api_ticket=45678, then signature=sha1(14123123323456345667456789)=4F76593A4245644FAE4E1BC940F6422A0C3EC03E.

CardSign cardSign Description

Sort the values ​​of api_ticket (special note: api_ticket is more secure than appsecret and is compatible with appsecret used in old versions of documents as signature credentials), app_id, location_id, times_tamp, nonce_str, card_id, and card_type in lexicographic order.

Concatenate all parameter strings into one string and encrypt it with sha1 to get cardSign.

Appendix 5 - Common Errors and Solutions

When calling the config interface, pass in the parameter debug: true to enable debug mode, and the page will alert an error message. The following are common errors and solutions:

invalid url domain The domain name of the current page is not bound to the appid used. Please make sure that the bound domain name is entered correctly. If a port number is used, the configured bound domain name must also include the port number (one appid can be bound to three valid domain names, see directory 1.1.1).

Invalid signature Signature error. It is recommended to check in the following order:

To confirm that the signature algorithm is correct, you can use the http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=jsapisign page tool to verify.

Confirm that the nonceStr (camel case S in js) and timestamp in config are consistent with the corresponding noncestr and timestamp used in the signature.

Make sure that the url is the complete url of the page (please confirm it in alert(location.href.split('#')[0]) on the current page), including the 'http(s)://' part and the GET parameter part after the '?', but not the part after the '#' hash.

Confirm that the appid in config is consistent with the appid used to obtain jsapi_ticket.

Make sure to cache access_token and jsapi_ticket.

Make sure that the URL you use to sign is obtained dynamically. For dynamic pages, see the PHP implementation in the example code. If it is a static HTML page, the front end uses ajax to pass the URL to the backend for signing. The front end needs to use js to obtain the link of the current page without the '#' hash part (you can use location.href.split('#')[0] to obtain it). Once the page is shared, the WeChat client will add other parameters to the end of your link. If the current link is not obtained dynamically, the signing of the shared page will fail.

The error "the permission value is offline verifying" is because the config is not executed correctly, or the called JSAPI is not passed into the jsApiList parameter of the config. It is recommended to check in the following order:

Confirm that the config is passed correctly.

If the JSAPI is called when the page is loaded, it must be written in the callback of wx.ready.

Make sure the jsApiList parameter of config contains this JSAPI.

permission denied This public account does not have permission to use this JSAPI (some interfaces require authentication before they can be used).

function not exist The current client version does not support this interface. Please upgrade to the new version to experience it.

Why is config:ok in version 6.0.1, but not ok in version 6.0.2 and later? (Because there is no permission verification before version 6.0.2, so config is ok, but this does not mean that the signature in your config is OK. Please check whether the correct signature is generated in 6.0.2 to ensure that config is also ok in higher versions.)

Android users have cancelled sharing in Moments, but the sharing is still successful (WeChat team has fixed this issue and it is now available on Android 6.1)

Cannot share on iOS and Android (please confirm that the public account has been authenticated. Only authenticated public accounts have the permission to share related interfaces. If it has been authenticated, check whether the monitoring interface is triggered in the wx.ready callback function)

Some clients of Android 6.0.2 cannot use the monitoring sharing interface (versions before Android 6.0.2 and after 6.0.2.58 will not have any problems, please download the latest version from the official website weixin.qq.com to experience it)

After the service goes online, you cannot obtain jsapi_ticket, but there is no problem when testing it yourself. (Because access_token and jsapi_ticket must be cached on your own server, otherwise the frequency limit will be triggered after going online. Please make sure to cache the token and ticket to reduce 2 server requests, which can not only avoid triggering the frequency limit, but also speed up your own service. Currently, 10,000 acquisitions are provided for the convenience of testing. After exceeding the threshold, the service will no longer be available. Please make sure to globally cache access_token and jsapi_ticket before the service goes online. Both are valid for 7200 seconds, otherwise once the frequency limit is triggered online, the service will no longer be available).

The image upload interface of some Android versions occasionally gets stuck (this problem exists in the early Android 6.0.2 version, which has been officially fixed. All versions after 6.0.2.58 support it. Please download the latest version from the official website to experience it)

How to upload multiple images in uploadImage (currently only supports uploading one image at a time. To upload multiple images, you need to wait until the previous image is uploaded before calling this interface)

Unable to preview the locally selected image (the chooseImage API itself supports preview, no additional support is needed)

Jump to link b through link a (for example, log in through WeChat authorization first), invalid signature signing failed (the link generated by the background signature is the current link using jssdk, that is, link b after the jump. Please do not use the authorization link for WeChat login for signature calculation. The background signature URL must be the full URL of the current page using jssdk without the '#' part)

A config:fail error occurs (this is caused by incomplete config parameters passed in. Please make sure to pass in the correct appId, timestamp, nonceStr, signature, and jsApiList that needs to be used)

How to download multimedia resources uploaded to WeChat by jsapi to your own server (please refer to the notes of uploadVoice and uploadImage interfaces in the document)

In Android, the serverId uploaded by other devices can be downloaded successfully but cannot be played (the WeChat team has confirmed this problem and has been fixed in Android version 6.1)

Android uploads to WeChat server through jssdk, and the third party then downloads from WeChat to its own server, which will cause noise (the WeChat team has fixed this problem and the backend has been optimized and launched)

After binding the parent domain, are its subdomains also available? (Yes, legal subdomains are fully supported after binding the parent domain)

In Android, when you open a page by scanning, and then call scanQRCode and return data to a third party, you will exit the current page directly (the WeChat team has confirmed this issue and has fixed it in Android 6.1)

In iOS WeChat version 6.1, the external links of shared pictures are not displayed. Only pictures with internal links on the public account page or pictures on the WeChat server can be displayed (the WeChat team has confirmed this problem and will fix it in 6.2)

Do you need to make it compatible with lower versions yourself? (jssdk is compatible with lower versions, and third parties do not need to do more work, but some interfaces are newly introduced in 6.0.2 and can only be called in the new version)

The payment signature of the official account is invalid and the transaction cannot be initiated (please make sure that the jweixin.js you use is the official online version, which can not only reduce user traffic, but also fix some bugs. If you copy it to a third-party server for use, the official will not provide any guarantee for any problems that may arise. For the specific payment signature algorithm, please refer to the JSSDK WeChat Payment column)

Previously, the file type uploaded by WeChat jssdk voice interface was speex, and third parties could not play it directly on their own web pages (the WeChat team confirmed the problem and has solved it online this week. Third parties can download standard amr audio files through the multimedia interface)

Currently, the Android WeChat client does not support the new H5 feature of pushState, so using pushState to implement the web app page will cause signature failure. This problem will be fixed in Android 6.2

<<:  WeChat JS-SDK-Use Permission Signature Algorithm

>>:  WeChat store interface

Recommend

AION Y Plus is a king bomb, with full intelligent driving range

AION Y Plus 610 Smart Driving Edition is launched...

Dr. Mok comments on the trends of 2015: The Internet of Things is still a mess

According to foreign media The Verge, Dr. Mo, a v...

Five rules to start your growth hacking journey

The Origins of Growth Hacking Originated from Sil...

Channel operation strategy, it is not difficult to attract traffic

Many people would ask, why do we spend so much mo...

Equity Incentive and Equity Financing Solutions Class

Resource introduction of equity incentive and equ...

Seven details determine whether you can be a successful entrepreneur

[[154346]] Now is an era of entrepreneurship for ...

5 keywords to help you write a copy with a sense of story

“If you want to build a ship, don’t hire people t...