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

Expo React Native中Stripe Connect完成后跳转回APP的实现咨询

一、Expo 项目端基础配置

1. 配置 app.json

在项目根目录的 app.json 中添加 Deep Link 协议和 Universal Link 关联域名:

{
  "expo": {
    "scheme": "yourapp", // 自定义Deep Link协议,比如 "yourshop"
    "associatedDomains": [
      "applinks:yourdomain.com" // 替换为你的实际域名,用于Universal Link
    ],
    // 保留原有其他配置
  }
}

2. 监听链接跳转逻辑

在项目入口文件(如 App.js)中,用 Linking API 处理跳转回来的链接:

import { Linking, useEffect } from 'react-native';

useEffect(() => {
  const handleRedirect = async (url) => {
    // 识别Stripe跳转回来的请求,做后续业务逻辑
    if (url.includes('stripe-redirect')) {
      console.log('用户完成Stripe开户,跳转回APP:', url);
      // 可解析URL参数(如status),更新用户状态或展示结果
    }
  };

  // 初始化时检查是否有未处理的跳转链接
  Linking.getInitialURL().then(handleRedirect);
  // 添加实时链接监听
  const subscription = Linking.addEventListener('url', (event) => handleRedirect(event.url));

  return () => subscription.remove();
}, []);

1. iOS:配置 apple-app-site-association 文件

在你的域名根目录或 .well-known 目录下,创建无后缀的 apple-app-site-association 文件,内容如下:

{
  "applinks": {
    "apps": [],
    "details": [
      {
        "appID": "你的苹果团队ID.项目BundleID",
        "paths": ["*"] // 可按需限制路径,比如 "/stripe-redirect/*"
      }
    ]
  }
}

注意:该文件必须通过 HTTPS 直接访问,不能有重定向。

在域名 .well-known 目录下创建 assetlinks.json 文件,内容:

[
  {
    "relation": ["delegate_permission/common.handle_all_urls"],
    "target": {
      "namespace": "android_app",
      "package_name": "你的安卓包名",
      "sha256_cert_fingerprints": ["你的安卓签名SHA256指纹"]
    }
  }
]

SHA256 指纹可通过命令 keytool -list -v -keystore 你的签名文件.jks 获取。

三、调整 Stripe 重定向与 Deno Edge Function

1. 修改重定向 URL

在 Deno Edge Function 中,将 Stripe 账户链接的 return_url 替换为你的 Deep Link 或 Universal Link:

// Deno Edge Function 代码片段
const accountLink = await stripe.accountLinks.create({
  account: 'acct_xxx',
  refresh_url: 'https://yourdomain.com/stripe-refresh', // 保留HTTPS刷新链接
  return_url: 'yourapp://stripe-redirect?status=completed', // 替换为你的Deep Link
  type: 'account_onboarding',
});

如果用 Universal Link,就写 https://yourdomain.com/stripe-redirect?status=completed。

2. 保持 WebBrowser 调用逻辑

继续使用 WebBrowser.openAuthSessionAsync 打开 Stripe 开户链接即可:

import * as WebBrowser from 'expo-web-browser';

const openStripeOnboarding = async (stripeLink) => {
  const result = await WebBrowser.openAuthSessionAsync(stripeLink);
  if (result.type === 'success') {
    // 可补充跳转成功后的逻辑
  }
};

四、测试验证

  • Deep Link 测试:在浏览器输入 yourapp://stripe-redirect?status=success,确认能唤起APP。
  • Universal Link 测试:在 Safari(iOS)或 Chrome(安卓)打开你的域名链接,确认直接跳转APP。
  • 完整流程测试:走一遍Stripe开户流程,验证完成后自动跳回APP并触发监听逻辑。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 19:01:13