zoukankan      html  css  js  c++  java
  • vue history模式下的微信分享

    // 微信验证
    export function requireConfig() {
      let url = window.location.href
    
      systemApi.wxoption({
        url: url
      }).then(res => {
        if (res.code === 200) {
          wx.config({
            debug: false,
            appId: res.data.appid, // 必填,企业号的唯一标识,此处填写企业号corpid
            timestamp: res.data.timestamp, // 必填,生成签名的时间戳
            nonceStr: res.data.nonceStr, // 必填,生成签名的随机串
            signature: res.data.signature, // 必填,签名,见附录1
            jsApiList: [
              'onMenuShareAppMessage',
              'onMenuShareTimeline'
            ]
          })
        }
      })
    }
    
    // 验证分享
    export function requireShare(title, desc, link, imgUrl) {
      let u = navigator.userAgent
      // 安卓需要重新验证
      if (u.indexOf('Android') > -1) {
        requireConfig()
      }
      wx.ready(function() {
        // 分享给朋友
        wx.onMenuShareAppMessage({
          title: title, // 分享标题
          desc: desc, // 分享描述
          link: `https://www.baidu.com${link}`, // 分享链接
          imgUrl: imgUrl, // 分享图标
          success: function() {
            // 用户确认分享后执行的回调函数
          },
          cancel: function() {
            // 用户取消分享后执行的回调函数
          }
        })
        // 分享给朋友圈
        wx.onMenuShareTimeline({
          title: title, // 分享标题
          link: `https://www.baidu.com${link}`, // 分享链接
          imgUrl: imgUrl, // 分享图标
          success: function() {
            // 用户确认分享后执行的回调函数
          },
          cancel: function() {
            // 用户取消分享后执行的回调函数
          }
        })
      })
    }
    App.vue
    
    // 微信分享
    requireConfig()
    
    
    
    其它需要使用分享的页面
    
    // 分享
          requireShare(
            '学堂',
            '学堂',
            `/course/index`,
            'http://share.baidu.com/pic.png'
          )
  • 相关阅读:
    使用fiddler对手机APP进行抓包
    接口测试xml格式转换成json
    python datetime笔记
    python time模块详解
    python time相关操作
    2013流行Python项目汇总
    大象的崛起!Hadoop七年发展风雨录
    利用Mahout实现在Hadoop上运行K-Means算法
    20个开源项目托管站点推荐
    有用的国外开源项目网址
  • 原文地址:https://www.cnblogs.com/lanshengzhong/p/10308184.html
Copyright © 2011-2022 走看看