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'
          )
  • 相关阅读:
    jdbc详解(三)
    超文本传输协议-HTTP/1.1
    前人栽树,后人擦屁股
    JAVA 读取计算机中相关信息
    POJ 1836-Alignment(DP/LIS变形)
    【Android】自己定义控件实现可滑动的开关(switch)
    加深理解UIView,UIResponder,UIController
    Fuel4d 2.3 公布
    Android中使用IntentService运行后台任务
    POJ2762 Going from u to v or from v to u? 强连通+缩点
  • 原文地址:https://www.cnblogs.com/lanshengzhong/p/10308184.html
Copyright © 2011-2022 走看看