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'
          )
  • 相关阅读:
    sql server报【将截断字符串或二进制数据】错误
    消息队列的一些知识
    excel中添加下拉候选
    君生我未生,我生君已老
    分库分表的几个面试题
    sql server判断表存在
    vue定义data的三种方式与区别
    sql server多表关联update
    使用CodeMirror在浏览器中实现编辑器的代码高亮效果
    Jquery easyui Tree的简单使用
  • 原文地址:https://www.cnblogs.com/lanshengzhong/p/10308184.html
Copyright © 2011-2022 走看看