webview中定制微信分享

时间:2014-12-04 12:25:19   收藏:0   阅读:561

 微信webview中分享默认抓取网页title,网页上第一张大图,当前网页链接作为分享素材(同易信),但是通过JsBridge可以用js定制分享的素材,此api并没有公开在官方文档中,记录如下:
     document.addEventListener(‘WeixinJSBridgeReady‘, function onBridgeReady() {
                /** 发送给好友 **/
                WeixinJSBridge.on(‘menu:share:appmessage‘, function(argv){
                     WeixinJSBridge.invoke(_eventName,{
                                    "appid": ‘xxx‘,
                                    "img_url": "xxxx",
                                    "img_width": "320",
                                    "img_height": "320",
                                    "link": ‘http://xxxx’,
                                    "desc": “朋友圈中别忘了填",
                                    "title": “xxxx"
                                    }, function(res) {
                                        // 我是回调,很精彩,有ready,有执行,有后事
                                    });
                    });
                
                /** 分享到朋友圈 **/
                WeixinJSBridge.on(‘menu:share:timeline‘, function(argv){
                    WeixinJSBridge.invoke(_eventName,{
                                    "appid": ‘xxx‘,
                                    "img_url": "xxxx",
                                    "img_width": "320",
                                    "img_height": "320",
                                    "link": ‘http://xxxx’,
                                    "desc": “朋友圈中别忘了填",
                                    "title": “xxxx"
                                    }, function(res) {
                                    });
                    });
                    
                 /** 分享到微博 **/
                WeixinJSBridge.on(‘menu:share:weibo‘, function(argv){
                     WeixinJSBridge.invoke(‘shareWeibo‘,{
                                    "content": "xxxx",
                                    "url": ‘http://xxxx‘,                                    }, function(res) {
                                    });
                });
        }, false); 

另外还有些有用的api,有人总结了,可以参见https://github.com/zxlie/WeixinApi   

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!