Node.js / Express:读取XML Post,Amazon IPN

我想使用亚马逊的IPN。 到目前为止,我从来没有使用XML,只是用req.body.param访问POST req.body.param 。 这似乎并没有工作。

亚马逊发送一个结构如下的发布请求:

 POST / HTTP/1.1 x-amz-sns-message-type: Notification x-amz-sns-message-id: 0000000-0000-00000-0000-00000EXAMPLE x-amz-sns-topic-arn: arn:aws:sns:EXAMPLE:11111EXAMPLE:TestTopic x-amz-sns-subscription-arn: arn:aws:sns:EXAMPLE:11111EXAMPLE:TestTopic: EXAMPLE Content-Length: 999 Content-Type: text/plain; charset=UTF-8 Host: ec2-EXAMPLE.compute-1.amazonaws.com Connection: Keep-Alive User-Agent: Amazon Simple Notification Service Agent { Type : Notification, MessageId : xxxxxx-xxxx-xxxx-xxxx-xxxxxEXAMPLE, TopicArn : arn:aws:sns:EXAMPLE:11111EXAMPLE:TestTopic, Message : { NotificationReferenceId: 1111111-1111-11111-1111-11111EXAMPLE, NotificationType: OrderReferenceNotification, SellerId: A3PJMS5WFYSRB4, ReleaseEnvironment: Sandbox, Version: 2013-01-01, NotificationData:<?xml version="1.0" encoding="UTF-8"?> <OrderReferenceNotification xmlns="https://mws.amazonservices.com/ipn/OffAmazonPayments/2013-01-01"> <OrderReference> <AmazonOrderReferenceId>P01-0000000-0000000-000000</AmazonOrderReferenceId> <OrderTotal> <Amount>0.0</Amount> <CurrencyCode>USD</CurrencyCode> </OrderTotal> <SellerOrderAttributes /> <OrderReferenceStatus> <State>Closed</State> <LastUpdateTimestamp>2013-01-01T01:01:01.001Z</LastUpdateTimestamp> <ReasonCode>AmazonClosed</ReasonCode> </OrderReferenceStatus> <CreationTimestamp>2013-01-01T01:01:01.001Z</CreationTimestamp> <ExpirationTimestamp>2013-01-01T01:01:01.001Z</ExpirationTimestamp> </OrderReference> </OrderReferenceNotification>, Timestamp:2013-01-01T01:01:01Z } Timestamp : 2013-01-01T01:01:001Z, SignatureVersion : 1, Signature : rkne..9=kOUhF, SigningCertURL : https://sns.EXAMPLE.amazonaws.com/SimpleNotificationService-aaaaaabbbbbbccccccEXAMPLE.pem, UnsubscribeURL : https://sns.EXAMPLE.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:EXAMPLE:11111EXAMPLE:TestTopic:GUID } 

我的routes.js这条路线是:

 app.post('/approveDonationAmazon', (req, res) -> #receive payment result from paypal # update Database {parseString} = require 'xml2js' console.log "req",req console.log "reqbody",req.body console.log "raw body",req.rawBody if req.body.message? xml = req.body.message parseString xml, (err, result) -> console.dir "result",result #TODO Process Payment Callback # databaseService.approveDonation(db, payment_status, payer_email, mc_gross, (err) -> # # if there is an error retrieving, send the error. nothing after res.json({ err: err }); will execute # if (err) # return res.json({ err: err }) # return true # ) else return res.json({ err: 'no message received' }) ) 

我的服务器日志告诉我,我的variables基本上没有定义:

 2015-05-04 12:57:18.149458500 _remoteAddress: '::1', 2015-05-04 12:57:18.149458500 body: {}, 2015-05-04 12:57:18.149459500 route: 2015-05-04 12:57:18.149459500 { path: '/approveDonationAmazon', 2015-05-04 12:57:18.149462500 stack: [ [Object] ], 2015-05-04 12:57:18.149462500 methods: { post: true } } } 2015-05-04 12:57:18.149462500 reqbody {} 2015-05-04 12:57:18.149463500 raw body undefined 

题:

如何访问消息variables,例如SellerId或Amount?