share.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import wx from 'weixin-js-sdk'
  2. // const url = (window.location.href.split('index.html')[0])+'index.html'
  3. let url = window.location.href.split('#')[0]
  4. url = url.indexOf('?') > -1 ? encodeURIComponent(url) : url
  5. export const shareConfig = (shareData, vm) => {
  6. vm.$u.api.wxInfo.getWxShareData({
  7. url
  8. }).then(res => {
  9. wx.config({
  10. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  11. appId: res.appId, // 必填,公众号的唯一标识
  12. timestamp: res.timestamp, // 必填,生成签名的时间戳
  13. nonceStr: res.nonceStr, // 必填,生成签名的随机串
  14. signature: res.signature, // 必填,签名
  15. jsApiList: [
  16. "updateAppMessageShareData",
  17. "updateTimelineShareData",
  18. 'wx-open-launch-weapp',
  19. ],
  20. openTagList: ['wx-open-launch-weapp']
  21. });
  22. //分享到好友
  23. wx.ready(function() {
  24. wx.updateAppMessageShareData({
  25. ...shareData,
  26. success: function() {
  27. console.log("配置成功1");
  28. }
  29. })
  30. });
  31. //分享到朋友圈
  32. wx.ready(function() {
  33. wx.updateTimelineShareData({
  34. ...shareData,
  35. success: function() {
  36. console.log("配置成功2");
  37. },
  38. })
  39. });
  40. wx.error(function(res) {
  41. console.log(res);
  42. });
  43. })
  44. }