微信公众号分享朋友圈和朋友updateAppMessageShareData

微信公众号分享朋友圈的案例

<!DOCTYPE HTML>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta name="viewport"
       content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
 <meta http-equiv="X-UA-Compatible" content="ie=edge">
 <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
 <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
 <title>标题</title>
</head>
<body>
<script>
 $(document).ready(function () {
// 重点是url后面一定是你当前页面的链接域名,这个很重要,无论分享的链接是不是当前链接都要必须要一样
// 也可以let param = window.location.href.split('#')[0]
// $.get('后端接口?url='+ param).then() $.get(
'https://guess.goldball.info/api/wechat/share?url=https://guess.goldball.info/pages/index/share/share?id=1', '', function (res) { console.log(res.data) wx.config({ debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来。 appId: res.data.appId, // 必填,公众号的唯一标识 timestamp: res.data.timestamp, // 必填,生成签名的时间戳 nonceStr: res.data.nonceStr, // 必填,生成签名的随机串 signature: res.data.signature, jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData'] }); }) wx.ready(function () { wx.updateAppMessageShareData({ title: '标题', desc: '描述文字', link: 'https://guess.goldball.info/#/test?id=1&user_id=1', imgUrl: 'https://www.imooc.com/static/img/index/logo2020.png', success: function () { } }); wx.updateTimelineShareData({ title: '标题', desc: '描述文字', link: 'https://guess.goldball.info/#/test?id=1&user_id=1', imgUrl: 'https://www.imooc.com/static/img/index/logo2020.png', type: 'link', dataUrl: '', success: function () { } }); }); wx.error(function (res) { console.log("shareerror") alert(res.errMsg); }); }) </script> </body> </html> 发送

链接分享:https://blog.csdn.net/weixin_40716786/article/details/84970595?spm=1001.2101.3001.6650.6&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-6-84970595-blog-116505986.pc_relevant_3mothn_strategy_and_data_recovery&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-6-84970595-blog-116505986.pc_relevant_3mothn_strategy_and_data_recovery&utm_relevant_index=6

 

一种方式:跨域获取链接分享

HTML代码为:

<script>
var shareTitle='帮我投票,送我去英国和安迪科尔共进Low tea!';
var shareDescription='帮我投票,送我去英国和安迪科尔共进Low tea!';
var shareUrl='<?php echo $wx_share['url']; ?>';
var shareImage='http://7xsqmh.com2.z0.glb.clouddn.com/images/logo_4.png';
var urls=location.href.split('#')[0];
var e=encodeURIComponent(urls);
</script>
<script>seajs.use("js/share_wx");</script>
<script>
  seajs.use('jquery',function($){
    $('#idFinish_wx').click(function(){
       $('.brok_pack').fadeIn(200);
       $(this).addClass('idwapimg');
    });
    $('.brok_pack').click(function(){
      $(this).fadeOut(200);
      $('#idFinish_wx').removeClass('idwapimg');
    })
  })
</script>
<script>
function sharesucess(){
  window.location.href=cid_url+'/api/wx_activity/cole_over';
}
</script>

JS代码为:

define("js/share_wx",["jquery","http://res.wx.qq.com/open/js/jweixin-1.0.0.js"],function(a){
    "user strict";var $=a("jquery");var wx=a('http://res.wx.qq.com/open/js/jweixin-1.0.0.js');
$.ajax({
  type:"GET",
  url:"http://wx.5usport.com/Jsapisign",
  data:{signurl:e},
  dataType:"json",
  success:function(e){
    //alert(e.appid);
    wx.config({
      debug:!1,
      appId:e.appid,
      timestamp:e.timestamp,
      nonceStr:e.noncestr,
      signature:e.signature,
      jsApiList:["checkJsApi","onMenuShareTimeline","onMenuShareAppMessage"]
      })
    },
  error:function(){
    alert("数据有误!")}
})

wx.ready(function(){
  wx.showOptionMenu(),
  wx.onMenuShareAppMessage({
    title:shareTitle,
    desc:shareDescription,
    link:shareUrl,
    imgUrl:shareImage,
    trigger:function(e){},
    success:function(e){
      sharesucess();
    },
    cancel:function(e){},
    fail:function(e){}
  })
  wx.onMenuShareTimeline({
    title:shareTitle,
    link:shareUrl,
    imgUrl:shareImage,
    trigger:function(e){},
    success:function(e){
      sharesucess();
    },
    cancel:function(e){},
    fail:function(e){}
  })
})
wx.error(function(e){
  alert(e.errMsg)
});

});

这样调用是很成功的

 分享到朋友圈、朋友、QQ空间文章查看:http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html

posted @ 2016-04-21 20:19  chenguiya  阅读(1589)  评论(0)    收藏  举报