Instantly share code, notes, and snippets.
Last active
April 26, 2016 07:31
-
Star
0
(0)
You must be signed in to star a gist -
Fork
1
(1)
You must be signed in to fork a gist
-
Save naoyeye/f861829342e4d7a87749 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var minisiteUrl = 'http://www.wandoujia.com/campaign/pizzahut/'; | |
var UTM = { | |
'weibo': '?utm_source=weibo&utm_medium=sns&utm_campaign=pizzahut', | |
'wechatFriend': '?utm_source=wechatFriend&utm_medium=sns&utm_campaign=pizzahut', | |
'wechatTimeline': '?utm_source=wechatTimeline&utm_medium=sns&utm_campaign=pizzahut', | |
// 扫描站内二维码的回流 | |
'qrcode': '?utm_source=qrcode&utm_medium=minisite&utm_campaign=pizzahut' | |
}; | |
// 分享文案 | |
var share = { | |
"weibo": { | |
"description": "这是微博分享文案", | |
"img": "这是分享到微博的图片地址" | |
}, | |
"wechatTimeline": { | |
"title": "这是分享到朋友圈的标题", | |
"img": "这是分享到微信朋友圈的图片地址" | |
}, | |
"wechatFriend": { | |
"title" : "这是分享给好友的标题", | |
"description": "这是简介", | |
"img": "这是分享到微信好友的图片地址" | |
}, | |
} | |
// 分享按钮的行为 | |
// 微博 & 微信好友 & 微信朋友圈 | |
function shareBtnActionSetup() { | |
if (device.isP4) { | |
$('.share-weibo').click(function () { | |
campaignTools.toast('正在打开微博,请稍候...'); | |
campaignTools.pushGaEvent('pizzahut', 'P4Share', 'weibo'); | |
campaignTools.runAppShare(share.weibo.description, share.weibo.description, share.weibo.img, minisiteUrl + UTM.weibo, 'SINA_WEIBO'); | |
}); | |
$('.share-wechat-friend').click(function () { | |
campaignTools.toast('正在打开微信,请稍候...'); | |
campaignTools.pushGaEvent('pizzahut', 'P4Share', 'wechatFriend'); | |
campaignTools.runAppShare(share.wechatFriend.title, share.wechatFriend.description, share.wechatFriend。img, minisiteUrl + UTM.wechatFriend, 'WECHAT'); | |
}); | |
$('.share-wechat-timeline').click(function () { | |
campaignTools.toast('正在打开微信,请稍候...'); | |
campaignTools.pushGaEvent('pizzahut', 'P4Share', 'wechatTimeline'); | |
campaignTools.runAppShare(share.wechatTimeline, share.wechatTimeline, share.wechatTimeline.img, minisiteUrl + UTM.wechatTimeline, 'WECHAT_TIMELINE'); | |
}); | |
} else { | |
// 分享到微博 | |
// 跳转页面 | |
var weiboURL = 'http://service.weibo.com/share/share.php?appkey=1483181040&relateUid=1727978503&url=' + encodeURIComponent(minisiteUrl + UTM.weibo) + '&title=' + encodeURIComponent(share.weibo.description) + '&pic=' + share.weibo.img; | |
$('.share-weibo').click(function () { | |
campaignTools.pushGaEvent('pizzahut', 'share', 'weibo'); | |
window.location.href = weiboURL; | |
}); | |
// 分享到微信 | |
$('.share-wechat-friend').click(function () { | |
// 微信内 | |
// 提示点击右上角 | |
if (device.isWechat) { | |
campaignTools.pushGaEvent('pizzahut', 'share', 'weiboTips'); | |
var tipsImg = 'http://t.wdjcdn.com/upload/mkt-campaign/designaward/208/wechat-share-tips.png'; | |
$('body').append('<div class="overlay"></div><div class="popup wechat-image"><img width="103" id="wechat-share-tips-img" src="' + tipsImg + '" /></div>'); | |
// 微信外 | |
// 弹二维码 提示用微信扫描 | |
} else { | |
campaignTools.pushGaEvent('pizzahut', 'share', 'qrcode'); | |
var popup = { | |
title: '分享到微信', | |
content: '<div class="center"><img class="qrcode" width="150" src="http://www.wandoujia.com/qr?s=5&c=' + encodeURIComponent(minisiteUrl + UTM.qrcode) + '" /></div><p>用微信扫描二维码,就可以分享到好友或朋友圈了</p>', | |
button: '关 闭' | |
}; | |
render.renderPopoup(popup); | |
} | |
}); | |
} | |
} | |
// setup wechat share | |
function wechatShareSetup() { | |
$.ajax({ | |
url: 'http://who.wandoujia.com/wx-corp/js-sdk', | |
type: 'POST', | |
data: { | |
url: location.href.split('#')[0] // 将当前URL地址上传至服务器用于产生数字签名 | |
// url: 'http://www.wandoujia.com/campaign/appmaker/' | |
} | |
}).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 | |
}); | |
wx.ready(function () { | |
// config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。 | |
// function initTimelineShare() { | |
wx.onMenuShareTimeline({ | |
// title: '这是一个测试', | |
title: share.wechatTimeline.title, // 分享标题 | |
link: minisiteUrl + UTM.wechatTimeline, // 分享链接 | |
img: share.wechatTimeline.img, // 分享图标 | |
success: function () { | |
// 用户确认分享后执行的回调函数 | |
// alert('分享成功'); | |
campaignTools.pushGaEvent('pizzahut', 'wechatWebviewShare', 'wechatTimeLine'); | |
}, | |
cancel: function () { | |
// 用户取消分享后执行的回调函数 | |
} | |
}); | |
// } | |
// function initFriendShare() { | |
wx.onMenuShareAppMessage({ | |
title: share.wechatFriend.title, // 分享标题 | |
desc: share.wechatFriend.description, // 分享描述 | |
link: minisiteUrl + UTM.wechatFriend, // 分享链接 | |
img: share.wechatFriend.img, // 分享图标 | |
type: '', // 分享类型,music、video或link,不填默认为link | |
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空 | |
success: function () { | |
// 用户确认分享后执行的回调函数 | |
campaignTools.pushGaEvent('pizzahut', 'wechatWebviewShare', 'wechatFriend'); | |
}, | |
cancel: function () { | |
// 用户取消分享后执行的回调函数 | |
} | |
}); | |
// } | |
// initTimelineShare(); | |
// initFriendShare(); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment