我已经json_decoded了我的paypal rest api响应并得到了这个:
["body"]=> object(stdClass)#4 (8) {
["id"]=> string(28) "PAY-66D616332R6551639KJLSMVQ"
["create_time"]=> string(20) "2013-10-10T22:12:38Z"
["update_time"]=> string(20) "2013-10-10T22:12:39Z"
["state"]=> string(7) "created"
["intent"]=> string(4) "sale"
["payer"]=> object(stdClass)#5 (2) {
["payment_method"]=> string(6) "paypal"
["payer_info"]=> object(stdClass)#6 (0) {}
}
["transactions"]=> array(1) {
[0]=> object(stdClass)#7 (3) {
["amount"]=> object(stdClass)#8 (3) {
["total"]=> string(6) "500.85"
["currency"]=> string(3) "USD"
["details"]=> object(stdClass)#9 (2) {
["subtotal"]=> string(6) "460.90"
["shipping"]=> string(5) "39.95"
}
}
["description"]=> string(43) "Mike and Maureen Photography - Order ID #10"
["item_list"]=> object(stdClass)#10 (1) {
["items"]=> array(2) {
[0]=> object(stdClass)#11 (5) {
["name"]=> string(48) "The Bean-8" x 10" - floating frame - black frame"
["sku"]=> string(7) "20 - 13"
["price"]=> string(6) "160.95"
["currency"]=> string(3) "USD"
["quantity"]=> string(1) "1"
}
[1]=> object(stdClass)#12 (5) {
["name"]=> string(62) "40 Steps and a View-36" x 48" - 0.75" thin gallery wrap canvas"
["sku"]=> string(5) "7 - 6"
["price"]=> string(6) "299.95"
["currency"]=> string(3) "USD"
["quantity"]=> string(1) "1"
}
}
}
}
}
["links"]=> array(3) {
[0]=> object(stdClass)#13 (3) {
["href"]=> string(79) "https://api.sandbox.paypal.com/v1/payments/payment/PAY-66D616332R6551639KJLSMVQ"
["rel"]=> string(4) "self"
["method"]=> string(3) "GET"
}
[1]=> object(stdClass)#14 (3) {
["href"]=> string(94) "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-1XB37931V5368954G"
["rel"]=> string(12) "approval_url"
["method"]=> string(8) "REDIRECT"
}
[2]=> object(stdClass)#15 (3) {
["href"]=> string(87) "https://api.sandbox.paypal.com/v1/payments/payment/PAY-66D616332R6551639KJLSMVQ/execute"
["rel"]=> string(7) "execute"
["method"]=> string(4) "POST"
}
}
}
我正在尝试检查“状态”的值,但我似乎无法弄清楚如何引用该值。我试过:($result
是数组所在的变量)
$result['body']['state']
$result['state']
$body['state']
这些都不起作用,所以谁能告诉我如何在混乱中引用关键的“状态”?我通常很擅长使用 PHP,但由于某种原因,我无法弄清楚这一点。
谢谢你的帮助。
编辑
我已经格式化了响应,以便更容易准备,但我坚持选择 [1] href 值。如果我基于前面的示例,我会使用
$result['body']->link 但我如何才能超越 [1] 中的特定 href?