說明:
目前商戶遇到nodejs基于express3.x架構return_url、notify_url能收到通知并解析資料。針對嫁接到express4.x架構能收到異步請求,req.body為空,無法解析異步資料。本地模拟支付寶處理資料向伺服器發送post請求,可以解析并擷取資料的問題。
原因:
主要是支付寶post異步請求商戶系統,傳回處理結果headers中Content-Type為"application/x-www-form-urlencoded; text/html; charset=utf-8",由于bodyparse版本的問題無法解析。建議去掉“ text/html;”就可以擷取post請求的資訊。
解決方案:
app.use(function (req, res, next){ if (req.url === 'your_alipay_notify_url') { req.headers['content-type'] = 'application/x-www-form-urlencoded'; } next(); }); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended:true}))
資源參考:[url]https://segmentfault.com/q/1010000004122789[/url]
如果大家還有什麼疑問歡迎在文章下方追問吐槽