码迷,mamicode.com
首页 > 微信 > 详细

微信分享

时间:2019-06-27 16:25:22      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:工具   desc   link   Once   开发者   tle   调用   rip   java   

找到已有公众号的appid,根据这个appid和url(encodeURIComponent(window.location.href)当前页面的url)向后端发起请求,拿到配置所需要的参数:timestamp、noncestr和signature等。

页面引入JS-SDK文件,通过script标签,引入微信官网的JS-SDK文件:
<script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js" type="text/javascript"></script>

基本配置:

wx.config({
  debug: false, // 是否开启调试模式
  appId: appid, //appid
  timestamp: timestamp, // 时间戳
  nonceStr: noncestr, // 随机字符串
  signature: signature, // 签名
  jsApiList: [
    onMenuShareTimeline,
    onMenuShareAppMessage,
    onMenuShareQQ,
    onMenuShareWeibo,
    onMenuShareQZone
  ] // 需要使用的JS接口列表
})

 

调用:

wx.ready(function(){
  // 分享给好友
  wx.onMenuShareAppMessage({
    title: title, // 分享标题
    desc: desc, // 分享描述
    link: link, // 分享链接
    imgUrl: imgUrl, // 分享图标
    success: function () {
      doShareDone()
    },
    cancel: function () {
      doShareCancel()
    }
  })
  
 // 分享到朋友圈
  wx.onMenuShareTimeline({
    title: title, // 分享标题
    link: link, // 分享链接
    imgUrl: imgUrl, // 分享图标
    success: function () {
      doShareDone()
    },
    cancel: function () {
      doShareCancel()
    }
  })
})

调试:

wx.config里的debug字段设置为true时,就可以进行调试。调试要用到微信开发者工具,选择公众号网页项目,输入页面地址就可以了。

转载:https://segmentfault.com/a/1190000016199418

微信分享

标签:工具   desc   link   Once   开发者   tle   调用   rip   java   

原文地址:https://www.cnblogs.com/xjy20170907/p/11097455.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!