var title =document.title;
var link ="";
var imgUrl ="<%=SystemManager.systemSetting.getImageRootPath()%><s:property escape="false" value="e.picture"/>";
var appid ="";
var productid =$("#productID").val()+"";
var timestamp ="";
var nonceStr ="";
var signature ="";
var openid ="";
//记录停留时间
$(function() {
//调用后台jssdk验证方法
var _url = "<%=request.getContextPath()%>/wxaction/jsSDKPackage.html?productid="+productid+"&source=wx&jssdkurl="+location.href;
//alert(_url);
//验证需要使用的JS接口列表
$.ajax({
type: 'POST',
url: _url,
data: {},
dataType: "json",
success: function(data){
console.log("data="+data);
appid=data.appid;
timestamp=data.timestamp;
nonceStr=data.noncestr;
signature=data.signature;
link=data.link;
openid=data.openid;
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: appid, // 必填,公众号的唯一标识
timestamp: timestamp, // 必填,生成签名的时间戳
nonceStr: nonceStr, // 必填,生成签名的随机串
signature: signature,// 必填,签名,见附录1
jsApiList: [
'checkJsApi',
'onMenuShareTimeline',
'onMenuShareAppMessage',
'onMenuShareQQ',
'onMenuShareWeibo',
'hideMenuItems',
'showMenuItems',
'hideAllNonBaseMenuItem',
'showAllNonBaseMenuItem',
'translateVoice',
'startRecord',
'stopRecord',
'onRecordEnd',
'playVoice',
'pauseVoice',
'stopVoice',
'uploadVoice',
'downloadVoice',
'chooseImage',
'previewImage',
'uploadImage',
'downloadImage',
'getNetworkType',
'openLocation',
'getLocation',
'hideOptionMenu',
'showOptionMenu',
'closeWindow',
'scanQRCode',
'chooseWXPay',
'openProductSpecificView',
'addCard',
'chooseCard',
'openCard'
] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
});
},
error:function(e){
console.log("获取签名参数失败。异常:"+e);
}
});
});
wx.ready(function () {
//需要调用的jssdk 方法
//具体参照https://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html
//此处为分享朋友圈例子
wx.onMenuShareTimeline({
title: title,
link: link,
imgUrl: imgUrl,
trigger: function (res) {
// 不要尝试在trigger中使用ajax异步请求修改本次分享的内容,因为客户端分享操作是一个同步操作,这时候使用ajax的回包会还没有返回
//alert(link);
//alert('用户点击分享到朋友圈');
},
success: function (res) {
updateShare("y",openid,productid)
//alert('已分享');
},
cancel: function (res) {
//alert('已取消');
},
fail: function (res) {
//alert(JSON.stringify(res));
}
});
});