In the recent project, a new requirement was added: after sharing a link with friends on wechat, open the link to jump to wechat mini program. As a result, I opened the development document of wechat: I investigated two ways. The first way is to generate OpenLink according to the interface provided by wechat platform (by obtaining the URL scheme code, it can achieve “small program pulling business scenarios such as SMS, email, external web page and wechat”). , the other is to use the open label WX-open-launch-app provided by wechat.

Results show

Effect of PC

Mobile effect

The link parameters of the jump are fixed or not carried

If the link you want to jump to does not need to carry parameters or the parameters are fixed, you can directly generate a scheme in the wechat public platform as shown below, and then jump (location.href) to this scheme is ok.

There are two ways to implement jumps

Unfortunately, it’s not that simple. I need to carry a dynamically generated parameter key. As mentioned above, there are two ways to get the scheme we need.

First said the way I use the first step on the hole, the first way to watch others say there may be internal browser does not support android system WeChat jump straight (cache), so I think we can together behind the links on a timestamp parameter and then generate a scheme to jump (no real attempt, A solution we don’t know if it will work). However, I have tested many Android phones and all support jump, probably because the Scheme code I generated carries dynamic parameters.

As for the second one, I did not adopt it, on the one hand, because the wechat cloud development service needs to be paid, on the other hand, the process is troublesome!! Therefore, the first method is adopted to generate OpenLink jump according to the interface provided by wechat.

Obtain the URL scheme to redirect

The documentation is clear. First, we need to generate the scheme code for the generated applet based on the access_token and jump_wXA parameters

After a general understanding, I sent the link of the document to the backend help to provide me with an interface to return scheme parameters, and then get the Scheme URL to jump to. The front end can easily look at the document processing ~~~

The front-end code

// Jump applet based on key and shared page path
			getScheme(key){
				getSchemeUrl({
					key: key,
					path: 'pages/companyHomePage/jobDetails/index'
				}).then(res= > {
					this.schemeUrl = JSON.parse(res.data.scheme).openlink; // Get schemeUrl
					console.log(this.schemeUrl);
					location.href = this.schemeUrl;
					console.log(this.curKey);
				}).catch(err= > {
					console.log(err); })},Copy the code

Interface response: