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

Unable to get any response from the apple pay - This resource came from a local override

我正在整合 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
})
}

日志:

消息:“苹果支付开始”,url: "https://-pay-gateway-cert.apple.com/paymentservices/startSession", body: {"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]

有人对此有想法吗?

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

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

但是,请求后,我的日志低于日志,

消息:“苹果支付成功”,响应:{“大小”:0,“超时”:0}

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

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

有人有想法吗? 我从 Apple Pay 服务器收到 {"size":0,"timeout":0}

能够解决 {"size":0,"timeout":0} 问题,它与节点获取库有关。我从我的代码级别修复了它。 (, 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, method: "POST", duration })
        return resp
    }).then(checkStatusAndGetJSON)
}
/** Apple Pay */
export const performValidation = (url, body) => post(url, body)