{"id":69378,"date":"2025-07-17T11:24:00","date_gmt":"2025-07-17T03:24:00","guid":{"rendered":"http:\/\/www.xiaoyebailong.com\/?p=69378"},"modified":"2025-11-02T23:39:47","modified_gmt":"2025-11-02T15:39:47","slug":"%e5%85%ac%e4%bc%97%e5%8f%b7%e7%bd%91%e9%a1%b5js-sdk%e7%9a%84wx-scanqrcode%e6%8e%a5%e5%8f%a3","status":"publish","type":"post","link":"http:\/\/www.xiaoyebailong.com\/index.php\/2025\/07\/17\/69378.htm","title":{"rendered":"\u516c\u4f17\u53f7\u7f51\u9875JS-SDK\u7684wx.scanQRCode\u63a5\u53e3"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>&lt;%@ codepage=65001%>\n&lt;html>\n&lt;head>\n&lt;meta http-equiv=\"Content-Type\" content=\"text\/html; charset=utf-8\">\n&lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0\" \/>\n&lt;script type=\"text\/javascript\" src=\"https:\/\/res.wx.qq.com\/open\/js\/jweixin-1.6.0.js\">&lt;\/script>\n&lt;\/head>\n&lt;script language=\"javascript\" type=\"text\/javascript\" runat=\"server\">\nvar hexcase = 0;\nvar b64pad  = \"=\";\nvar chrsz   = 8;\nfunction hex_sha1(s){return binb2hex(core_sha1(str2binb(s),s.length * chrsz));}\nfunction b64_sha1(s){return binb2b64(core_sha1(str2binb(s),s.length * chrsz));}\nfunction str_sha1(s){return binb2str(core_sha1(str2binb(s),s.length * chrsz));}\nfunction hex_hmac_sha1(key, data){ return binb2hex(core_hmac_sha1(key, data));}\nfunction b64_hmac_sha1(key, data){ return binb2b64(core_hmac_sha1(key, data));}\nfunction str_hmac_sha1(key, data){ return binb2str(core_hmac_sha1(key, data));}\nfunction sha1_vm_test()\n{\n  return hex_sha1(\"abc\") == \"a9993e364706816aba3e25717850c26c9cd0d89d\";\n}\nfunction core_sha1(x, len)\n{\n  \/* append padding *\/\n  x&#91;len >> 5] |= 0x80 &lt;&lt; (24 - len % 32);\n  x&#91;((len + 64 >> 9) &lt;&lt; 4) + 15] = len;\n  var w = Array(80);\n  var a =  1732584193;\n  var b = -271733879;\n  var c = -1732584194;\n  var d =  271733878;\n  var e = -1009589776;\n  for(var i = 0; i &lt; x.length; i += 16)\n  {\n    var olda = a;\n    var oldb = b;\n    var oldc = c;\n    var oldd = d;\n    var olde = e;\n    for(var j = 0; j &lt; 80; j++)\n    {\n      if(j &lt; 16) w&#91;j] = x&#91;i + j];\n      else w&#91;j] = rol(w&#91;j-3] ^ w&#91;j-8] ^ w&#91;j-14] ^ w&#91;j-16], 1);\n      var t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)),\n                       safe_add(safe_add(e, w&#91;j]), sha1_kt(j)));\n      e = d;\n      d = c;\n      c = rol(b, 30);\n      b = a;\n      a = t;\n    }\n    a = safe_add(a, olda);\n    b = safe_add(b, oldb);\n    c = safe_add(c, oldc);\n    d = safe_add(d, oldd);\n    e = safe_add(e, olde);\n  }\n  return Array(a, b, c, d, e);\n}\n\/*\n * Perform the appropriate triplet combination function for the current\n * iteration\n *\/\nfunction sha1_ft(t, b, c, d)\n{\n  if(t &lt; 20) return (b &amp; c) | ((~b) &amp; d);\n  if(t &lt; 40) return b ^ c ^ d;\n  if(t &lt; 60) return (b &amp; c) | (b &amp; d) | (c &amp; d);\n  return b ^ c ^ d;\n}\n\/*\n * Determine the appropriate additive constant for the current iteration\n *\/\nfunction sha1_kt(t)\n{\n  return (t &lt; 20) ?  1518500249 : (t &lt; 40) ?  1859775393 :\n         (t &lt; 60) ? -1894007588 : -899497514;\n}\n\/*\n * Calculate the HMAC-SHA1 of a key and some data\n *\/\nfunction core_hmac_sha1(key, data)\n{\n  var bkey = str2binb(key);\n  if(bkey.length > 16) bkey = core_sha1(bkey, key.length * chrsz);\n  var ipad = Array(16), opad = Array(16);\n  for(var i = 0; i &lt; 16; i++)\n  {\n    ipad&#91;i] = bkey&#91;i] ^ 0x36363636;\n    opad&#91;i] = bkey&#91;i] ^ 0x5C5C5C5C;\n  }\n  var hash = core_sha1(ipad.concat(str2binb(data)), 512 + data.length * chrsz);\n  return core_sha1(opad.concat(hash), 512 + 160);\n}\n\/*\n * Add integers, wrapping at 2^32. This uses 16-bit operations internally\n * to work around bugs in some JS interpreters.\n *\/\nfunction safe_add(x, y)\n{\n  var lsw = (x &amp; 0xFFFF) + (y &amp; 0xFFFF);\n  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);\n  return (msw &lt;&lt; 16) | (lsw &amp; 0xFFFF);\n}\n\/*\n * Bitwise rotate a 32-bit number to the left.\n *\/\nfunction rol(num, cnt)\n{\n  return (num &lt;&lt; cnt) | (num >>> (32 - cnt));\n}\n\/*\n * Convert an 8-bit or 16-bit string to an array of big-endian words\n * In 8-bit function, characters >255 have their hi-byte silently ignored.\n *\/\nfunction str2binb(str)\n{\n  var bin = Array();\n  var mask = (1 &lt;&lt; chrsz) - 1;\n  for(var i = 0; i &lt; str.length * chrsz; i += chrsz)\n    bin&#91;i>>5] |= (str.charCodeAt(i \/ chrsz) &amp; mask) &lt;&lt; (32 - chrsz - i%32);\n  return bin;\n}\n\/*\n * Convert an array of big-endian words to a string\n *\/\nfunction binb2str(bin)\n{\n  var str = \"\";\n  var mask = (1 &lt;&lt; chrsz) - 1;\n  for(var i = 0; i &lt; bin.length * 32; i += chrsz)\n    str += String.fromCharCode((bin&#91;i>>5] >>> (32 - chrsz - i%32)) &amp; mask);\n  return str;\n}\n\/*\n * Convert an array of big-endian words to a hex string.\n *\/\nfunction binb2hex(binarray)\n{\n  var hex_tab = hexcase ? \"0123456789ABCDEF\" : \"0123456789abcdef\";\n  var str = \"\";\n  for(var i = 0; i &lt; binarray.length * 4; i++)\n  {\n    str += hex_tab.charAt((binarray&#91;i>>2] >> ((3 - i%4)*8+4)) &amp; 0xF) +\n           hex_tab.charAt((binarray&#91;i>>2] >> ((3 - i%4)*8  )) &amp; 0xF);\n  }\n  return str;\n}\n\/*\n * Convert an array of big-endian words to a base-64 string\n *\/\nfunction binb2b64(binarray)\n{\n  var tab = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwx  yz0123456789+\/\";\n  var str = \"\";\n  for(var i = 0; i &lt; binarray.length * 4; i += 3)\n  {\n    var triplet = (((binarray&#91;i   >> 2] >> 8 * (3 -  i   %4)) &amp; 0xFF) &lt;&lt; 16)\n                | (((binarray&#91;i+1 >> 2] >> 8 * (3 - (i+1)%4)) &amp; 0xFF) &lt;&lt; 8 )\n                |  ((binarray&#91;i+2 >> 2] >> 8 * (3 - (i+2)%4)) &amp; 0xFF);\n    for(var j = 0; j &lt; 4; j++)\n    {\n      if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;\n      else str += tab.charAt((triplet >> 6*(3-j)) &amp; 0x3F);\n    }\n  }\n  return str;\n}\n&lt;\/script>\n&lt;script language=\"jscript\" runat=\"server\">\nArray.prototype.get = function(x) { return this&#91;x]; };\nfunction parseJSON(strJSON) { return eval(\"(\" + strJSON + \")\"); }\n&lt;\/script>\n&lt;%\nfunction Sha1(Data)\n    Sha1 = hex_sha1(Data)\nend function\n\nFunction ToUnixTime(strTime, intTimeZone)\n    If IsEmpty(strTime) or Not IsDate(strTime) Then strTime = Now\n    If IsEmpty(intTimeZone) or Not isNumeric(intTimeZone) Then intTimeZone = 0\n    ToUnixTime = DateAdd(\"h\",-intTimeZone,strTime)\n    ToUnixTime = DateDiff(\"s\",\"1970-01-01 00:00:00\", ToUnixTime)\nEnd Function\n\nFunction GetUrl()\n   On Error Resume Next    \n   Dim strTemp    \n   If LCase(Request.ServerVariables(\"HTTPS\")) = \"off\" Then    \n   strTemp = \"http:\/\/\"    \n   Else    \n   strTemp = \"https:\/\/\"    \n   End If    \n   strTemp = strTemp &amp; Request.ServerVariables(\"SERVER_NAME\")\n   'If Request.ServerVariables(\"SERVER_PORT\") &lt;> 80 Then strTemp = strTemp &amp; \":\" &amp; Request.ServerVariables(\"SERVER_PORT\")   \n   If Request.ServerVariables(\"SERVER_PORT\") &lt;> 80 Then strTemp = strTemp   \n   strTemp = strTemp &amp; Request.ServerVariables(\"URL\")    \n   If Trim(Request.QueryString) &lt;> \"\" Then strTemp = strTemp &amp; \"?\" &amp; Trim(Request.QueryString)    \n   GetUrl = strTemp    \nEnd Function\n\n'+++++++++++++++++++++++++++++++++++++++++++++++++++++++\nSql8 = \"Select * from token where id=1 and datediff(s,addtime,'\"&amp;now()&amp;\"')&lt;=3000\"\nSet rs8 = Server.CreateObject(\"ADODB.RecordSet\")\nRs8.open Sql8,conn,1,1\nif rs8.recordcount&lt;>0 then 'datediff(\"s\",rs8(\"addtime\"),now())\naccess_token=rs8(\"access_token\")\nelse\n'########################################################\nDim access_token\nFunction GetBodyt()\nSet https = Server.CreateObject(\"Microsoft.XMLHTTP\") \nWith https\n.Open \"GET\", \"https:\/\/api.weixin.qq.com\/cgi-bin\/token?grant_type=client_credential\", False\n.setRequestHeader \"Content-Type\",\"application\/x-www-form-urlencoded\"\n.Send \"appid=\"&amp;APPID&amp;\"&amp;secret=\"&amp;APPSECRET&amp;\"\"\nGetBodyt = .ResponseBody\nEnd With \nGetBodyt = BytesToBstr(GetBodyt,\"utf-8\")\nSet https = Nothing \nEnd Function\n\nFunction BytesToBstr(body,Cset)\ndim objstream\nset objstream = Server.CreateObject(\"adodb.stream\")\nobjstream.Type = 1\nobjstream.Mode =3\nobjstream.Open\nobjstream.Write body\nobjstream.Position = 0\nobjstream.Type = 2\nobjstream.Charset = Cset\nBytesToBstr = objstream.ReadText \nobjstream.Close\nset objstream = nothing\nEnd Function\n\nSet objTests = parseJSON(GetBodyt()) \n\nSql7 = \"Select * from token where id=1\"\nSet rs7= Server.CreateObject(\"ADODB.RecordSet\")\nRs7.open Sql7,conn,1,3\naccess_token=objTests.access_token\nexpires_in=objTests.expires_in\nrs7(\"access_token\")=access_token\nrs7(\"addtime\")=now()\nrs7.update\nrs7.close\nset rs7=nothing\n'########################################################\nend if\nrs8.close\nset rs8=nothing\n'--------------------------------------------------------\n\n'+++++++++++++++++++++++++++++++++++++++++++++++++++++++\nSql8 = \"Select * from token where id=1 and datediff(s,times,'\"&amp;now()&amp;\"')&lt;=3000\"\nSet rs8 = Server.CreateObject(\"ADODB.RecordSet\")\nRs8.open Sql8,conn,1,1\nif rs8.recordcount&lt;>0 then 'datediff(\"s\",rs8(\"times\"),now())\nticket=rs8(\"ticket\")\nelse\n'########################################################\nDim ticket\nFunction ticketk()\n\nSet http = Server.CreateObject(\"Microsoft.XMLHTTP\") \nWith http\n.Open \"get\", \"https:\/\/api.weixin.qq.com\/cgi-bin\/ticket\/getticket?access_token=\" &amp; access_token &amp; \"\", False\n .setRequestHeader \"Content-Type\",\"application\/json\"\n.Send \"type=jsapi\"\nticketk = .ResponseBody\nEnd With \nticketk = BytesToBstr(ticketk,\"utf-8\")\nSet http = Nothing \nEnd Function\n\nFunction BytesToBstr(body,Cset)\ndim objstream\nset objstream = Server.CreateObject(\"adodb.stream\")\nobjstream.Type = 1\nobjstream.Mode =3\nobjstream.Open\nobjstream.Write body\nobjstream.Position = 0\nobjstream.Type = 2\nobjstream.Charset = Cset\nBytesToBstr = objstream.ReadText \nobjstream.Close\nset objstream = nothing\nEnd Function\n\n' \u6dfb\u52a0\u8c03\u8bd5\u4fe1\u606f\nDim ticketResponse\n\nticketResponse = ticketk()\nSet objTestsk = parseJSON(ticketResponse)\n\n' \u7ee7\u7eed\u539f\u6709\u7684\u903b\u8f91\u4f46\u907f\u514dresponse.end\u4e2d\u65ad\u6267\u884c\nif IsObject(objTestsk) then\n   ticket=objTestsk.ticket\nend if\n\nSql7 = \"Select * from token where id=1\"\nSet rs7= Server.CreateObject(\"ADODB.RecordSet\")\nRs7.open Sql7,conn,1,3\nticket=objTestsk.ticket\nexpires_in=objTestsk.expires_in\nrs7(\"ticket\")=ticket\nrs7(\"times\")=now()\nrs7.update\nrs7.close\nset rs7=nothing\n'########################################################\nend if\nrs8.close\nset rs8=nothing\n'--------------------------------------------------------\n\nFunction getCode1(iCount1)\n     Dim arrChar1, j1, k1, strCode1\n     arrChar1 = \"23456789ABCDEFGHJKLMNPQRSTUVWXYZ\"\n     k1=Len(arrChar1)\n     Randomize\n     For i1=1 to iCount1\n          j1=Int(k1 * Rnd )+1\n          strCode1 = strCode1 &amp; Mid(arrChar1,j1,1)\n     Next\n     getCode1 = strCode1\nEnd Function\n\nDim noncestr, timestamp, url, signstr, signature\nnoncestr = getCode1(16)\ntimestamp = ToUnixTime(Now(), +8)\n'url = GetUrl()\nurl = \"http:\/\/www.xiaoyebailong.com\/sacn\/\" '\u8fd9\u5757\u5982\u679c\u540e\u9762\u662findex.asp\u53ef\u4ee5\u4e0d\u5199\nsignstr = \"jsapi_ticket=\" &amp; ticket &amp; \"&amp;noncestr=\" &amp; noncestr &amp; \"&amp;timestamp=\" &amp; timestamp &amp; \"&amp;url=\" &amp; url\nsignature = Sha1(signstr)\n%>\n&lt;body>\n&lt;h3>\u5fae\u4fe1\u626b\u4e00\u626b&lt;\/h3>\n&lt;a class=\"btn\" href=\"javascript:void(0)\" onclick=\"startScan()\">\u91cd\u65b0\u626b\u7801&lt;\/a>\n&lt;div class=\"tips\">\u8bf7\u5728\u5fae\u4fe1\u5185\u6253\u5f00\u6b64\u9875\u9762\uff1b\u8fdb\u5165\u5373\u81ea\u52a8\u8c03\u8d77\u626b\u7801\u3002&lt;\/div>\n&lt;div id=\"result\">\u626b\u7801\u7ed3\u679c\u5c06\u663e\u793a\u5728\u8fd9\u91cc&lt;\/div>\n\n&lt;script>\n(function(){\n  var ua = navigator.userAgent.toLowerCase();\n  if (ua.indexOf('micromessenger') === -1) {\n    document.getElementById('result').innerHTML = '\u8bf7\u5728\u5fae\u4fe1\u5185\u6253\u5f00\u672c\u9875\u9762\u4ee5\u4f7f\u7528\u626b\u4e00\u626b\u529f\u80fd\u3002';\n    return;\n  }\n  wx.config({\n    debug: false,\n    appId: '&lt;%=APPID%>',\n    timestamp: &lt;%=timestamp%>,\n    nonceStr: '&lt;%=noncestr%>',\n    signature: '&lt;%=signature%>',\n    jsApiList: &#91;'scanQRCode']\n  });\n  wx.ready(function(){ startScan(); });\n  wx.error(function(res){\n    document.getElementById('result').innerHTML = 'wx.config \u6821\u9a8c\u5931\u8d25\uff1a' + JSON.stringify(res);\n  });\n})();\nfunction startScan(){\n  wx.scanQRCode({\n    needResult: 1,\n    scanType: &#91;'qrCode','barCode'],\n    success: function(res){\n      var r = res.resultStr || '';\n      location.href = 'http:\/\/www.xiaoyebailong.com\/sacn\/?hexiaoma='+r+'';\n      \/\/document.getElementById('result').textContent = r || '\u672a\u83b7\u53d6\u5230\u7ed3\u679c';\n    },\n    fail: function(err){\n      document.getElementById('result').innerHTML = '\u626b\u7801\u5931\u8d25\uff1a' + JSON.stringify(err);\n    },\n    cancel: function(){\n      document.getElementById('result').textContent = '\u5df2\u53d6\u6d88\u626b\u7801';\n    }\n  });\n}\n&lt;\/script>\n&lt;\/body>\n&lt;\/html>\n\n\u4e0b\u9762\u662f\u5177\u4f53\u7f51\u5740\n\u5fae\u4fe1\u626b\u4e00\u626b\uff08wx.scanQRCode\uff09\u529f\u80fd\u65b0\u624b\u53ef\u80fd\u9047\u5230\u7684\u95ee\u9898\nhttps:&#47;&#47;blog.csdn.net\/weixin_37848710\/article\/details\/104538510\n\nJS-SDK \u4f7f\u7528\u8bf4\u660e\nhttps:\/\/developers.weixin.qq.com\/doc\/service\/guide\/h5\/jssdk.html#63\n\n\u5fae\u4fe1 JS \u63a5\u53e3\u7b7e\u540d\u6821\u9a8c\u5de5\u5177\nhttps:\/\/mp.weixin.qq.com\/debug\/cgi-bin\/sandbox?t=jsapisign\nhttp:\/\/www.ttmd5.com\/hash.php?type=5\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,1],"tags":[12,659,660,636,658],"topic":[],"class_list":["post-69378","post","type-post","status-publish","format-standard","hentry","category-htmlcss","category-technology","tag-asp","tag-js-sdk","tag-wx-scanqrcode","tag-636","tag-658"],"_links":{"self":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/69378","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/comments?post=69378"}],"version-history":[{"count":1,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/69378\/revisions"}],"predecessor-version":[{"id":69379,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/69378\/revisions\/69379"}],"wp:attachment":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/media?parent=69378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/categories?post=69378"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/tags?post=69378"},{"taxonomy":"topic","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/topic?post=69378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}