| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import wx from 'weixin-js-sdk'
- // const url = (window.location.href.split('index.html')[0])+'index.html'
- let url = window.location.href.split('#')[0]
- url = url.indexOf('?') > -1 ? encodeURIComponent(url) : url
- export const shareConfig = (shareData, vm) => {
- vm.$u.api.wxInfo.getWxShareData({
- url
- }).then(res => {
- wx.config({
- debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
- appId: res.appId, // 必填,公众号的唯一标识
- timestamp: res.timestamp, // 必填,生成签名的时间戳
- nonceStr: res.nonceStr, // 必填,生成签名的随机串
- signature: res.signature, // 必填,签名
- jsApiList: [
- "updateAppMessageShareData",
- "updateTimelineShareData",
- 'wx-open-launch-weapp',
- ],
- openTagList: ['wx-open-launch-weapp']
- });
- //分享到好友
- wx.ready(function() {
- wx.updateAppMessageShareData({
- ...shareData,
- success: function() {
- console.log("配置成功1");
- }
- })
- });
- //分享到朋友圈
- wx.ready(function() {
- wx.updateTimelineShareData({
- ...shareData,
- success: function() {
- console.log("配置成功2");
- },
- })
- });
- wx.error(function(res) {
- console.log(res);
- });
- })
- }
|