// #ifdef H5 import api from '@/api/api.js' import config from "../config.js" import jWeixin from './lib/jweixin-module.js' function share() { //微信分享 //获取签名 let data = { // location.href.split('#')[0]) // url: Vue.prototype.$config.redirect + '/#/' url: location.href.split('#')[0] } api('getSignPackage', data).then(res => { if (res.code == 200) { let { appId, nonceStr, signature, timestamp } = res.result jWeixin.config({ debug: false, appId: appId, nonceStr: nonceStr, signature: signature, timestamp: timestamp, jsApiList: [ 'updateTimelineShareData', 'updateAppMessageShareData', 'onMenuShareWeibo', 'getLocation', 'chooseWXPay', 'requestMerchantTransfer', 'checkJsApi', 'scanQRCode', ], success: function () { console.log('配置成功'); } }); jWeixin.ready(function () { // 微信分享的数据 var shareData = { "link": addQueryParams(data.url), "desc": "布丁小说", "title": "布丁小说", imgUrl: uni.getStorageSync('login_logo'), success: function () { //分享成功可以做相应的数据处理 console.log('注册分享成功'); // uni.showToast({ // mask: true, // duration: 1000, // title: '注册分享成功', // }); }, fail : function (e){ console.log(e); } }; //分享微信朋友圈内容设置 jWeixin.updateTimelineShareData(shareData); //分享给朋友内容设置 jWeixin.updateAppMessageShareData(shareData); //分享到微博内容设置 jWeixin.onMenuShareWeibo(shareData); }); jWeixin.error(function (err) { console.error(err); // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。 }) } }) } function addQueryParams(url) { if (url) { //获取用户id let userInfo = localStorage.getItem('userInfo') ? JSON.parse(localStorage.getItem('userInfo')) : null if (userInfo) { url += `?inviter=${userInfo.id}` } } return url } export default share // #endif // #ifndef H5 export default function(){} // #endif