在Android模拟器中运行的本地网站上使用Google的PaymentRequest

时间:2017-06-05 15:44:59

标签: javascript android payment-request-api

我试图在我的Android模拟器中运行的本地网站上测试Google的PaymentRequest api。但是,当我做的时候

var paymentRequest = window.PaymentRequest(//some object here//);

我收到以下错误

"Error: Failed to construct 'PaymentRequest': Must be in a secure context

现在,PaymentRequest将在localhost和https上运行,但是从Android模拟器上的端口运行它,其中uri为10.2.2.01:8000/myUrlHere将失败,因为它不是localhost。有关如何解决这个问题的任何想法?

2 个答案:

答案 0 :(得分:3)

PaymentRequest必须用于安全上下文,它是以下之一:

  1. HTTPS。
  2. 本地主机。
  3. 磁盘上的本地文件。
  4. http:// 10.2.2.01:8000不是安全的上下文,因此您无法在那里使用PaymentRequest。请尝试以下方法之一:

    1. https://10.2.2.01:8000。 (SSL证书必须有效。这意味着URL栏中的锁定图标应为绿色。例如,您可以从https://letsencrypt.org/获取一个。)
    2. https:// localhost:8000。
    3. 文件:///sdcard/index.html

答案 1 :(得分:2)

如果您拥有Android设备,则可以通过USB电缆连接设备并从localhost提供服务来测试您的网站。试试这个:

https://developers.google.com/web/tools/chrome-devtools/remote-debugging/

如果不这样做,您可能希望使用模拟器尝试此工具:

https://ngrok.com/

ngrok允许您从***。ngrok.com域的localhost代理服务。