Yii2-curl oAuth2 与 zoho

Yii2-curl oAuth2 with zoho

我正在研究 Yii2。我有一个 URL,它在点击浏览器时被重定向到我的重定向 URI

URL

https://accounts.zoho.com/oauth/v2/auth?scope=ZohoBugTracker.projects.ALL,ZohoBugTracker.bugs.ALL&client_id=1000&response_type=code&access_type=offline&redirect_uri=http://11.111.111.111:7000/api/oauth/zoho_auth

当我点击上面的 URL 时,它会重定向到我的重定向 URI,同时给出一个代码

重定向 URI

点击上面的 URL 重定向 URI 是 http://11.111.111.111:7000/api/oauth/zoho_auth?code=1000&location=us&accounts-server=https%3A%2F%2Faccounts.zoho.com

重定向 URI 响应

{"Message":"No HTTP resource was found that matches the request URI 'http://11.111.111.111:7000/api/oauth/zoho_auth?code=1000&location=us&accounts-server=https:%2F%2Faccounts.zoho.com'."}

如何从上面的响应中得到 code

更新 1

按照给出的建议。我尝试使用 linslin 发送 GET 请求。下面是我的代码

 public static function authToken()
{

    $curl = new curl\Curl();
    $response = $curl->setGetParams([
        'scope' => 'ZohoBugTracker.projects.ALL,ZohoBugTracker.bugs.ALL',
        'client_id' => '1000',
        'response_type' => 'code',
        'access_type' => 'offline',
        'redirect_uri' => 'http://11.111.111.111:7000/api/oauth/zoho_auth',
    ])
        ->get('https://accounts.zoho.com/oauth/v2/auth');

    echo $response;
    exit();
}

然后在一个函数中调用这个函数,我实际上通过它使用 zoho API

创建错误

正在通过 POSTMAN

测试我的 API

http://localhost:225/inventory-web/api/web/v1/installation/email?ref_no=28373340485858U&customer_id=37030315933&site_snap_name=28373340485858U_1530958224_site_9.jpg&flag=1

我的 email 函数是在 API 控制器中编写的。因此,它将首先命中 issueSetup($param1,$param2)

public function actionEmail()
{
    .
    .
    .
    .

     Installations::setupEmail($param1, $param2, $param3);
    .
    .
    .
}

上面的函数setupEmail($param1,$param2,$param3)在我的控制器里面。

 public static function setupEmail($ref_no, $customer_id, $install_id)
 {
     .
     .
     .
     .
     .
      list(params.....)= Installations::issueSetup($param1,$param2);
     .
     .
     .
     .      
  }

issuSetup 函数

public static function issueSetup($param1,$param2)
{
     .
     .
     .
     .
    $token = Installations::authToken();

    exit();
    .
    .
    .
    . 
}

点击 API 后,我在 POSTMAN 中没有收到任何回复,只有空 window

非常感谢任何帮助。

你试过这个错误吗

if ($curl->errorCode === null) {
   echo $response;
} else {

    echo '<pre>';print_r($curl->errorCode);
} 

当您启用 SSL 并检查响应代码/响应 header 以重定向到 Zuhu 上的 userAuth 表单时,它工作得很好:

$curl = new \linslin\yii2\curl\Curl();

/** @var Curl $response */
$curl->setGetParams([
        'scope' => 'ZohoBugTracker.projects.ALL,ZohoBugTracker.bugs.ALL',
        'client_id' => '1000',
        'response_type' => 'code',
        'access_type' => 'offline',
        'redirect_uri' => 'http://11.111.111.111:7000/api/oauth/zoho_auth',
])->setOption(CURLOPT_SSL_VERIFYPEER, true)
    ->setOption(CURLOPT_SSL_VERIFYHOST, false)
    ->setOption(CURLOPT_CAINFO, 'C:/Ampps/apache/conf/ssl_crt/cacert.pem')
    ->get('https://accounts.zoho.com/oauth/v2/auth');

$responseHeaders = $curl->responseHeaders;

if ($curl->responseCode === 302 && isset($responseHeaders['Location'])) {
    header("location: ".$responseHeaders['Location']);
    die();
}