0
4

2 回答 2

0

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

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

但是,在请求之后,我得到以下日志,

消息:“apple pay SUCCESS”,响应:{“size”:0,“timeout”:0}

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

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

有人有想法吗? 我从苹果支付服务器获得 {"size":0,"timeout":0}

于 2021-05-11T12:55:30.657 回答
0

能够解决 {"size":0,"timeout":0} 问题,它与节点获取库有关。我从我的代码级别修复了它。(POST请求的节点获取问题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)
于 2021-05-18T03:16:32.083 回答