·您当前的位置:首页 > 技术教程 > Html5技术 >

[html5]微信分享代码设定标题缩图等信息的代码

时间:2017-08-18 18:20酷播
[html5]微信分享代码设定标题缩图等信息的代码

[html5]微信分享代码设定标题缩图等信息的代码

  1. <script>   
  2. var imgUrl = 'http://topic.xcar.com.cn/201403/ad_q3/pic/banner.jpg';   
  3. var lineLink = 'http://topic.xcar.com.cn/201403/ad_q3/index.php';   
  4. var descContent = "http://topic.xcar.com.cn/201403/ad_q3/index.php";   
  5. var shareTitle = '【奥迪Q3开启尊享礼遇季】报名试驾,赢取精美礼品';   
  6. var appid = 'wxc9937e3a66af6dc8';   
  7.    
  8. function shareFriend() {   
  9.     WeixinJSBridge.invoke('sendAppMessage',{   
  10.                             "appid": appid,   
  11.                             "img_url": imgUrl,   
  12.                             "img_width": "640",   
  13.                             "img_height": "640",   
  14.                             "link": lineLink,   
  15.                             "desc": descContent,   
  16.                             "title": shareTitle   
  17.                             }, function(res) {   
  18.                             _report('send_msg', res.err_msg);   
  19.                             })   
  20. }   
  21. function shareTimeline() {   
  22.     WeixinJSBridge.invoke('shareTimeline',{   
  23.                             "img_url": imgUrl,   
  24.                             "img_width": "640",   
  25.                             "img_height": "640",   
  26.                             "link": lineLink,   
  27.                             "desc": descContent,   
  28.                             "title": shareTitle   
  29.                             }, function(res) {   
  30.                             _report('timeline', res.err_msg);   
  31.                             });   
  32. }   
  33. function shareWeibo() {   
  34.     WeixinJSBridge.invoke('shareWeibo',{   
  35.                             "content": descContent,   
  36.                             "url": lineLink,   
  37.                             }, function(res) {   
  38.                             _report('weibo', res.err_msg);   
  39.                             });   
  40. }   
  41. // 当微信内置浏览器完成内部初始化后会触发WeixinJSBridgeReady事件。   
  42. document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {   
  43.    
  44.         // 发送给好友   
  45.         WeixinJSBridge.on('menu:share:appmessage', function(argv){   
  46.             shareFriend();   
  47.             });   
  48.    
  49.         // 分享到朋友圈   
  50.         WeixinJSBridge.on('menu:share:timeline', function(argv){   
  51.             shareTimeline();   
  52.             });   
  53.    
  54.         // 分享到微博   
  55.         WeixinJSBridge.on('menu:share:weibo', function(argv){   
  56.             shareWeibo();   
  57.             });   
  58.         }, false);   
  59. </script>   

说明:页面上需新建mate标签如下代码:

  1. <meta name="sharecontent" data-msg-img="缩略图地址" data-msg-title="标题" 
    data-msg-content="简介" data-msg-callBack="" data-line-img="缩略图地址" 
    data-line-title
    ="标题" data-line-callBack=""/>   

来源:http://blog.csdn.net/china_skag/article/details/39611327

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器