无法从 Apple Pay 获得任何响应 - 此资源来自本地覆盖
Posted
技术标签:
【中文标题】无法从 Apple Pay 获得任何响应 - 此资源来自本地覆盖【英文标题】:Unable to get any response from the apple pay - This resource came from a local override 【发布时间】:2021-07-31 20:58:51 【问题描述】:我正在集成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 都是一样的。我将我的 MercerIdentityCertificate.pem 附加到证书和密钥。
但是,无法从苹果支付服务器获得任何响应。在我的请求之后,它抛出一个错误,并且 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
)
日志:
消息:“Apple Pay 开始”,网址: "https://-pay-gateway-cert.apple.com/paymentservices/startSession",正文:"merchantIdentifier":"..","displayName":"测试 支付","initiative":"web","initiativeContext":"--**.***."
消息:“apple pay ERROR”,错误:*
我正在使用节点获取库。我的 Web 应用程序和节点应用程序部署在 AWS 服务器中。我已通过证书满足服务器设置和环境设置要求。 [https://developer.apple.com/documentation/apple_pay_on_the_web/setting_up_your_server]
有人知道吗?
【问题讨论】:
【参考方案1】:我的 merchIdentityCert 的私钥存在问题,我已修复。安装 .cer 文件后,从 Keychain Access 中展开,将 2 项导出为 .p12 并使用 OpenSSL 将其转换为 .pem。现在,我有一个包含这两种资产的 PEM 文件。然后我继续我的过程,这次没有收到我在上面帖子中提到的以下错误。
消息:“apple pay ERROR”,错误:
但是,在请求之后,我得到以下日志,
消息:“apple pay SUCCESS”,响应:"size":0,"timeout":0
同样,在 Inspect Element → Network → (点击我的请求) → Preview
响应预览的顶部,它显示一条消息为“Reveal |此资源来自本地覆盖”
有人有想法吗? 我从苹果支付服务器获得 "size":0,"timeout":0
【讨论】:
【参考方案2】:能够解决 "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, method: "POST", duration )
return resp
).then(checkStatusAndGetJSON)
/** Apple Pay */
export const performValidation = (url, body) => post(url, body)
【讨论】:
更多详情:[链接] (developer.apple.com/forums/thread/…)以上是关于无法从 Apple Pay 获得任何响应 - 此资源来自本地覆盖的主要内容,如果未能解决你的问题,请参考以下文章