微信分享 js

<script type="text/javascript">
 	        document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
        window.shareData = {  
           "imgUrl": "http://www.baidu.com", 
            "timeLineLink": "http://www.baidu.com",
            "sendFriendLink": "http://www.baidu.com",
            "weiboLink": "http://www.baidu.com",
            "tTitle": "内容",
            "tContent": "内容",
            "fTitle": "内容",
            "fContent": "内容",
            "wContent": "内容" 
        };
        // 发送给好友
        WeixinJSBridge.on('menu:share:appmessage', function (argv) {
            WeixinJSBridge.invoke('sendAppMessage', { 
                "img_url": window.shareData.imgUrl,
                "img_width": "640",
                "img_height": "640",
                "link": window.shareData.sendFriendLink,
                "desc": window.shareData.fContent,
                "title": window.shareData.fTitle
            }, function (res) {
                _report('send_msg', res.err_msg);
            })
        });

        // 分享到朋友圈
        WeixinJSBridge.on('menu:share:timeline', function (argv) {
            WeixinJSBridge.invoke('shareTimeline', {
                "img_url": window.shareData.imgUrl,
                "img_width": "640",
                "img_height": "640",
                "link": window.shareData.timeLineLink,
                "desc": window.shareData.tContent,
                "title": window.shareData.tTitle
            }, function (res) {
                _report('timeline', res.err_msg);
            });
        });

        // 分享到微博
        WeixinJSBridge.on('menu:share:weibo', function (argv) {
            WeixinJSBridge.invoke('shareWeibo', {
                "content": window.shareData.wContent,
                "url": window.shareData.weiboLink,
            }, function (res) {
                _report('weibo', res.err_msg);
            });
        });
        }, false)
    </script>
<pre name="code" class="javascript">function toWexinFriends(){
     
     
    WeixinJSBridge.invoke('shareTimeline',{
        "img_url": "http://example.com/example.png",
        //"img_width": "640",
        //"img_height": "640",
        "link": "http://example.com",
        "desc": "描述",
        "title": "标题"
    },function(res){
        // 返回res.err_msg,取值
        // share_timeline:cancel 用户取消
        // share_timeline:fail 发送失败
        // share_timeline:confirm 发送成功
        WeixinJSBridge.log(res.err_msg);
         
        if(res.err_msg == 'share_timeline:confirm'){
            //转发成功
        };
    });
     
}
function addFirend(){//经测试微信官方已屏蔽
 
//gh_122a2ee67fae 为被添加者的微信ID
 
WeixinJSBridge.invoke("addContact", {webtype: "1",username: 'gh_122a2ee67fae'}, function(e) {
            WeixinJSBridge.log(e.err_msg);
            //e.err_msg:add_contact:added 已经添加
            //e.err_msg:add_contact:cancel 取消添加
            //e.err_msg:add_contact:ok 添加成功
            if(e.err_msg == 'add_contact:added' || e.err_msg == 'add_contact:ok'){
                //关注成功,或者已经关注过
            }
        })
}


 

                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值