<!doctype html>
<html>
<head>
<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>demo</title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function () {
getWeixinParams();
});
var appId ;
var nonceStr ;
var signature ;
var timestamp ;
function getWeixinParams() {
var WX_url = location.href.split('#')[0];
$.ajax({
type: "get",
url: "********",
data: {"URL": WX_url},
datatype: "json",
async:false,
success: function (data) {
var data = JSON.parse(data);
appId = data.appId;
nonceStr = data.nonceStr;
signature = data.signature;
timestamp = data.timestamp;
getWeixinParamsCallBack(data.appId, data.timestamp, data.nonceStr, data.signature);
},
error: function () {
alert("出错了");
}
});
}
function getWeixinParamsCallBack(appId, timestamp, nonceStr, signature) {
wx.config({
debug: true,
appId: appId,
timestamp: timestamp,
nonceStr: nonceStr,
signature: signature,
jsApiList: ['scanQRCode']
});
wx.ready(function () {
});
wx.error(function (res) {
alert("获取数据出错了:" + res.errMsg);
});
}
function getWeixinResult() {
wx.scanQRCode({
needResult: 1,
scanType: ["qrCode", "barCode"],
success: function (res) {
var result = res.resultStr;
if (result.indexOf("=") != -1) {
result = result.split("=")[1];
} else if (result.indexOf(",") != -1) {
result = result.split(",")[1];
}
alert(res.resultStr);
}
});
}
</script>
</body>
</html>
你没调用扫一扫方法啊