如何使用PHP重定向到从JSON响应接收的URL

如何使用PHP重定向到从JSON响应接收的URL,php,Php,我使用process.php发布到API并接收以下响应 { "payment_request": { "id": "554efa8b701c4021be7310b8916cc30b", "phone": null, "email": null, "buyer_name": null, "amount": "12", "purpose": "product-sleek", "status": "Pending", "send_sms": fal

我使用
process.php
发布到API并接收以下响应

{ "payment_request": 
  { 
  "id": "554efa8b701c4021be7310b8916cc30b", 
  "phone": null, 
  "email": null, 
  "buyer_name": null, 
  "amount": "12", 
  "purpose": "product-sleek", 
  "status": "Pending", 
  "send_sms": false, 
  "send_email": false, 
  "sms_status": null, 
  "email_status": null, 
  "shorturl": null, 
  "longurl": "https://www.example.com/@user/554efa8b701c4021be7310b8916cc30b", 
  "redirect_url": "https://example.com/order-received/", 
  "webhook": null,
  "created_at": "2016-04-06T05:01:04.042Z",
  "modified_at": "2016-04-06T05:01:04.042Z", 
  "allow_repeated_payments": false 
  }, 
"success": true 
}

现在,在收到响应后,我想将页面重定向到响应json中的
longurl
值,我应该如何做?

使用
json\u decode
解析
array
object
中的json,然后使用
header
函数重定向它

$json = '{ "payment_request":
  {
  "id": "554efa8b701c4021be7310b8916cc30b",
  "phone": null,
  "email": null,
  "buyer_name": null,
  "amount": "12",
  "purpose": "product-sleek",
  "status": "Pending",
  "send_sms": false,
  "send_email": false,
  "sms_status": null,
  "email_status": null,
  "shorturl": null,
  "longurl": "https://www.example.com/@user/554efa8b701c4021be7310b8916cc30b",
  "redirect_url": "https://example.com/order-received/",
  "webhook": null,
  "created_at": "2016-04-06T05:01:04.042Z",
  "modified_at": "2016-04-06T05:01:04.042Z",
  "allow_repeated_payments": false
  },
"success": true
}';

$json_array = json_decode($json, true);

$longurl = $json_array['payment_request']['longurl'];

header("Location: $longurl");

非常感谢。正是我需要的。