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

如何通过客户邮箱地址获取Stripe Connect关联账户的AccountID

实现思路

Stripe 官方的「列出所有关联账户」接口没有提供直接按邮箱筛选的参数,你可以按照以下逻辑实现匹配:

  • 调用 v1/accounts 接口拉取平台下所有关联的 Connect 账户,单接口最多可拉取100条数据,若账户总量超过100需要自行处理分页逻辑
  • 遍历接口返回的 data 数组,逐一对比每个账户的 email 字段和目标客户的邮箱
  • 匹配成功后直接取对应账户的 id 字段,即为你需要的打款用 Account ID
代码示例

cURL 示例

你可以配合 jq 工具直接在命令行完成筛选,代码如下:

# 替换为你的Stripe密钥和待匹配的目标邮箱
STRIPE_SECRET_KEY="sk_test_xxxxxx"
TARGET_EMAIL="customer@example.com"

# 调用接口并筛选对应Account ID
curl -G https://api.stripe.com/v1/accounts \
  -u "$STRIPE_SECRET_KEY:" \
  -d limit=100 \
  | jq -r '.data[] | select(.email == "'"$TARGET_EMAIL"'") | .id'

PHP 示例

使用Stripe官方PHP SDK实现,先通过Composer安装依赖:composer require stripe/stripe-php

<?php
require 'vendor/autoload.php';

// 初始化Stripe客户端
$stripe = new \Stripe\StripeClient('sk_test_xxxxxx');
$targetEmail = 'customer@example.com';
$targetAccountId = null;

// 拉取关联账户列表
$accounts = $stripe->accounts->all(['limit' => 100]);
foreach ($accounts as $account) {
    if ($account->email === $targetEmail) {
        $targetAccountId = $account->id;
        break;
    }
}

// 输出结果
if ($targetAccountId) {
    echo "匹配到的Account ID:" . $targetAccountId;
} else {
    echo "未找到对应邮箱的关联账户";
}
?>

Java 示例

使用Stripe官方Java SDK实现:

import com.stripe.Stripe;
import com.stripe.model.Account;
import com.stripe.model.AccountCollection;
import com.stripe.param.AccountListParams;

public class SearchStripeAccount {
    public static void main(String[] args) {
        Stripe.apiKey = "sk_test_xxxxxx";
        String targetEmail = "customer@example.com";
        String targetAccountId = null;

        try {
            AccountListParams params = AccountListParams.builder().setLimit(100L).build();
            AccountCollection accounts = Account.list(params);
            
            for (Account account : accounts.getData()) {
                if (targetEmail.equals(account.getEmail())) {
                    targetAccountId = account.getId();
                    break;
                }
            }

            if (targetAccountId != null) {
                System.out.println("匹配到的Account ID:" + targetAccountId);
            } else {
                System.out.println("未找到对应邮箱的关联账户");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

注意:如果你的平台关联账户总量超过100,需要处理分页逻辑拉取全量账户后再筛选,避免遗漏匹配结果。

内容的提问来源于stack exchange,提问作者Abdelkarim Darouy

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.25 14:36:07