douzhang7603 2014-02-23 13:37
浏览 42

使用Paypal登录API集成成功的Paypal登录将预期数据返回为空

I have an issue that i can't resolve. I'm trying to create an application on wordpress wherein when a user visits a page it will automatically ask the user to login and authenticate using a paypal account. When successfully log-in, I wanted to display the profile details(first for testing only) and later code it again for the intended use. However, I use the code below, and when I successfully logged, authenticate and get redirected to the redirect_url(meaning the process in logging in and authentication is done correctly) the expected profile details via print_r is empty.

<?php
/* Paypal app details */
$client_id = 'xxxx';    // paypal client id
$client_secret = 'xxx'; // client secret
$scopes = 'email profile';  //e.g. openid email profile https://uri.paypal.com/services/paypalattributes
$app_return_url = 'http://website.ccc/verify/';  // Redirect url
$nonce = time() . rand();

$code = $_REQUEST["code"];

if(empty($code)) {
    #IF the code paramater is not available, load the auth url.
    $state = md5(uniqid(rand(), TRUE)); // CSRF protection
    $paypal_auth_url = "https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize?"
            ."client_id=".$client_id
            ."&response_type=code"
            ."&scope=".$scopes
            ."&nonce=".$nonce
            ."&state=".$state
            ."&redirect_uri=".urlencode($app_return_url);

    header("Location: $paypal_auth_url");     
}else{
    /* GET Access TOKEN */
    $token_url = "https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/tokenservice";    
    $postvals = "client_id=".$client_id
            ."&client_secret=".$client_secret
            ."&grant_type=authorization_code"
            ."&code=".$code;


    $ch = curl_init($token_url);
    $options = array(
                CURLOPT_POST => 1,
                CURLOPT_VERBOSE => 1,
                CURLOPT_POSTFIELDS => $postvals,
                CURLOPT_RETURNTRANSFER => 1,
                CURLOPT_SSLVERSION => 3
    );
    curl_setopt_array( $ch, $options );
    $response = curl_exec($ch);
    curl_close($ch);
    $atoken = json_decode($response);

    /* GET PROFILE DETAILS */
    $profile_url = "https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/userinfo?"
            ."schema=openid"
            ."access_token=".$atoken->access_token;

    $ch = curl_init($profile_url);
    $options = array(
                CURLOPT_RETURNTRANSFER => 1,
                CURLOPT_SSLVERSION => 3
    );
    curl_setopt_array( $ch, $options );
    $response = curl_exec($ch);
    curl_close($ch);
    $profile= json_decode($response,true);  // PROFILE DETAILs in Array format


    /* View the Profile Details */

    echo "<pre>";
    print_r($profile);
    echo "</pre>";
}

?>

Can you help me dig with this?

  • 写回答

1条回答 默认 最新

  • dow98764 2014-05-07 19:01
    关注

    Hi friend simply add '&' on before access token,

    $profile_url = "https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/userinfo?" ."schema=openid" ."**&**access_token=".$atoken->access_token;

    评论

报告相同问题?

悬赏问题

  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿