支付宝、微信扫一扫

 

function sys(){
    // alert('扫一扫')
    //判断浏览器环境
    var userAgent = navigator.userAgent;
    if (userAgent.indexOf("MicroMessenger") > -1){
        
        // 获取配置信息
        // alert('appid'+wxappid)
        $.ajax({
            url: `/api/wechat/config/${wxappid}`,
            type: 'get',
            data: {url: encodeURIComponent(location.href.split('#')[0])},
            dataType: 'json',
            async: false,
            success: function(res){
                // alert('001')
                // alert(wx)
                wx.config({
                    debug: false,
                    appId: res.appId,
                    timestamp: res.timestamp,
                    nonceStr: res.nonceStr,
                    signature: res.signature,
                    jsApiList: ["scanQRCode"]
                });
                wx.ready(function () {
                    // alert('5')
                    wx.scanQRCode({
                        needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
                        success: function (res) {
                            // alert('11111')
                            // alert(JSON.stringify(res))
                            // 扫码成功,跳转到二维码指定页面(res.resultStr为扫码返回的结果)
                            location.href = res.resultStr;
                        },
                        fail: function (res) {
                            // alert('44')
                            // 调用失败
                            if (res.errMsg.indexOf('function_not_exist') > 0 ) {
                                alert('当前版本过低,请进行升级');
                            }
                        },
                        cancel: function(res){
                            // 用户取消操作
                            alert('取消操作')
                        }
                    });
                });
            },
            error: function(res){
                // alert('222')
                // alert(JSON.stringify(res))
            }
        })



    } else if(userAgent.indexOf("AlipayClient") > -1){
        // alert('ZHIF')           
        ap.scan(function(res){
            // alert(JSON.stringify(res))
            // ap.alert(res.code);
            ap.redirectTo({url: res.code});
        });

    } else{
        // alert('a')
    }
}

 

转载于:https://www.cnblogs.com/xhrr/p/11607645.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值