微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法从 Apple Pay 获得任何响应 - 此资源来自本地覆盖

如何解决无法从 Apple Pay 获得任何响应 - 此资源来自本地覆盖

我正在整合apple pay 并关注支付请求API! 根据文档 (https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_js_api/requesting_an_apple_pay_payment_session)

cert: merchIdentityCert 和 key: merchIdentityCert 都是一样的。我将我的 MerchantIdentityCertificate.pem 附加到证书和密钥。

但是,无法从 Apple Pay 服务器获得任何响应。在我的请求之后,它抛出一个错误并且 safari 显示一条消息“此资源来自本地覆盖”

代码

const merchIdentityCert = fs.readFileSync("./merchIdentityCert.pem")
const httpsAgent = new https.Agent({
  cert: merchIdentityCert,key: merchIdentityCert,maxVersion: "TLSv1.2",minVersion: "TLSv1.2"
})
const post = (url,body) => {
logger.info({ message: "apple pay START",url,body })
fetch(url,{
  body: JSON.stringify(body),method: "POST",agent: httpsAgent
}).then(resp => {
logger.info({ message: "apple pay SUCCESS",resp })
return resp
}).catch((error) => {
logger.info({ message: "apple pay ERROR",error })
return error
})
}

日志:

message: "apple pay START",url: “https://-pay-gateway-cert.apple.com/paymentservices/startSession”,正文:{"merchantIdentifier":"..","displayName":"测试 Pay","initiative":"web","initiativeContext":"--**.***."}

消息:“apple pay ERROR”,错误:{}*

我正在使用节点获取库。我的 Web 应用程序和节点应用程序部署在 AWS 服务器中。我已经通过证书满足了服务器设置和环境设置要求。 [https://developer.apple.com/documentation/apple_pay_on_the_web/setting_up_your_server]

有人对此有什么想法吗?

解决方法

能够解决 {"size":0,"timeout":0} 问题,它与节点获取库有关。我从我的代码级别修复了它。 (Node-fetch problems with POST requests,https://www.npmjs.com/package/node-fetch)

除此之外,我使用以下请求使用远程服务器进行调试,并将会话对象提供给我。

curl -XPOST -H "Content-type: application/json" -d '{"merchantIdentifier":"merchant.***.xxxxx","displayName":"TestPay","initiative":"web","initiativeContext":"***-***-xxxxxx.xxxxxxxxxx.xx"}' --cert cert.pem:cert.pem 'https://apple-pay-gateway-cert.apple.com/paymentservices/startSession'

我的代码:

import fetch from "node-fetch"
import fs from "fs"
import { promiseReject } from "../utils/misc"
import { Logger } from "../services/Logger"
import https from "https"
const logger = new Logger("Apple Pay Client")
const checkStatusAndGetJSON = (fetchResponse) =>
    fetchResponse.ok
        ? fetchResponse.json()
        : fetchResponse.json().then(promiseReject)
const merchIdentityCert = fs.readFileSync("./merchIdentityCert.pem")
const httpsAgent = new https.Agent({
    cert: merchIdentityCert,key: merchIdentityCert,maxVersion: "TLSv1.2",minVersion: "TLSv1.2"
})
const basicHeaders = {
    "Accept": "application/json","lang": "en","Content-Type": "application/json"
}
const post = (url,body) => {
    const start = Date.now()
    return fetch(url,{
        body: JSON.stringify(body),headers: basicHeaders,method: "POST",agent: httpsAgent
    }).then(resp => {
        const duration = Date.now() - start
        logger.debug(`apple pay call took ${duration} millis.`,{ endpoint: url,duration })
        return resp
    }).then(checkStatusAndGetJSON)
}
/** Apple Pay */
export const performValidation = (url,body) => post(url,body)
,

我的 merchIdentityCert 的私钥有问题,我修复了它。安装 .cer 文件后,从 Keychain Access 中展开它,将 2 个项目导出为 .p12 并使用 OpenSSL 将其转换为 .pem。现在,我有一个包含这两个资产的 PEM 文件。然后我继续我的过程,这次没有收到我在上面帖子中提到的以下错误。

消息:“apple pay ERROR”,错误:{}

但是,在请求之后,我得到了低于日志,

message: "apple pay SUCCESS",resp: {"size":0,"timeout":0}

同样,在 Inspect Element → Network →(点击我的请求)→ Preview

响应预览的顶部,它显示一条消息“揭示 |此资源来自本地覆盖”

有人有什么想法吗? 我从 Apple Pay 服务器获取 {"size":0,"timeout":0}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。