2
我试图创建一个webhook请求来测试本地,库 给出了一个错误。我通过发送测试生成请求的主体 balance.available webhook here: https://dashboard.stripe.com/test/webhooks/we_1BI2E2IYOmXNPhc1uOyyRvHg 我复制正文并将其放入文件/tmp/stripe.webhook.json.tmp。 该文档描述了如何生成签名: https://stripe.com/docs/webhooks#signatures如何在本地生成签名的Stripe休息webhook请求?
$ date +%s
1509229775
$ cat /tmp/stripe.webhook.tmp | openssl dgst -hmac whsec_nRZzpzBajM5zBLxnyFAHNZLkLLEu5Xlj -sha256
(stdin)= de2da72d739f0bdf0e2289eab5ac131f51cdd35af8f9c1f1224333b53abde9f7
$ curl -s -X POST http://localhost:3000/stripe/webhook -H "Stripe-Signature: t=1509229775,v1=de2da72d739f0bdf0e2289eab5ac131f51cdd35af8f9c1f1224333b53abde9f7" -d @/tmp/stripe.webhook.json.tmp | head -2
Invalid signature.
$ head -2 /tmp/stripe.webhook.tmp
1509229775.{
"created": 1326853478,
$ head -2 /tmp/stripe.webhook.json.tmp
{
"created": 1326853478,
def webhook
payload = request.body.read
sig_header = request.env['HTTP_STRIPE_SIGNATURE']
endpoint_secret = ENV['STRIPE_WEBHOOK']
event = nil
begin
event = Stripe::Webhook.construct_event(payload, sig_header,
endpoint_secret)
rescue JSON::ParserError => e
# Invalid payload
render plain: "Invalid JSON.", status: 400
return
rescue Stripe::SignatureVerificationError => e
# Invalid signature
render plain: "Invalid signature.", status: 400
return
end
哇,工作!我不知道'-d'剥掉了字符! – Chloe
对不对?这不是很明显。我正在努力解决类似问题,只通过检查发送的原始请求来了解这一点。 – duck