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

iOS端UPI Intent集成问题:支付完成后无法自动返回App

解决iOS WebView集成Cashfree UPI Intent支付后无法自动返回App的问题

核心排查方向与修复方案

1. 确认Universal Links配置有效性

  • 确保App已正确配置Universal Links:将Cashfree回调域名写入apple-app-site-association文件,部署到域名的.well-known目录下。
  • Xcode中App的Associated Domains需添加对应applinks:前缀域名,例如applinks:your-cashfree-callback-domain.com。
  • 测试验证:在Safari中打开回调链接,若无法直接跳转至App,说明配置存在问题,需重新检查文件格式、域名部署及Xcode配置。

2. 拦截WebView的UPI跳转请求

在iOS的WKWebView中拦截UPI Intent请求,通过原生代码唤起PSP App并指定回调Universal Link,避免WebView直接处理跳转:

func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
    guard let url = navigationAction.request.url else {
        decisionHandler(.allow)
        return
    }
    // 判断是否为UPI协议链接
    if url.scheme == "upi" {
        // 追加回调Universal Link参数
        var components = URLComponents(url: url, resolvingAgainstBaseURL: false)
        components?.queryItems?.append(URLQueryItem(name: "callbackUrl", value: "your-universal-link://payment-callback"))
        guard let modifiedUrl = components?.url else {
            decisionHandler(.allow)
            return
        }
        if UIApplication.shared.canOpenURL(modifiedUrl) {
            UIApplication.shared.open(modifiedUrl, options: [:]) { success in
                if !success {
                    // 处理唤起失败逻辑
                }
            }
            decisionHandler(.cancel)
        } else {
            decisionHandler(.allow)
        }
    } else {
        decisionHandler(.allow)
    }
}

3. 检查Cashfree支付参数配置

  • 发起Cashfree支付请求时,确保return_url参数值为App对应的Universal Link,而非普通HTTP链接。
  • iOS 15+对自定义Scheme跳转限制严格,优先使用Universal Links作为回调地址。

4. 实现Universal Links回调处理

在AppDelegate或SceneDelegate中添加回调处理逻辑,确保App能接收并解析支付结果:

// AppDelegate
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    if userActivity.activityType == NSUserActivityTypeBrowsingWeb, let url = userActivity.webpageURL {
        // 将回调URL加载到WebView,更新支付状态
        webView?.load(URLRequest(url: url))
        return true
    }
    return false
}

// SceneDelegate(iOS 13+)
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
    if userActivity.activityType == NSUserActivityTypeBrowsingWeb, let url = userActivity.webpageURL {
        if let webView = (scene as? UIWindowScene)?.windows.first?.rootViewController?.view as? WKWebView {
            webView.load(URLRequest(url: url))
        }
    }
}

5. 验证PSP App回调行为

部分PSP App(如iOS版Google Pay)对回调格式有特定要求,需确保callbackUrl为HTTPS协议的Universal Link。可直接构造UPI链接在Safari中测试,确认支付完成后是否能自动跳回App,以此排查是Cashfree配置问题还是PSP端限制。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 05:10:27