您的位置:首页 > 移动开发 > 微信开发

统计微信分享信息

2015-10-28 17:57 513 查看
有时候我们需要统计用户分享的信息,或者在用户分享之后我们要执行某些操作。只需要在一个jsp里面放一下下面的代码,

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
function share(link,title,desc,icon){
var shareLink = link;
var shareTitle = title;
var shareDesc = desc;
var shareIcon = icon;
$.ajax({
type: "post",
url: "${pageContext.request.contextPath}/wxjsapi/config",
//url: "${pageContext.request.contextPath}/test.jsp?url="+window.location.href,
data:{
url:window.location.href
},
success: function (data) {
/* wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: 'wx5c668f38955bf3a7',
timestamp: 1443198507,
nonceStr: 'Jgd8KdFyH8dN8Tts',
signature: "9f9842364f1f730eba5c744bcfb98b30f2287cd6",
jsApiList: ["onMenuShareTimeline", "onMenuShareAppMessage", "onMenuShareQQ", "onMenuShareWeibo", "closeWindow"] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
}); */
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: data.appId,
timestamp: data.timestamp,
nonceStr: data.noncestr,
signature: data.signature,
jsApiList: ["onMenuShareTimeline", "onMenuShareAppMessage", "onMenuShareQQ", "onMenuShareWeibo", "closeWindow"] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
});
wx.error(function(res) {
alert("信息验证失败,请重新打开页面:"+res);
console.log(res);
});
wx.ready(function() {
wx.onMenuShareTimeline({
title:shareTitle, // 分享标题
link:shareLink, // 分享链接
imgUrl:shareIcon, // 分享图标
success:function() {addShareInfo("friend_circle");},
cancel:function() {}
});
wx.onMenuShareAppMessage({
title:shareTitle, // 分享标题
desc:shareDesc, // 分享描述
link:shareLink, // 分享链接
imgUrl:shareIcon, // 分享图标
type:"link", // 分享类型,music、video或link,不填默认为link
dataUrl:"", // 如果type是music或video,则要提供数据链接,默认为空
success:function() {addShareInfo("weixin_friend");},
cancel:function() {}
});
wx.onMenuShareQQ({
title:shareTitle, // 分享标题
desc:shareDesc, // 分享描述
link:shareLink, // 分享链接
imgUrl:shareIcon, // 分享图标
success:function() {addShareInfo("QQ");},
cancel:function() {}
});
wx.onMenuShareWeibo({
title:shareTitle, // 分享标题
desc:shareDesc, // 分享描述
link:shareLink, // 分享链接
imgUrl:shareIcon, // 分享图标
success:function() {addShareInfo("weibo");},
cancel:function() {}
});
});
}
});
}
$(function(){//页面加载完成之后执行
var url=window.location.href;
share(url,title,description,img);//该方法初始分享的数据,实现自己的配置和操作

});
function addShareInfo(){

//这里写你分享的成功之后的操作代码

}
</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: