微信开发扫一扫功能并且屏蔽分享菜单

1.引入JS

  <script language="javascript" type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>

 

2.代码

用到微信的这3个接口'translateVoice', 'scanQRCode', 'hideMenuItems'

 

屏蔽  分享到朋友圈 分享给朋友 发送给QQ好友 发送给QQ空间:"menuItem:share:timeline", "menuItem:share:appMessage", "menuItem:share:qq", "menuItem:share:QZone"

完整代码如下:

<script>
                if (wx) {
                    var jurl = location.href;
                    if (jurl.indexOf('#'))
                        jurl = jurl.split('#')[0];
                    var timestamp = Math.round(new Date().getTime() / 1000), nonceStr = Math.random().toString(36).substr(2, 15);
                    $.getJSON("http://取票据接口?noncestr=" + nonceStr + "&timestamp=" + timestamp + "&url=" + encodeURIComponent(location.href) + "&callback=?",
                            function (a) {
                                if (a.success) {
                                    wx.config({
                                        debug: false,
                                        appId: 'wxd6cccc001e84efdb',
                                        timestamp: timestamp,
                                        nonceStr: nonceStr,
                                        signature: a.msg,
                                        jsApiList: ['translateVoice', 'scanQRCode', 'hideMenuItems']
                                    });
                                    wx.error(function (res) {
                                        alert("出错了:" + res.errMsg);
                                    });
                                    wx.ready(function () {
                                        wx.checkJsApi({
                                            jsApiList: ['translateVoice', 'scanQRCode', 'hideMenuItems'],
                                            success: function (res) {
                                            }
                                        })
                                        wx.hideMenuItems({ menuList: ["menuItem:share:timeline", "menuItem:share:appMessage", "menuItem:share:qq", "menuItem:share:QZone"] });
                                    });
                                }
                                else {
                                    alert(a.msg);
                                }
                            });
                }
                function Sao() {
                    $.ajax({
                        url: '/WxMeeting/GetBoDrawState?r=' + Math.random(),
                        type: 'post',
                        async: false,
                        dataType: 'jsonp',
                        data: { phone: "", id: "@Model.HDManageID" },
                        success: function (r) {
                            if (r.success) {
                                if (wx) {
                                    wx.scanQRCode({
                                        needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
                                        scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码,默认二者都有
                                        success: function (res) {
                                            location.href = res.resultStr; // 当needResult 为 1 时,扫码返回的结果
                                        }
                                    });
                                }
                            }
                            else {
                                alert(r.msg);
                            }
                        }
                    });
                }
            </script>

3.参考JSSDK地址:

微信JS-SDK说明文档

 

posted on 2017-07-10 11:50  花生哒哒  阅读(290)  评论(0编辑  收藏  举报

导航