如何从 Viva 钱包获取 OAuth 2 访问令牌
How to obtain OAuth 2 access token from Viva Wallet
在这一步我需要发送这个参数:
POST https://demo-accounts.vivapayments.com/connect/token HTTP/1.1
Authorization: Basic Z2VuZXJpY19hY3F1aXJpbmdfY2xpZW50LmFwcHMudml2YXBheW1lbnRzLmNvbTpnZW5lcmljX2FjcXVpcmluZ19jbGllbnQ
Accept: application/json
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials
我做了什么:(ACCESS_TOKEN我已经得到)
$ch = curl_init();
$options = array(
CURLOPT_URL => 'https://demo-accounts.vivapayments.com/connect/token',
CURLOPT_POST => 1,
CURLOPT_HEADER => false,
CURLOPT_HTTPAUTH => ACCESS_TOKEN,
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Content-Type: application/x-www-form-urlencoded',
'grant_type=client_credentials'
)
);
curl_setopt_array($ch, $options);
curl_exec($ch);
curl_close($ch);
我收到的错误:
请求错误
您的浏览器发送了该服务器无法理解的请求。
参考#7.85c5d3ba.1606074405.4bd39133
Link API 的那个:(我在步骤 2 中停止:请求访问令牌)
https://developer.vivawallet.com/web-api-integration/authentication/#oauth-2-token-generation
CURLOPT_HTTPAUTH
The HTTP authentication method(s) to use. The options are: CURLAUTH_BASIC, CURLAUTH_DIGEST, CURLAUTH_GSSNEGOTIATE, CURLAUTH_NTLM, CURLAUTH_ANY, and CURLAUTH_ANYSAFE.
CURLOPT_USERPWD
A username and password formatted as "[username]:[password]" to use for the connection.
尝试更新代码以向 /token
端点发送 POST 请求以获取令牌。
您应该在 $result
中找到一个标记:
$credentials = "$login:$password";
$ch = curl_init();
$options = array(
CURLOPT_URL => 'https://demo-accounts.vivapayments.com/connect/token',
CURLOPT_POST => 1,
CURLOPT_HEADER => false,
// Set the auth type as `Basic`
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
// Set login and password for Basic auth
CURLOPT_USERPWD => $credentials,
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Content-Type: application/x-www-form-urlencoded'
),
// To send additional parameters in the POST body
CURLOPT_POSTFIELDS => "grant_type=client_credentials"
);
curl_setopt_array($ch, $options);
// This is the response for your request
$result = curl_exec($ch);
// This is the response status code (if you are interested)
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
查看示例并在此处试用:
https://paiza.io/projects/e/JQJeAZsOlI5m9OFSda4FQQ
在这一步我需要发送这个参数:
POST https://demo-accounts.vivapayments.com/connect/token HTTP/1.1
Authorization: Basic Z2VuZXJpY19hY3F1aXJpbmdfY2xpZW50LmFwcHMudml2YXBheW1lbnRzLmNvbTpnZW5lcmljX2FjcXVpcmluZ19jbGllbnQ
Accept: application/json
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials
我做了什么:(ACCESS_TOKEN我已经得到)
$ch = curl_init();
$options = array(
CURLOPT_URL => 'https://demo-accounts.vivapayments.com/connect/token',
CURLOPT_POST => 1,
CURLOPT_HEADER => false,
CURLOPT_HTTPAUTH => ACCESS_TOKEN,
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Content-Type: application/x-www-form-urlencoded',
'grant_type=client_credentials'
)
);
curl_setopt_array($ch, $options);
curl_exec($ch);
curl_close($ch);
我收到的错误:
请求错误 您的浏览器发送了该服务器无法理解的请求。 参考#7.85c5d3ba.1606074405.4bd39133
Link API 的那个:(我在步骤 2 中停止:请求访问令牌)
https://developer.vivawallet.com/web-api-integration/authentication/#oauth-2-token-generation
CURLOPT_HTTPAUTH
The HTTP authentication method(s) to use. The options are: CURLAUTH_BASIC, CURLAUTH_DIGEST, CURLAUTH_GSSNEGOTIATE, CURLAUTH_NTLM, CURLAUTH_ANY, and CURLAUTH_ANYSAFE.
CURLOPT_USERPWD
A username and password formatted as "[username]:[password]" to use for the connection.
尝试更新代码以向 /token
端点发送 POST 请求以获取令牌。
您应该在 $result
中找到一个标记:
$credentials = "$login:$password";
$ch = curl_init();
$options = array(
CURLOPT_URL => 'https://demo-accounts.vivapayments.com/connect/token',
CURLOPT_POST => 1,
CURLOPT_HEADER => false,
// Set the auth type as `Basic`
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
// Set login and password for Basic auth
CURLOPT_USERPWD => $credentials,
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Content-Type: application/x-www-form-urlencoded'
),
// To send additional parameters in the POST body
CURLOPT_POSTFIELDS => "grant_type=client_credentials"
);
curl_setopt_array($ch, $options);
// This is the response for your request
$result = curl_exec($ch);
// This is the response status code (if you are interested)
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
查看示例并在此处试用: https://paiza.io/projects/e/JQJeAZsOlI5m9OFSda4FQQ