php - 返回“无法发布 /index.php”的 HTML 按钮
问题描述
我正在尝试激活作为 Stripe Connect 功能的 index.php 文件。但是,当我按下我的 HTML 页面上的按钮来激活该功能时,它会导致Cannot POST /pages/index.php
. HTML 和 PHP 文件都在同一个文件夹中。我想要做的是自动化这个:https ://stripe.com/docs/connect/express-accounts#token-request
代码
<form action="input.php" method="post">
<input type="submit" class="bg-transparent text-grey-darkest font-bold uppercase tracking-wide py-3 px-6 border-2 border-grey-light hover:border-grey rounded-lg" value="Continue">
</form>
PHP代码
<?php
define('CLIENT_ID', 'ca_xxxxxxx');
define('API_KEY', 'sk_xxxxxxx');
define('TOKEN_URI', 'https://connect.stripe.com/oauth/token');
define('AUTHORIZE_URI', 'https://connect.stripe.com/oauth/authorize');
if (isset($_GET['code'])) { // Redirect w/ code
$code = $_GET['code'];
$token_request_body = array(
'client_secret' => API_KEY,
'grant_type' => 'authorization_code',
'client_id' => CLIENT_ID,
'code' => $code,
);
$req = curl_init(TOKEN_URI);
curl_setopt( $ch, CURLOPT_USERAGENT, '' );
curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
curl_setopt($req, CURLOPT_POST, true);
curl_setopt($req, CURLOPT_POSTFIELDS, http_build_query($token_request_body));
// TODO: Additional error handling
$respCode = curl_getinfo($req, CURLINFO_HTTP_CODE);
$resp = json_decode(curl_exec($req), true);
curl_close($req);
echo $resp['access_token'];
} else if (isset($_GET['error'])) { // Error
echo $_GET['error_description'];
} else { // Show OAuth link
$authorize_request_body = array(
'response_type' => 'code',
'scope' => 'read_write',
'client_id' => CLIENT_ID
);
$url = AUTHORIZE_URI . '?' . http_build_query($authorize_request_body);
echo "<a href='$url'>Connect with Stripe</a>";
}
?>
解决方案
推荐阅读
- ruby - 如何使用 Ruby 和 Selenium 在 input='file' 不存在时使用发送键
- c++ - CMake 项目无法与 Boost.Test 静态或动态链接
- python - 通过单独的 .py 文件编写更简洁的 Python 代码
- angular - 在 Azure Pipelines 中集成 Angular 测试用例
- css - webpack-cdn-plugin 不在 head 中导入 CSS
- python - 如何在Python上逐行填充空矩阵?
- c++ - 试图创建一个空的类列表并用指针引用它
- python - 无法使用 Gzip 解压缩 DES3 加密数据
- uwp - 一次只能注册一个 PrintTaskRequested 事件的处理程序 UWP 打印错误
- excel - Excel crash after Copy and paste Chart image