简体   繁体   中英

convert curl to php OAuth2.0 Token Generate Error

<?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" }

use these headers like

curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'Authorization: Basic R1FRWkZWcGpJQ0E5Y2xScUFQZVowODhSQTVYTFgzNzk6QTNLNkxjVHU3OTZ1QTZtxxyy',
    'Content-Type: application/x-www-form-urlencoded')
);

--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");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM