twilio-webhook:无法验证签名



我在twilio控制台中为Messaging设置了一个webhook:它是对表单url的POSThttps://apim.com/twilio?ApiKey=xxxxxxxxx,它调用API管理器(然后重定向到我用Java编写的REST应用程序(

在发送SMS时,我收到HTTP请求以及标题X-Twilio-Signature和带有密钥"的表单数据;身体;并重视我的短信内容(到目前为止,我总是尝试使用消息"测试"(

我使用Twilio SDK(最新版本8.29.0(进行如下验证:

RequestValidator requestValidator = new RequestValidator(twilioAuthToken); // "twilioAuthToken" contains the primary auth token (there is no secondary)
String twilioHttpRequest = "https://apim.com/twilio?ApiKey=xxxxxxxxx"; // this url is exactly the one provided in the webhook
String signature= request.getHeader("X-Twilio-Signature");
Map<String, String> paramsTest = new HashMap<>();
paramsTest.put("Body", "test"); // "test" is the sms message i always send
boolean isValid = requestValidator.validate(twilioHttpRequest, paramsTest, signature);

并且验证总是失败

我尝试了很多其他东西:

  • 没有身体
  • 按照twilio网站等上的说明操作,无需sdk。但无济于事

我还注意到,每当我发送短信时,传入的签名总是不同的,这让我认为是使用了日期字段或其他东西来生成它。

任何帮助都将不胜感激!

我终于解决了这个验证问题。

事实证明,我没有使用Twilio发送的所有表单参数(有很多:https://www.twilio.com/docs/messaging/guides/webhook-request)。这就是验证不断失败的原因。

对Spring用户也有很大帮助:https://github.com/mjg123/ValidatingTwilioWebhooks

最新更新