0

我在服务器端的 ionic 中集成了 instamojo 支付网关,我在下面放置了访问令牌的代码

<?php

class Instamojo
{
    private $client_id;
    private $client_secret;
    private $url = "https://api.instamojo.com/oauth2/token/";
    private $env = "production";

    public function __construct($client_id, $client_secret)
    {
        $this->client_id = $client_id;
        $this->client_secret = $client_secret;
    }

    public function getToken() {
        if (substr( $this->client_id, 0, 5 ) === "test_") {
            $this->url = "https://test.instamojo.com/oauth2/token/";
            $this->env = "test";
        }
        $curl = curl_init($this->url);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, rawurldecode(http_build_query(array(
            'client_id' => $this->client_id,
            'client_secret' => $this->client_secret,
            'grant_type' => 'client_credentials'
        ))));
        $json = json_decode(curl_exec($curl));
        if(curl_error($curl))
        {
            echo 'error:' . curl_error($curl);
        }
        if (isset($json->error)) {
            return "Error: " . $json->error;
            throw new \Exception("Error: " . $json->error);
        }
        $this->token = $json;
        return $this->env . $json->access_token;
    }
}

$instamojo = new Instamojo("Client ID", "Client Secret");
echo $instamojo->getToken();
?>

当我在 url 中运行此代码时出现错误“错误:invalid_client”。如何从 instamojo 帐户获取客户端 ID 和客户端密码。在 instamojo 中,我在 api 和插件部分仅获得 API 密钥、Auth Token 和 Salt。

解决了。 1. 前往 instamojo 账户下的 App & Plugin 部分。2. 点击 Generate Credentials 按钮 3. 在 Platform/Framework 下选择 Ionic-SDK 然后点击 Generate
4. Credentials 按钮。获得客户端 ID 和客户端密码。

4

0 回答 0