<?php
$certFile = "/etc/apache2/ssl/thasaix/thasaix_com.crt";
$keyFile = "/etc/apache2/ssl/thasaix/thasaix.com.key";
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSLCERT, $certFile);
curl_setopt($curl, CURLOPT_SSLKEY, $keyFile);
curl_setopt($curl, CURLOPT_URL, 'https://openapi-test.kasikornbank.com/v2/oauth/token');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
$headers = array();
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
$headers[] = 'Authorization: Basic R1FRWkZWcGpJQ0E5Y2xScUFQZVowODhSQTVYTFgzNzk6QTNLNkxjVHU3OTZ1QTZtxxyy';
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$data = array('grant_type' => 'client_credentials');
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($curl);
curl_close($curl);
print $response;
?>
curl --cert /etc/apache2/ssl/thasaix/thasaix_com.crt
--key /etc/apache2/ssl/thasaix/thasaix.com.key
--location --request POST 'https://openapi-test.kasikornbank.com/v2/oauth/token'
--header 'Content-Type: application/x-www-form-urlencoded'
--header 'Authorization: Basic R1FRWkZWcGpJQ0E5Y2xScUFQZVowODhSQTVYTFgzNzk6QTNLNkxjVHU3OTZ1QTZtxxyy'
--data-urlencode 'grant_type=client_credentials'
the result is
{ "code": "openapi_error", "message": "OAuth2.0 Token Generate Error" }
CodePudding user response:
use these headers like
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Authorization: Basic R1FRWkZWcGpJQ0E5Y2xScUFQZVowODhSQTVYTFgzNzk6QTNLNkxjVHU3OTZ1QTZtxxyy',
'Content-Type: application/x-www-form-urlencoded')
);
CodePudding user response:
--data-urlencode 'grant_type=client_credentials'
Should be body part then I change code and it work
curl_setopt($curl, CURLOPT_POSTFIELDS, "grant_type=client_credentials");