Php paypal中的验证码错误无效

Php paypal中的验证码错误无效,php,paypal,paypal-sandbox,Php,Paypal,Paypal Sandbox,我正在尝试使用授权代码获取访问令牌、刷新令牌等。我正在使用以下代码,但它会产生此错误:验证代码无效。我正在对客户端ID和机密ID使用沙盒凭据 我从iOs设备接收$PaypalToken。 那么问题是什么呢 这是最初的paypal请求: 卷曲'\ -H“内容类型:应用程序/x-www-form-urlencoded”\ -H“授权:基本QWZV…=”\ -d'授权类型=授权类型=代码和响应类型=令牌和重定向类型=urn:ietf:wg:oauth:2.0:oob和代码=EBYhRW3ncivudQ

我正在尝试使用授权代码获取访问令牌、刷新令牌等。我正在使用以下代码,但它会产生此错误:
验证代码无效
。我正在对客户端ID和机密ID使用沙盒凭据

我从iOs设备接收
$PaypalToken

那么问题是什么呢

这是最初的paypal请求:

卷曲'\
-H“内容类型:应用程序/x-www-form-urlencoded”\
-H“授权:基本QWZV…=”\
-d'授权类型=授权类型=代码和响应类型=令牌和重定向类型=urn:ietf:wg:oauth:2.0:oob和代码=EBYhRW3ncivudQn8UopLp4A28…'

PHP代码:

$host2 = 'https://api.sandbox.paypal.com/v1/oauth2/token';
$clientId = 'XXXXXXX';
$clientSecret = 'xxxxxx';
$PaypalToken = $values->Token;
$postdata = 'grant_type=authorization_code&response_type=token&redirect_uri=urn:ietf:wg:oauth:2.0:oob&code='.$PaypalToken;
//$postdata = 'grant_type=client_credentials&response_type=token&code=wwwwwwwwwwwww';
//$postdata = 'grant_type=client_credentials';
$curl = curl_init($host2);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_USERPWD, $clientId.":".$clientSecret);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
# curl_setopt($curl, CURLOPT_VERBOSE, TRUE);
$response = curl_exec( $curl );
// Convert the result from JSON format to a PHP array
$json_response = json_decode($response,true);
if (empty($response)) {
    curl_close($curl); // close cURL handler
    $returnArr['Success'] = 0;
    $returnArr['Message'] = $json_response['error_description'];
    echo json_encode($returnArr);exit;
} else {
    $info = curl_getinfo($curl);
    //echo "<pre>";print_r($info);print_r($response);
    curl_close($curl);
    if($info['http_code'] != 200 && $info['http_code'] != 201 ) {
        $returnArr['Success'] = 0;
        $returnArr['Message'] = $json_response['error_description'];
        echo json_encode($returnArr);exit;
    }
}
echo "<pre>";print_r($json_response); 
$host2='1!'https://api.sandbox.paypal.com/v1/oauth2/token';
$clientId='XXXXXXX';
$clientSecret='xxxxxx';
$PaypalToken=$values->Token;
$postdata='grant\u type=authorization\u code&response\u type=token&redirect\u uri=urn:ietf:wg:oauth:2.0:oob&code='。$PaypalToken;
//$postdata='grant\u type=client\u credentials&response\u type=token&code=WWWWWWW';
//$postdata='grant_type=client_-credentials';
$curl=curl_init($host2);
curl_setopt($curl,CURLOPT_POST,true);
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($curl,CURLOPT_USERPWD,$clientId.:“$clientSecret);
curl_setopt($curl,CURLOPT_头,false);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_POSTFIELDS,$postdata);
#curl_setopt($curl,CURLOPT_VERBOSE,TRUE);
$response=curl\u exec($curl);
//将结果从JSON格式转换为PHP数组
$json\u response=json\u decode($response,true);
if(空($response)){
curl_close($curl);//close curl处理程序
$returnArr['Success']=0;
$returnArr['Message']=$json_response['error_description'];
echo json_encode($returnArr);退出;
}否则{
$info=curl\u getinfo($curl);
//回显“;打印($info);打印($response);
curl_close($curl);
如果($info['http\u code']!=200&&$info['http\u code']!=201){
$returnArr['Success']=0;
$returnArr['Message']=$json_response['error_description'];
echo json_encode($returnArr);退出;
}
}
回声“;打印($json\U响应);
如果我更改
$postdata='grant_type=client_credentials'然后返回以下内容:

排列 ( [范围]=>openid.*.*
[访问令牌]=>A015KRoybqmm6eJqEzxX65jtGsd-L96g20KsAugrvSkB
[令牌类型]=>承载
[应用程序id]=>app-80W284485P519543T
[expires_in]=>28800
)

那么如何获取访问令牌,刷新令牌呢?
提前谢谢。

我想这不是你的问题

你的代码完全正确

请您的移动应用程序开发人员将Paypal环境设置为沙箱。它可能在非网络上

因为我已经有一次面对过这个问题

祝你好运。让我知道你的答案


问候。

谢谢你的回答。这是有用的。