首页 > 解决方案 > Yii2-curl oAuth2 与 zoho

问题描述

我正在努力Yii2。我有一个URL在点击浏览器时被重定向到我的重定向URI

网址

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":"未找到与请求 URI ' http://11.111.111.111:7000/api/oauth/zoho_auth?code=1000&location=us&accounts-server=https:%2F%2Faccounts.zoho 匹配的 HTTP 资源。 com '。”}

如何code从上述响应中获得?

更新 1

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

 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 创建错误

测试我的API通过POSTMAN

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);
     .
     .
     .
     .      
  }

问题设置功能

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

    exit();
    .
    .
    .
    . 
}

击中后API,我在 POSTMAN 中没有得到任何响应,只是空窗口

在此处输入图像描述

任何帮助将不胜感激。

标签: urlyii2uriyii2-advanced-appzoho

解决方案


当您启用 SSL 并检查响应代码/响应标头以重定向到 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();
}

推荐阅读