配置微信api调扫码功能

时间:2019-02-28 10:23:17   收藏:0   阅读:465
	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-z\d]/ig, "");//处理条形码扫描的字符
			    		$("#account2").val(dealserialNumber);
			    	}else{
			    		$("#account2").val(‘‘);
			    		 layer.open({
		    			    content: ‘返回错误‘,
		    			    skin: ‘msg‘,
		    			    time: 2 //2秒后自动关闭
		    			  });
			    	}
			    } 
			})
		})
	});

  

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!