0, the main content first

Into the pit

In wechat web page development, use JSSDK to customize shared content. IOS custom sharing works, android custom sharing does not work, but wx.config and other configurations are OK. The JSSDK version I’m using is 1.4.0. Share API is updateAppMessageShareData.

By the way. When using the latest sharing API, wechat will automatically add parameters at the end of our sharing links, which will cause parsing problems when we pass parameters. For example, the link we configured is: https://test.com?id=11. When shared, the link becomes: https://test.com?from=singlemessage? Id =11. This can cause problems when we take parameters from links. But there’s a pattern to it. Is it in? To insert its own parameter before the. So our argument is the last one, right? The following code is just to illustrate the idea, specific application must be to judge a variety of situations, from the URL address to obtain parameters of these basic skills needless to say) :

    let paramsArray = window.location.href.split("?");
    let myParams = paramsArray[paramsArray.length - 1]; // Our parameters are here
Copy the code

Fill in the pit

Finally, it was found to be caused by the use of the latest version of the library’s new sharing API, which was also proposed in the wechat community, but is still unresolved. So the only way is not to use the version and the new sharing API. OnMenuShareAppMessage 1.3.3 is recommended. The official documentation warns that these older apis will soon be obsolete. However, due to the instability of the new API and the lack of a specific time frame, it will take some time to scrap the previous API. So I have the same problem as me. Android phones cannot customize sharing, IOS phones can, or other problems. Please try to see if there is a version problem, and provide ideas for your reference

After reading this, you will fully understand the main content of the article. If your time is precious, you can leave now. If you’re interested, you can continue to listen to my story.

Let’s begin the story in earnest

1. Pit entering process

In the recent development project, there is a wechat custom sharing function, because I have done wechat webpage development before, I feel small case, introduce JSSDK, back end to provide configuration interface, call SDK under wx.config configuration, configure the API needed in wx.ready, such as sharing to wechat friends, done.

Start work, after all, the last development of wechat web page is almost a year, JSSDK version do not know how much update, first go to the official website to see the document wechat JS-SDK documentation. At first glance, versions are all up to 1.4.0. This function mainly uses the share interface, skip to the share interface to see

Please note that the original wx.onMenuShareTimeline, wx.onMenuShareAppMessage, wx.onMenuShareQQ, and wx.onMenuShareQZone interfaces will be abandoned. Migration as soon as possible, please use the client 6.7.2 and JSSDK version 1.4.0 above support wx. UpdateAppMessageShareData, updateTimelineShareData interface.

The existing sharing interfaces of wx.onMenuShareTimeline, wx.onMenuShareAppMessage, wx.onMenuShareQQ and wx.onMenuShareQZone will be abandoned. Instead is wx updateAppMessageShareData, updateTimelineShareData. At the same time, sharing to wechat friends and sharing to QQ friends merged into one interface, sharing to moments and sharing to QQ zone merged into one interface.

In this case, you’ll want to use version 1.4.0 and use the latest API.

According to the official documentation, what follows is a wave of aggressive actions, and then you test yourself on your IOS phone when it’s okay

Tip: It is required that the shared link domain name or path must be consistent with the JS security domain name corresponding to the current page. Because the interface may be the same domain name, Charles map Remote is used for proxy to facilitate local testing and local development

Two, find the problem

I only tested it on my IOS phone. After the test, the test students found that there was no problem with IOS custom sharing, but there was a problem with android custom sharing to wechat friends and wechat space. And Android phone to share QQ to share QQ space is no problem.

Summary pit is: Android mobile phone to share wechat friends, wechat space is not good. Anything else is fine

Third, filling holes

I have been full of confidence in the code I wrote, but I didn’t believe my test classmates when they mentioned that there was a bug. I thought it was an environmental problem. Later found that I was looking down on wechat, wechat development since ancient times pit, or obediently to find what is caused by the problem

First, turn on debug mode

Wx. config returns OK, and the related API configuration also returns OK, indicating that the JSSDK and related interface configuration is ok.

Then, start from scratch, configuration first write dead, according to the document to write the most standard try, or still line.

Next, there are all kinds of Google, some people have raised the corresponding questions, there are comrades in the wechat development community feedback (2018-09-29), and there are also official staff to answer, but in the end there is no answer.

Finally, take a look at those custom sharing successful demo. When I looked at it, THERE was no difference. When I looked at it more closely, I suddenly realized that the API used by the successful demo was different from that used by me. Ok, another wave of aggressive action, 1.3.3 for the next version. And then the test, as expected, can be tested, and then test let test students test also passed. Sure enough, the latest API is not stable.

Four,

1. The latest version of wechat JSSDK is 1.4.0. First, its requirements for wechat customers are 6.7.2. That’s a little high

2. Second, the stability of the latest version remains to be seen

3, in the use of external public library, have to pay attention to the related version of the problem, Webpack/NPM often due to the version of the problem

In short, android phones cannot customize sharing due to using the latest version of JSSDK and related apis. Use the lower version libraries and apis.

Note that I am writing this post on 2019-01-08, wechat may fix this problem later, and then we can consider using the new API, and some will be deprecated, just to give you a solution to the problem. Please correct any questions.