我正在建立第三方API的支付集成。发送请求后,我收到终端的回复。我需要的是在视图中获取表单中的令牌。如何访问令牌值?
Started GET "/charges/charge" for 127.0.0.1 at 2017-06-09 14:28:48 +0300
Processing by ChargesController#charge as HTML"{\"status\":\"success\",\"systemTime\":1497007730319,\"conversationId\":\"123456789\",\"token\":\"4d4b7364-acf7-45df-9fbc-d680212ab9ba\",\"checkoutFormContent\":\"<script type=\\\"text/javascript\\\">if (typeof pay == 'undefined') {var pay = {token:\\\"4d4b7364-acf7-45df-9fbc-d680212ab9ba\\\",price:1.20,}</script>\
答案 0 :(得分:1)
This is the json response which you are getting from payment getway. So you will need to parse it. You can parse this json response like this
response = "{\"status\":\"success\",\"systemTime\":1497007730319,\"conversationId\":\"123456789\",\"token\":\"4d4b7364-acf7-45df-9fbc-d680212ab9ba\"}"
parsed_response = JSON.parse(response) # This will return you hash
token = parsed_response['token']