网页调用扫码枪支付方案

扫码枪光源分为激光和影像.

激光不能扫描屏幕码.影像可扫描屏幕码.

1.网页中使用input

<input id="payAuthNo" type="hidden" style="opacity: 0;">

2使用弹框prompt

if ($("#payAuthNo").val() == '') {
    var payCodeAuth = prompt('请出示付款码','');
    $("#payAuthNo").val(payCodeAuth);
}

3.监听keypress事件

var code = "";
var lastTime,nextTime;
var lastCode,nextCode;
$('body').bind('keypress', function(e) {
    console.log(e.which);
    nextCode = e.which;
    nextTime = new Date().getTime();

    if(lastCode != null && lastTime != null && nextTime - lastTime <= 30) {
        code += String.fromCharCode(lastCode); 
    } else if(lastCode != null && lastTime != null && nextTime - lastTime > 100){
        code = "";
    }

    lastCode = nextCode;
    lastTime = nextTime;
    if(e.which == 13){
        
        $('#payAuthNo').val(code); //自动填充到表单
        console.log($('#payAuthNo').val());
        console.log(bCanPay);
        if (bCanPay == true) {
            alert('go to pay');
            sendPayRequest();
        }
        code = "";
    }
});

 

posted @ 2022-01-21 08:47  变形金刚之猩猩将军  阅读(739)  评论(0)    收藏  举报