【发布时间】:2017-06-07 05:52:54
【问题描述】:
因为我需要在我的项目中使用贝宝付款。这是我从paypal官方页面得到的。https://developer.paypal.com/docs/api/payments.payouts-batch/
curl -v -X POST https://api.sandbox.paypal.com/v1/payments/payouts \
-H "Content-Type:application/json" \
-H "Authorization: Bearer Access-Token" \
-d '{
"sender_batch_header": {
"sender_batch_id": "2014021801",
"email_subject": "You have a payout!"
},
"items": [
{
"recipient_type": "EMAIL",
"amount": {
"value": "9.87",
"currency": "USD"
},
"note": "Thanks for your patronage!",
"sender_item_id": "201403140001",
"receiver": "anybody01@gmail.com"
},
{
"recipient_type": "PHONE",
"amount": {
"value": "112.34",
"currency": "EUR"
},
"note": "Thanks for your support!",
"sender_item_id": "201403140002",
"receiver": "91-734-234-1234"
},
{
"recipient_type": "PHONE",
"amount": {
"value": "5.32",
"currency": "USD"
},
"note": "Thanks for your patronage!",
"sender_item_id": "201403140003",
"receiver": "408-234-1234"
},
{
"recipient_type": "PHONE",
"amount": {
"value": "5.32",
"currency": "USD"
},
"note": "Thanks for your patronage!",
"sender_item_id": "201403140004",
"receiver": "408-234-1234"
}
]
}'
由此我能够在 php 中实现这一点。
$ch = curl_init();
$header_object = (object) array('sender_batch_header'=>(object) array('sender_batch_id'=>"2014021801",'email_subject'=>"you got that"));
$data_array = array('items'=>array(
"recipient_type"=>"EMAIL",'amount'=>array('value'=>'9.87','CAD'),'note'=>'get your money',"sender_item_id"=>"232211",'receiver'=>"prabhs36@gmail.com"));
$data = array($header_object,$data_array);
// print_r($object);
// die();
$c_header = ['Content-Type'=>'application/json"',
'Authorization'=>'Bearer access_token_string_was_here'];
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/payouts");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER,$c_header);
// curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_POSTQUOTE, $data);
// grab URL and pass it to the browser
$data_2 = curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
我实际上无法理解这里的 -d 是什么意思,所以我可以理解,或者我认为是,$data 变量是我所做的。但我收到类 std 类的对象无法转换为字符串的错误。和数组到字符串的转换。
谁能真正告诉我哪里出了问题,应该怎么做。
【问题讨论】:
-
std 类是您得到的响应。当您收到错误时,问题将是处理响应