export default function Share(config){ window.wx.config({ debug: false, // 开启调试模式 appId: config.appid, // 必填,公众号的唯一标识 timestamp: config.timestamp, // 必填,生成签名的时间戳 nonceStr: config.nonceStr, // 必填,生成签名的随机串 signature: config.signature, // 必填,签名,见附录1 jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage'], // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }); } Share.prototype = { constructor:Share, init(config){ this.imgUrl = config.imgUrl; this.link = config.link; this.description = config.description; this.title = config.title; window.wx.ready(()=>{ this.toFriend(); this.toTimeline(); }); window.wx.error(res=>{ alert(`${res.errMsg}`) }); }, toFriend(){ window.wx.onMenuShareAppMessage({ imgUrl: this.imgUrl, link: this.link, title: this.title, desc: this.description, success: function () { // 用户确认分享后执行的回调函数 alert('success') }, }); }, toTimeline() { window.wx.onMenuShareTimeline({ imgUrl: this.imgUrl, link: this.link, title: this.title, desc: this.description, success: function () { // 用户确认分享后执行的回调函数 alert('succes11s') }, }); } }
|