gpt4 book ai didi

php - 来自 curl php 的资源 ID #2 响应

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:00:47 26 4
gpt4 key购买 nike

我正在尝试将此命令行解释为 curl php

curl 命令:

curl https://api.sandbox.paypal.com/v1/oauth2/token \
-H "Accept: application/json" \
-H "Accept-Language: en_US" \
-u "{clientId}:{secret}" \
-d "grant_type=client_credentials"

这是我的 curl php 代码:

$url = 'https://api.sandbox.paypal.com/v1/oauth2/token';
$info = array(
'grant_type' =>'client_credentials'
);
$post_field_string = http_build_query($info, '', '&');

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Accept-Language: en_US')
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD,'AQHeHhDPIpAoxWaNkXOwCNFV4cZUobhqDa_4qHPKh0iDrSd6rLaxIknT-lmgwd:EJHLmhBMT9dB48kou4V0jyJzaq-CqUlY0zS6QKsxOZKI15hZHZjTfoSV7MO8we');
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_field_string );
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_HEADER,1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");

$exec = curl_exec($ch);
curl_exec($ch);

curl_close($ch);

我得到了这个结果:

Resource id #2

我是 curl 的新手,但我正在尝试研究它。那是我的 curl php 中的正确代码吗?

我期待 curl 的这个示例响应:

{
"scope": "https://api.paypal.com/v1/payments/.* https://api.paypal.com/v1/vault/credit-card https://api.paypal.com/v1/vault/credit-card/.*",
"access_token": "EEwJ6tF9x5WCIZDYzyZGaz6Khbw7raYRIBV_WxVvgmsG",
"token_type": "Bearer",
"app_id": "APP-6XR95014BA15863X",
"expires_in": 28800
}

最佳答案

试试这段代码:

CURLOPT_HTTPHEADER 如果您传递的是数组或字符串,则不需要。

已添加

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
绕过 SSL

<?php
$url = 'https://api.sandbox.paypal.com/v1/oauth2/token';
$info = array(
'grant_type' =>'client_credentials'
);
$post_field_string = http_build_query($info, '', '&');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_USERPWD,'ATKsMxDPf23rhQTgixcTYxLfuJoBsTiIRyaSQW_4J8_rNoVQsXHQkBjmBN0z:EOvF6RBizzf9qH2eA_s3PYmQk--smR6Xe8kDws228lq5pA0IebXTg902FY7f');
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_field_string);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_HEADER,1);
$exec = curl_exec($ch);
echo '<pre>';
print_r($exec);
curl_close($ch);

响应:

HTTP/1.1 200 OK Server: Apache-Coyote/1.1

PROXY_SERVER_INFO: host=slcsbjava3.slc.paypal.com;threadId=234251 Paypal-Debug-Id:976e66d30ed12

SERVER_INFO: identitysecuretokenserv:v1.oauth2.token&CalThreadId=138269&TopLevelTxnStartTime=14666662622&Host=slcsbidensectoken502.slc.paypal.com&pid=17346

CORRELATION-ID: 976e66d30ed12

Date: Wed, 04 Jun 2014 10:21:51 GMT

Content-Type: application/json

Transfer-Encoding: chunked

{
"scope": "openid",
"access_token": "A015wXWyeWOj3CprA4dz8uvB.AgGUE-A-p6SuQhw..rmGug",
"token_type": "Bearer",
"expires_in": 28800
}

关于php - 来自 curl php 的资源 ID #2 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24032451/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com