zoukankan      html  css  js  c++  java
  • uni-app开发经验分享十七: 开发微信公众号(H5)JSSDK 的使用方式

    因为这个jssdk被uni-app坑了好多天,作者说支持1.4版本,但是我用1.4的两个分享的新方法一直不支持。

    最后只能放弃了,期待什么时候能更新上。

    基本的使用方法:
    第一步 - 下载使用方式
    下载地址:https://unpkg.com/jweixin-module@1.4.1/out/index.js

    项目引用:

     项目下新建模块,放在该模块下。
    main.js引用:

    var jweixin = require('jweixin-module')
    
    		//获取微信公众号的配置
    		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, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
    					 appId: s.data.appId, // 必填,公众号的唯一标识
    					 timestamp: s.data.timestamp, // 必填,生成签名的时间戳
    					 nonceStr: s.data.nonceStr, // 必填,生成签名的随机串
    					 signature: s.data.signature.toLowerCase(), // 必填,签名,见附录1
    					 jsApiList: ["onMenuShareTimeline", "onMenuShareAppMessage","onMenuShareQQ","onMenuShareWeibo","onMenuShareQZone"]
    				});	
    				
    				jweixin.ready(function () {
    
    				 //获取“分享到QQ”按钮点击状态及自定义分享内容接口(即将废弃)
    				 jweixin.onMenuShareQQ({
    					 title: title, // 分享标题
    					 desc: desc, // 分享描述
    					 link: url, // 分享链接
    					 imgUrl: imgurl, // 分享图标
    					 success: function () {
    						 // 用户确认分享后执行的回调函数
    					 },
    					 cancel: function () {
    						 // 用户取消分享后执行的回调函数
    					 }
    				});
    				
    				//获取“分享给朋友”按钮点击状态及自定义分享内容接口(即将废弃)
    				 jweixin.onMenuShareAppMessage({
    					 title: title, // 分享标题
    					 desc: desc, // 分享描述
    					 link: url, // 分享链接
    					 imgUrl: imgurl, // 分享图标
    					 type: '', // 分享类型,music、video或link,不填默认为link
    					 dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
    					 success: function () {
    						 // 用户确认分享后执行的回调函数
    					 },
    					 cancel: function () {
    						 // 用户取消分享后执行的回调函数
    					 }
    				});
    				
    				//获取“分享到朋友圈”按钮点击状态及自定义分享内容接口(即将废弃)
    				 jweixin.onMenuShareTimeline({
    					 title: title, // 分享标题
    					 desc: desc, // 分享描述
    					 link: url, // 分享链接
    					 imgUrl: imgurl, // 分享图标
    					 type: '', // 分享类型,music、video或link,不填默认为link
    					 dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
    					 success: function () {
    						 // 用户确认分享后执行的回调函数
    					 },
    					 cancel: function () {
    						 // 用户取消分享后执行的回调函数
    					 }
    				});
    				
    				//获取“分享到腾讯微博”按钮点击状态及自定义分享内容接口
    				 jweixin.onMenuShareWeibo({
    					 title: title, // 分享标题
    					 desc: desc, // 分享描述
    					 link: url, // 分享链接
    					 imgUrl: imgurl, // 分享图标
    					 type: '', // 分享类型,music、video或link,不填默认为link
    					 dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
    					 success: function () {
    						 // 用户确认分享后执行的回调函数
    					 },
    					 cancel: function () {
    						 // 用户取消分享后执行的回调函数
    					 }
    				});
    				
    				 //获取“分享到QQ空间”按钮点击状态及自定义分享内容接口(即将废弃)
    				 jweixin.onMenuShareQZone({
    					 title: title, // 分享标题
    					 desc: desc, // 分享描述
    					 link: url, // 分享链接
    					 imgUrl: imgurl, // 分享图标
    					 type: '', // 分享类型,music、video或link,不填默认为link
    					 dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
    					 success: function () {
    						 // 用户确认分享后执行的回调函数
    					 },
    					 cancel: function () {
    						 // 用户取消分享后执行的回调函数
    					 }
    				});
    			});
    			},
    			fail: err => {
    				console.log('request fail', err);
    			}
    	});	

    转载于:https://blog.csdn.net/qq_24347541/article/details/89710562

  • 相关阅读:
    hdu 5795 A Simple Nim 博弈sg函数
    hdu 5724 Chess 博弈sg+状态压缩
    hdu 3094 A tree game 树上sg
    2017"百度之星"程序设计大赛
    hdu 6134 Battlestation Operational 莫比乌斯反演
    HDU 6143 Killer Names DP+快速密
    HDU 6107 Typesetting 倍增
    HDU 6096 String 排序 + 线段树 + 扫描线
    HDU 6086 Rikka with String AC自动机 + DP
    HDU 6073 Matching In Multiplication dfs遍历环 + 拓扑
  • 原文地址:https://www.cnblogs.com/smileZAZ/p/14185456.html
Copyright © 2011-2022 走看看