Skip to content

Instantly share code, notes, and snippets.

@naoyeye
Created February 26, 2015 06:55
Show Gist options
  • Select an option

  • Save naoyeye/0968d7db56e23cb53e6f to your computer and use it in GitHub Desktop.

Select an option

Save naoyeye/0968d7db56e23cb53e6f to your computer and use it in GitHub Desktop.
微信 js sdk 分享
function wechatShareSetup() {
$.ajax({
url: 问我,
type: 'POST',
data: {
// url: 'http://www.wandoujia.com/campaign/spring2015/?utm_source=wechat&utm_medium=sns&utm_campaign=spring2015'
url: location.href.split('#')[0] // 将当前URL地址上传至服务器用于产生数字签名
}
}).done(function (r) {
// 返回了数字签名对象
// console.log(r);
// console.log(r.appId);
// console.log(r.timestamp);
// console.log(r.nonceStr);
// console.log(r.signature);
// 开始配置微信JS-SDK
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: r.appId, // 必填,公众号的唯一标识
timestamp: r.timestamp, // 必填,生成签名的时间戳
nonceStr: r.nonceStr, // 必填,生成签名的随机串
signature: r.signature, // 必填,签名,见附录1
jsApiList: [
'checkJsApi',
'onMenuShareTimeline',
'onMenuShareAppMessage',
'onMenuShareQQ',
'onMenuShareWeibo',
'hideMenuItems'//,
// 'chooseImage'
] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
});
resetWechatShare();
});
}
function resetWechatShare() {
wx.ready(function () {
// config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
// alert(JSON.stringify(wechatShareObj));
function initTimelineShare() {
wx.onMenuShareTimeline({
// title: '这是一个测试',
title: wechatShareObj.title, // 分享标题
link: wechatShareObj.link, // 分享链接
imgUrl: wechatShareObj.imgUrl, // 分享图标
success: function () {
// 用户确认分享后执行的回调函数
// alert('分享成功');
campaignTools.pushGaEvent('spring2015', 'newShare', 'wechatTime');
},
cancel: function () {
// 用户取消分享后执行的回调函数
}
});
}
function initFriendShare() {
wx.onMenuShareAppMessage({
title: wechatShareObj.title, // 分享标题
desc: wechatShareObj.desc, // 分享描述
link: wechatShareObj.link, // 分享链接
imgUrl: wechatShareObj.imgUrl, // 分享图标
type: '', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: function () {
// 用户确认分享后执行的回调函数
campaignTools.pushGaEvent('spring2015', 'newShare', 'wechatFriend');
},
cancel: function () {
// 用户取消分享后执行的回调函数
}
});
}
initTimelineShare();
initFriendShare();
});
}
@emmachen99
Copy link

求具体生成wx.config参数的代码

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment