You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过Plaid连接银行账户时触发内部错误的排查求助

通过Plaid连接银行账户时触发内部错误的排查求助

各位好,我最近在做通过Plaid对接银行账户的功能,但每次尝试连接都会弹出内部错误提示:
Something went wrong, Internal error occurred.

![错误提示截图]

下面是我目前写的前端JavaScript代码,用来初始化Plaid Link:

<button id="link-button">Link Bank Account</button>
<script type="text/javascript" src="https://cdn.plaid.com/link/v2/stable/link-initialize.js"></script>
<script type="text/javascript">
    var linkHandler = Plaid.create({
        clientName: '<?php echo $case->name; ?>',
        env: '<?php echo getenv("PLAID_ENVIRONMENT"); ?>', // 环境根据实际情况设为development/production
        key: '<?php echo getenv("PLAID_CLIENT_ID"); ?>', // 替换为自己的Plaid公钥
        product: ['balance'], // 也可以用transactions等其他产品
        onSuccess: function(public_token, metadata) {
            console.log('Plaid Link success!');
            console.log(public_token);
            console.log(metadata);
            // 这里把public_token传给后端换取access_token
            fetch('/admin/api/plaid.php', {
                    method: 'POST',
                    body: JSON.stringify({
                        public_token: public_token
                    }),
                    headers: {
                        'Content-Type': 'application/json'
                    }
                })
                .then(response => response.json())
                .then(data => {
                    console.log('Access token received:', data.access_token);
                });
        },
        onExit: function(err, metadata) {
            console.log('Plaid Link exited');
            console.log(err, metadata);
        }
    });

    document.getElementById('link-button').onclick = function() {
        console.log('Button clicked, opening Plaid Link...');
        linkHandler.open();
    };
</script>

然后是处理请求的后端plaid.php文件,我怀疑会不会是这里的逻辑有问题,但自己摸不准:

require 'vendor/autoload.php';

use TomorrowIdeas\Plaid\Plaid;

$plaid = new Plaid(
    \getenv("PLAID_CLIENT_ID"),
    \getenv("PLAID_CLIENT_SECRET"),
    \getenv("PLAID_ENVIRONMENT")
);

// 从请求体获取前端传的public_token
$data = json_decode(file_get_contents('php://input'), true);
$public_token = $data['public_token'];

try {
    $response = $plaid->items->get("access_token");
    print_r($response);
} catch (\TomorrowIdeas\Plaid\PlaidRequestException $e) {
    echo "Error: " . $e->getMessage() . "\n";
    var_dump($e); // 查看异常详情
}
$item = $plaid->items->get("itm_1234");
exit();

另外还有个奇怪的点:

浏览器控制台里完全没有任何错误信息
![控制台无错误截图]

我翻了好多Plaid的PHP相关文档,但资料特别少,联系Plaid的支持也没得到实质性的帮助,有没有大佬能帮我分析下这个内部错误可能出在什么地方?

备注:内容来源于stack exchange,提问作者Roizy Kish

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.15 03:43:03