WebHook Example Using java



我的webhook被调用了,但是数据被打乱了。根据此处的文档https://flutterwavedevelopers.readme.io/docs/events-webhooks,我期待着一条json消息,但我得到了这个

id=64883&txRef=HJDVXUSEMO&flwRef=N%2FA&orderRef=URF_1516263337305_8473935&paymentPlan=&createdAt=2018-01-18T08%3A15%3A37.000Z&amount=12.819223403930664&charged_amount=13.08&status=pending&IP=%3A%3Affff%3A127.0.0.1&currency=USD&customer%5Bid%5D=12569&customer%5Bphone%5D=&customer%5BfullName%5D=solodriver%20KESO4&customer%5Bcustomertoken%5D=&customer%5Bemail%5D=email%40solo.com&customer%5BcreatedAt%5D=2018-01-18T08%3A15%3A37.000Z&customer%5BupdatedAt%5D=2018-01-18T08%3A15%3A37.000Z&customer%5BdeletedAt%5D=&customer%5BAccountId%5D=957&entity%5Bcard6%5D=424242&entity%5Bcard_last4%5D=4242.

我在HttpServlet 中使用此代码

private static JSONObject getBody(HttpServletRequest request) throws 
IOException {
String jb = IOUtils.toString(request.getReader());
AppConstants.logger("JB:" + jb);
try 
return HTTP.toJSONObject(jb);
catch (JSONException e) 
// crash and burn
throw new IOException("Error parsing JSON request string");
}

如何获取此格式?

{
"id": "8368",
"txRef": "rave-checkout-1499791631",
"flwRef": "N/A",
"createdAt": "2017-07-11T16:47:39.000Z",
"amount": "9000",
"charged_amount": "9152.5",
"status": "pending",
"IP": "154.120.106.151",
"currency": "NGN",
"customer[id]": "380",
"customer[phone]": "",
"customer[fullName]": "Anonymous customer",
"customer[customertoken]": "",
"customer[email]": "user@example.com",
"customer[createdAt]": "2017-05-09T18:32:52.000Z",
"customer[updatedAt]": "2017-05-09T18:32:52.000Z",
"customer[deletedAt]": "customer[AccountId]",
"entity[card6]": "543889",
"entity[card_last4]": "0229"
}

根据您包含的文档链接:

默认情况下,Webhook数据以url编码的形式发送,但您可以在仪表板上的webhook设置页面上进行配置,以发送请求改为JSON。

所以我会登录到仪表板并在那里配置设置。我没有Flutterwave登录,所以不知道的设置是什么样子的

@Matt Freake,你说得对。

你可以做的另一件事是,在收到事件通知后,进行URL解码,你应该得到整洁的字符串

最新更新