H5页面在微信端的分享

1、获取基本信息
2、实现
1)、页面引入JS-SDK文件
2)、基本配置
wx.config({debug: false,// 是否开启调试模式appId: appid,//appidtimestamp: timestamp,// 时间戳nonceStr: noncestr,// 随机字符串signature: signature,// 签名jsApiList:['onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','onMenuShareWeibo','onMenuShareQZone']// 需要使用的JS接口列表})
3)、使用
wx.ready(()=> {// 分享给好友wx.onMenuShareAppMessage({title: title, // 分享标题desc: desc, // 分享描述link: link, // 分享链接imgUrl: imgUrl, // 分享图标success: ()=> {doShareDone()},cancel: ()=> {doShareCancel()}})// 分享到朋友圈wx.onMenuShareTimeline({title: title, // 分享标题link: link, // 分享链接imgUrl: imgUrl, // 分享图标success: ()=> {doShareDone()},cancel: ()=> {doShareCancel()}})})// 分享成功回调function doShareDone() {console.log("分享成功")}// 取消分享回调function doShareCancel() {console.log("取消了分享")}
3、调试
4、遇到的问题及解决方案
1)、Uncaught TypeError: Cannot read property 'config' of undefined
2)、Uncaught (in promise) TypeError: Cannot read property 'ready' of undefined
3)、invalid signature
解决:如果文档里的方法都没有解决这个问题,还有一种方法,先设置一种最基础的配置,使其config ok,然后再设置一遍自己需要的有各种参数的分享文案,这样能绕过配置,成功分享。

评论
