我有access_token,核心ID和金额。 请在CURL php中提供解决方案。 GIT网址 https://github.com/paypal/PayPal-iOS-SDK/blob/master/docs/future_payments_server.md
curl 'https://api.paypal.com/v1/payments/payment' \
-H "Content-Type: application/json" \
-H "PayPal-Client-Metadata-Id: c2edbd6e97b14ff2b19ddb8eec9d264c" \
-H "Authorization: Bearer WfXdnxmyJtdF4q59ofxuQuAAk6eEV-Njm6puht3Nk3w" \
-d '{
"intent":"authorize",
"payer":{
"payment_method":"paypal"
},
"transactions":[
{
"amount":{
"currency":"USD",
"total":"1.88"
},
"description":"future of sauces"
}
]
}'
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/payment");
curl_setopt($ch, CURLOPT_HEADER, "Content-Type: application/json");
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HEADER, "PayPal-Client-Metadata-Id: 10aab1a2e941462096ca8aba539784f3");
curl_setopt($ch, CURLOPT_HEADER, "Authorization: Bearer A103.Ekl88t1fnvoypD1F7HZDt3X-jzmxm6rxMxW6QtI79iIJdgDaDiIO8luWS-C1D-0z.h2YAz4LujULmTjQXcPjF8_ImbV0");
curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{
"intent":"authorize",
"payer":{
"payment_method":"paypal"
},
"transactions":[
{
"amount":{
"currency":"USD",
"total":"1.88"
},
"description":"future of sauces"
}
]
}');
**using curl Php**
$result1 = curl_exec($ch);
$information = curl_getinfo($ch);
curl_close($ch);
print_r($result1);
print_r($information);die;
返回卷曲信息 1Array ( [url] => https://api.sandbox.paypal.com/v1/payments/payment [content_type] =>应用程序/ JSON [http_code] => 401 [header_size] => 520 [request_size] => 514 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 1.542536 [namelookup_time] => 0.341438 [connect_time] => 0.628821 [pretransfer_time] => 1.237494 [size_upload] => 363 [size_download] => 0 [speed_download] => 0 [speed_upload] => 235 [download_content_length] => 0 [upload_content_length] => 363 [starttransfer_time] => 1.542478 [redirect_time] => 0 [redirect_url] => [primary_ip] => 173.0.82.78 [certinfo] =>排列 ( )
[primary_port] => 443
[local_ip] => 115.112.59.164
[local_port] => 58225
[request_header] => POST /v1/payments/payment HTTP/1.1
主持人:api.sandbox.paypal.com 接受: / 内容长度:363 内容类型:application / x-www-form-urlencoded
答案 0 :(得分:0)
至少,此代码存在您要发送的HTTP标头的问题。
CURLOPT_HEADER
,设置为true
时,会导致HTTP响应标头包含在cURL响应中。
要发送HTTP标头,您需要使用CURLOPT_HTTPHEADER
并传递标头数组。
看起来像这样:
$headers = array(
'Content-Type: application/json',
'PayPal-Client-Metadata-Id: 10aab1a2e941462096ca8aba539784f3',
'Authorization: Bearer A103.Ekl88t1fnvoypD1F7HZDt3X-jzmxm6rxMxW6QtI79iIJdgDaDiIO8luWS-C1D-0z.h2YAz4LujULmTjQXcPjF8_ImbV0',
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
您还需要致电curl_setopt($ch, CURLOPT_POST, 1);
以实际发送POST请求。