1 仔细阅读开发者文档,逻辑关系要捋顺.
2 appid, appsecret, mch_id, key 之间的关系要弄清.
3 统一下单api传xml格式.
4 当签名错误产生时,一定要先检查各个字段的key和value书写是否正确,也要注意key和mch_id是否匹配.
5 微信返回的数据只能发送到服务端(Ajax无效)
6 生成签名时可以用签名校验工具生成.
asp 代码如下:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%Session.CodePage=65001%>
<%Response.Charset = "utf-8"%>
<%
Response.Buffer = True
Response.ExpiresAbsolute = Now() - 1
Response.Expires = 0
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "No-Cache"
%>
<%
Function getXML(url)
Dim sttp
Set sttp = server.createobject("MSXML2.XMLHTTP")
sttp.open "GET",url,false, "", ""
sttp.send()
getXML = bBytesToBstr(sttp.responseBody)
Set sttp = Nothing
End Function
Function bBytesToBstr(body)
dim objstream
set objstream = CreateObject("adodb.stream") '//调用adodb.stream组件
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = "GB2312" '转换原来默认的UTF-8编码转换成GB2312编码,否则直接用XMLHTTP调用有中文字符的网页得到的将是乱码
bBytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
end Function
%>
<%
dim code
code = request("code")
dim appid
appid = "*******"
dim secret
secret = "*********"
'response.write(code)
Dim Str
Str = getXML("https://api.weixin.qq.com/sns/oauth2/access_token?appid="&appid&"&secret="&secret&"&code="&Code&"&grant_type=authorization_code")
response.write(str)
%>