首页 > 代码库 > 微信分享JS函数

微信分享JS函数

 1 //微信内置浏览器分享事件 2 //来自:http://www.cnblogs.com/cielwater 3 //分享朋友圈事件 4 //UpdateWeixinJSBridge(CircleModel[Json格式,分享朋友圈事件参数]) 5 //Json{, img_url:封面图片地址, img_width:图片宽度, img_height:图片高度, link:跳转地址, desc:正文, title:标题} 6 function Circle(CircleModel) { 7     WeixinJSBridge.on(‘menu:share:timeline‘, function (argv) { 8         WeixinJSBridge.invoke(‘shareTimeline‘, { 9             "img_url": CircleModel.img_url,10             "img_width": CircleModel.img_width,11             "img_height": CircleModel.img_height,12             "link": CircleModel.link,13             "desc": CircleModel.desc,14             "title": CircleModel.title15         }, function (res) {16             if (‘share_timeline:cancel‘ != res.err_msg) {17                 //如果用户没有取消18                 weimobAfterShare("", WeixinModel.link, ‘timeline‘);19             }20             _report(‘timeline‘, res.err_msg);21         });22     });23 }24 //分享好友事件25 //FriendsModel[Json格式,分享给朋友事件参数]26 //Json{img_url:封面图片地址, img_width:图片宽度, img_height:图片高度, link:跳转地址, desc:正文, title:标题}27 function Friends(FriendsModel) {28     WeixinJSBridge.on(‘menu:share:appmessage‘, function (argv) {29         WeixinJSBridge.invoke(‘sendAppMessage‘, {30             "img_url": FriendsModel.img_url,31             "img_width": FriendsModel.img_width,32             "img_height": FriendsModel.img_height,33             "link": FriendsModel.link,34             "desc": FriendsModel.desc,35             "title": FriendsModel.title36         }, function (res) {37             if (‘send_app_msg:cancel‘ != res.err_msg) {38                 weimobAfterShare("", window.shareData.link, ‘appmessage‘);39             }40             _report(‘send_msg‘, res.err_msg);41         })42     });43 }44 //分享微博事件45 //WeiboModel[Json格式,分享微博事件参数]46 //Json{content:正文, url:跳转地址}47 function Weibo(WeiboModel) {48     WeixinJSBridge.on(‘menu:share:weibo‘, function (argv) {49         WeixinJSBridge.invoke(‘shareWeibo‘, {50             "content": WeiboModel.content,51             "url": WeiboModel.url52         }, function (res) {53             if (‘share_weibo:cancel‘ != res.err_msg) {54                 weimobAfterShare("", WeiboModel.url, ‘weibo‘);55             }56             _report(‘weibo‘, res.err_msg);57         });58     });59 }60 //绑定微信分享事件61 function WeiXinBind(CircleModel, FriendsModel, WeiboModel) {62     document.addEventListener(‘WeixinJSBridgeReady‘, function onBridgeReady() {63         Circle(InitializeCircleModel);64         Friends(InitializeFriendsModel);65         Weibo(InitializeWeiboModel);66     }, false);67 }

 

微信分享JS函数