我在服务器端的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密钥,身份验证令牌和Salt。
已解决。
1.转到instamojo帐户下的“应用程序和插件”部分。
2.单击生成凭证按钮
3.在“平台/框架”下选择“ Ionic-SDK”,然后单击“生成”
4.凭据按钮。有客户端ID和客户端密钥。