首页 > 解决方案 > Cordova ios 应用程序在使用 stripe/v3 时自动重定向到 js.stripe.com

问题描述

我正在尝试在我的 Cordova ios 应用程序中实施条带付款。我对我的 android 应用程序做了同样的事情,它工作正常,但使用 ios 我立即被重定向到 URL https://js.stripe.com/v3/m-outer-7e4b9b871fee876475cf1d5d316fe456.html#url=file%3A%2F% 2F%2FUsers%2Fpeter%2FLibrary%2FDeveloper%2FCoreSimulator%2FDevices%2F9D689B57-710A-44FF-A531-209A40951971%2Fdata%2FContainers%2FBundle%2FApplication%2F39452448-BC9C-48CC-A645-30216Capp%2Fwww%Findex.Project. html&title=Hello%20World&referrer=&muid=NA&sid=NA&version=6&preview=false (在cordova应用程序WebView中)。

我看了其他类似的问题。我尝试添加到我的 config.xml:

<allow-navigation href="https://*.stripe.com/*" />

它没有解决将 WebView 重定向到网页的问题,但它现在将我带到另一个网页:https ://m.stripe.network/inner.html#url=file%3A%2F%2F%2FUsers% 2Fpeter%2FLibrary%2FDeveloper%2FCoreSimulator%2FDevices%2F9D689B57-710A-44FF-A531-209A40951971%2Fdata%2FContainers%2FBundle%2FApplication%2F8F59C0AB-C0B4-47B8-BE59-ED7F4BA6Ewww%2FTestProject.html=F%2Findex.html 20World&referrer=&muid=NA&sid=NA&version=6&preview=false

简称为 stripe.network

这既发生在我的主项目上,也发生在专门为这个错误制作的新黑色测试项目上。测试项目有以下文件:

配置文件

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.menumeals.test" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>TestProject</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <access origin="*" />
    <allow-navigation href="https://*.stripe.com/*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
</widget>

索引.html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="initial-scale=1, width=device-width, viewport-fit=cover">
        <meta name="color-scheme" content="light dark">
        <link rel="stylesheet" href="css/index.css">
        <title>Hello World</title>
    </head>
    <body>
        <div class="app">
            <h1>Apache Cordova</h1>
            <div id="deviceready" class="blink">
                <p class="event listening">Connecting to Device</p>
                <p class="event received">Device is Ready</p>
            </div>
            <a href="index2.html">Go to index2</a>
        </div>
        <script src="https://js.stripe.com/v3"></script>
        <script src="cordova.js"></script>
        <script src="js/index.js"></script>
    </body>
</html>

index.js

var app = {

    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
    },
    
    onDeviceReady: function() {
        // Cordova is now initialized. Have fun!
        console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
        document.getElementById('deviceready').classList.add('ready');
    }
}

app.initialize();

当我取出<script src="https://js.stripe.com/v3"></script>页面时不再重定向。

标签: ioscordovastripe-payments

解决方案


我通过将其添加到我的 config.xml 来解决此问题

<allow-navigation href="https://*.stripe.network/*" />
<allow-navigation href="https://*.stripe.com/*" />

允许导航

控制 WebView 本身可以导航到哪些 URL。仅适用于顶级导航。

与允许意图相比

控制允许应用程序要求系统打开哪些 URL。默认情况下,不允许使用任何外部 URL。


推荐阅读