我使用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
值,我应该怎么做?
答案 0 :(得分:1)
使用json_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");