var url = encodeURIComponent(location.href.split('#')[0]); $.get(iapi+'/htweb/wx/getJsSdkSign?url='+url,function(data){ var data = JSON.parse(data); data = data["reason"]; wx.config({ debug:false, appId:data.appId, nonceStr: data.nonceStr, signature: data.signature, timestamp: parseInt(data.timestamp), jsApiList: ['previewImage','chooseImage','uploadImage','scanQRCode'] }) }); wx.ready(function(){ $("#account2").on("click",function(){ wx.scanQRCode({ needResult: 1, desc: 'scanQRCode desc', success: function (res) { //alert(res.resultStr); if(res.resultStr.indexOf(',') > 0){ var dealserialNumber=res.resultStr.split(',')[1]; dealserialNumber = dealserialNumber.replace(/[^a-zd]/ig, "");//处理条形码扫描的字符 $("#account2").val(dealserialNumber); }else{ $("#account2").val(''); layer.open({ content: '返回错误', skin: 'msg', time: 2 //2秒后自动关闭 }); } } }) }) });