Uni-app development experience sharing seventeen: developing WeChat official account (H5) JSSDK usage

Time:2021-4-20

Because this jssdk has been cheated by the uni app for many days, the author said that it supports version 1.4, but I have not supported the two new sharing methods of version 1.4.

Finally, I had to give up and look forward to updating it.

Basic usage:
Step 1 – Download usage
Download address: https://unpkg.com/[email protected]/out/index.js

Project reference:

Create a new module under the project and put it under the module.
main . JS reference:

var jweixin = require('jweixin-module')

		// Get the configuration of WeChat official account
		uni.request({
		
			url: 'xxxxxxxxxxx',
			dataType: 'text',
			data: {
				url: window.location.href.split('#')[0]
			},
			success: res => {
				var s = JSON.parse(res.data);
				console.log(s.data);
				
				 jweixin.config({
					 debug :  false , //  Start debugging mode , The return values of all the API calls will be alerted on the client side. To view the incoming parameters, you can open them on the PC side, and the parameter information will be printed out through the log, only on the PC side.
					 appId: s. data.appId // required, the only sign of the official account.
					 timestamp: s. data.timestamp , // required. Generate the signature timestamp
					 nonceStr :  s . data . nonceStr , //  Required, generate random string of signature
					 signature: s. data.signature.toLowerCase (), // required, signature, see Appendix 1
					 jsApiList: ["onMenuShareTimeline", "onMenuShareAppMessage","onMenuShareQQ","onMenuShareWeibo","onMenuShareQZone"]
				});	
				
				jweixin.ready(function () {

				 //Get the click status of "share to QQ" button and customize the interface for sharing content (about to be abandoned)
				 jweixin.onMenuShareQQ({
					 Title: title, // share the title
					 Desc: DESC, // share description
					 Link: URL, // share link
					 Imgurl: imgurl, // share Icon
					 success: function () {
						 //  Callback function executed after user confirms sharing
					 },
					 cancel: function () {
						 //Callback function executed after user cancels sharing
					 }
				});
				
				//Get the click status of "share with friends" button and customize the shared content interface (about to be abandoned)
				 jweixin.onMenuShareAppMessage({
					 Title: title, // share the title
					 Desc: DESC, // share description
					 Link: URL, // share link
					 Imgurl: imgurl, // share Icon
					 Type: ', // sharing type, music, video or link. If not filled in, the default is link
					 Dataurl: ', // if the type is music or video, the data link should be provided, which is empty by default
					 success: function () {
						 //  Callback function executed after user confirms sharing
					 },
					 cancel: function () {
						 //Callback function executed after user cancels sharing
					 }
				});
				
				//Get the click status of "share to friends" button and customize the interface for sharing content (about to be abandoned)
				 jweixin.onMenuShareTimeline({
					 Title: title, // share the title
					 Desc: DESC, // share description
					 Link: URL, // share link
					 Imgurl: imgurl, // share Icon
					 Type: ', // sharing type, music, video or link. If not filled in, the default is link
					 Dataurl: ', // if the type is music or video, the data link should be provided, which is empty by default
					 success: function () {
						 //  Callback function executed after user confirms sharing
					 },
					 cancel: function () {
						 //Callback function executed after user cancels sharing
					 }
				});
				
				//Get the click status of "share to Tencent Weibo" button and customize the interface for sharing content
				 jweixin.onMenuShareWeibo({
					 Title: title, // share the title
					 Desc: DESC, // share description
					 Link: URL, // share link
					 Imgurl: imgurl, // share Icon
					 Type: ', // sharing type, music, video or link. If not filled in, the default is link
					 Dataurl: ', // if the type is music or video, the data link should be provided, which is empty by default
					 success: function () {
						 //  Callback function executed after user confirms sharing
					 },
					 cancel: function () {
						 //Callback function executed after user cancels sharing
					 }
				});
				
				 //Get the click status of "share to QQ space" button and customize the interface for sharing content (about to be abandoned)
				 jweixin.onMenuShareQZone({
					 Title: title, // share the title
					 Desc: DESC, // share description
					 Link: URL, // share link
					 Imgurl: imgurl, // share Icon
					 Type: ', // sharing type, music, video or link. If not filled in, the default is link
					 Dataurl: ', // if the type is music or video, the data link should be provided, which is empty by default
					 success: function () {
						 //  Callback function executed after user confirms sharing
					 },
					 cancel: function () {
						 //Callback function executed after user cancels sharing
					 }
				});
			});
			},
			fail: err => {
				console.log('request fail', err);
			}
	});

Reproduced in: https://blog.csdn.net/qq_ 24347541/article/details/89710562