微信分享接口

看着微信分享的 demo 好糾結啊。。。不知道怎麼去觸發他。哪位大神能夠指點一下。。。點擊按鈕彈出分享

js不太懂。。搞了半天也沒搞出來。。請教你們。

wx.ready(function () {

wx.onMenuShareTimeline({
          title: window.shareData.tTitle,
          link: window.shareData.timeLineLink,
          imgUrl: window.shareData.imgUrl,
          desc: window.shareData.tContent,
               trigger: function (res) {
            // 不要嘗試在trigger中使用ajax異步請求修改本次分享的內容,由於客戶端分享操做是一個同步操做,這時候使用ajax的回包會尚未返回
            alert('用戶點擊發送給朋友');
          },
          success: function (res) {
           alert('已分享');
          },
          ancel: function (res) {
        alert('已取消');
      },
          fail: function (res) {
              alert('錯誤');
          }
        });
});

 http://www.360doc.com/content/14/1118/21/15077656_426245574.shtmlhtml

 

        function onBridgeReady(){
            //WeixinJSBridge.call('hideOptionMenu');
            $("#share").click(function(){
                WeixinJSBridge.call('onMenuShareTimeline');
            });
        }

        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
            }else if (document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
            }
        }else{
            onBridgeReady();
        }

        /*
        var lineLink    = 'http://../....';    // 要分享的頁面的URL
        var imgUrl      = 'http://.../...';    // 顯示在微信裏的縮略圖
        var shareTitle  = '頁面標題';          // 頁面標題
        var descContent = "頁面內容簡介";      // 內容簡介
        var appid       = '';                  // APP ID, 能夠爲空


        function wx_shareFriend() {  
            WeixinJSBridge.invoke('sendAppMessage',{  
                "appid": appid,  
                "img_url": imgUrl,  
                "img_width": "640",  
                "img_height": "640",  
                "link": lineLink,  
                "desc": descContent,  
                "title": shareTitle  
            }, function(res) {  
                //alert(res.err_msg);  
            })  
        }  

        function wx_shareTimeline() {  
            WeixinJSBridge.invoke('shareTimeline',{  
                "img_url": imgUrl,  
                "img_width": "640",  
                "img_height": "640",  
                "link": lineLink,  
                "desc": descContent,  
                "title": shareTitle  
            }, function(res) {  
                //alert(res.err_msg);  
            });  
        }  

        function wx_shareWeibo() {  
            WeixinJSBridge.invoke('shareWeibo',{  
                "content": descContent,  
                "url": lineLink,  
            }, function(res) {  
                //alert(res.err_msg);  
            });  
        }  

        function onBridgeReady(){
            WeixinJSBridge.on('menu:share:appmessage', wx_shareFriend);   // 發送給朋友
            WeixinJSBridge.on('menu:share:timeline',   wx_shareTimeline); // 分享到朋友圈
            WeixinJSBridge.on('menu:share:weibo',      wx_shareWeibo);    // 分享到微博
        }

        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
            }else if (document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
            }
        }else{
            onBridgeReady();
        }

        function onBridgeReady(){
            WeixinJSBridge.on('menu:share:appmessage', wx_shareFriend);  
            WeixinJSBridge.on('menu:share:timeline',   wx_shareTimeline);  
            WeixinJSBridge.on('menu:share:weibo',      wx_shareWeibo);
        }

        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
            }else if (document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
            }
        }else{
            onBridgeReady();
        }

        WeixinJSBridge.call('hideOptionMenu');
        WeixinJSBridge.call('hideToolbar');
        WeixinJSBridge.invoke('closeWindow',{},function(res){
            alert(res.err_msg);
        });
        WeixinJSBridge.invoke('getNetworkType',{},function(e){
            WeixinJSBridge.log(e.err_msg);
        });
        */
相關文章
相關標籤/搜索