我正在从付款服务,从带有JSON数据的Webhook中获得POST响应,并将其发送到.asp页,在此我使用aspJson.asp
来读取所获取的JSON。
我正在在线使用邮政服务进行测试,以将有效的JSON发送到我的页面https://reqbin.com
,当我收到200 OK response
时,我可以读取JSON文件并获取其值并将其插入我的数据库中。
但是,如果我进行实际付款,则可以看到付款服务正在将POST发送到我的页面,因为我可以对数据库进行简单的插入。 但是,当我尝试读取他们发送的JSON时,我无法获取JSON值?
所以我不知道我在想什么?我测试的JSON假定与真实的JSON具有相同的结构,因此它应该起作用。
我测试过的JSON,如果我从https://reqbin.com发送,它就可以工作。
{
"Id": "12",
"MerchantId": "11111",
"Timestamp": "",
"Event": "payment.checkout.completed",
"Data": {
"order": {
"amount": {
"amount": "2222",
"currency": "SEK"
},
"reference": "161978963",
"orderItems": [{
"grossTotalAmount": "30000",
"name": "Lampa",
"netTotalAmount": "10000",
"quantity": 1,
"reference": "1-123",
"taxRate": 2500,
"taxAmount": "2500",
"unit": "111",
"unitPrice": 0
}]
},
"consumer": {
"firstName": "Claes",
"lastName": "Gustavsson",
"country": "NOR",
"email": "info@xxx.se",
"ip": "xx.xxx.xx.xx",
"phoneNumber": {
"prefix": "+47",
"number": "12345678"
},
"shippingAddress": {
"addressLine1": "Norrgatan1",
"addressLine2": "",
"city": "Varberg",
"country": "",
"postcode": "43200",
"receiverLine": ""
}
},
"paymentId": "12345678"
}
}
我正在与此一起获取JSON。
Response.ContentType = "application/json"
Function BytesToStr(bytes)
Dim Stream
Set Stream = Server.CreateObject("Adodb.Stream")
Stream.Type = 1 'adTypeBinary
Stream.Open
Stream.Write bytes
Stream.Position = 0
Stream.Type = 2 'adTypeText
Stream.Charset = "utf-8"
BytesToStr = Stream.ReadText
Stream.Close
Set Stream = Nothing
End Function
if Request.TotalBytes > 0 then
Dim postBody
postBody = BytesToStr(Request.BinaryRead(Request.TotalBytes))
Response.Write(postBody) ' the JSON data
end if
要获取JSON值,我可以使用它,如果我只是对其进行测试,则可以正常工作,但是如果我进行了适当的付款,则无法获取事件值?
jsonstring = Cstr(postBody)
Set oJSON = New aspJSON
oJSON.loadJSON(jsonstring)
theevent=oJSON.data("Event")
response.write "this is the event"&theevent
那么,如果我像测试一样发送它,以及从付款服务那里获得它,那会有什么区别? 还是我错过了什么?
任何输入都非常感谢!