gpt4 book ai didi

node.js - 无法获取 Apple Pay 支付 session

转载 作者:太空宇宙 更新时间:2023-11-03 23:12:45 25 4
gpt4 key购买 nike

我们正在尝试在我的项目中在网络上实现 ApplePay。根据苹果文档,我从 applejs api onvalidatemerchant 函数获取验证 url,并将此验证 url 传递到 Node js 路由以获取苹果支付 session 。这是我为了获取苹果支付 session 而遵循的文档( https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_js_api/requesting_an_apple_pay_payment_session )。

下面是我编写的用于获取苹果支付 session 的自定义 Node js代码。传递给此 Node 的验证url(即)req.query.url js路由代码为 https://apple-pay-gateway-cert.apple.com/paymentservices/startSession .

app.get('/getAppleSession2', function (req, res) {


var endpointURL = req.query.url;
var cert_path = './apple_pay.pem';
var cert = fs.readFileSync(cert_path);
console.log('endpointURL is ' + endpointURL);
console.log('cert_path is ' + cert_path);
console.log('cert is'+cert);
const options = {
url: endpointURL,
method: 'post',
cert: cert,
key: cert,
body: {
merchantIdentifier: "xxxxx.xxxxx.xxxxx.xxxxx.xxxxx",
displayName: "xxxxx.xxxxx.xxxxx.xxxxx.xxxxx",
initiative: "web",
initiativeContext: "xxxxx.xxxx.xxxx.xxxx.com"
},
json: true,
};
//console.log("body" + body);
request(options, function (error, response, body) {
console.log('body of getAppleSession' + body);
console.log('Response from getAppleSession' + response);
console.error('Error object ' + error);

res.send(body);
});

});

但这就是我收到的这条路线的响应

body of  getAppleSession undefined
Response from getAppleSession undefined
Error object Error: error:0906D06C:PEM routines:PEM_read_bio:no start line

不确定这里出了什么问题,因为我正在按照苹果的文档执行此操作。我怀疑这是否与我将证书(商家身份证书)传递到此 Nodejs 路由的方式有关。我通过从 Apple Development 门户下载 .cer 格式的商家身份证书来生成证书,并通过在 Mac 的 KeyChain access 中导入 .cer 文件并将其导出到 .pem 来将从 Apple 门户下载的证书转换为 .pem 格式钥匙串(keychain)访问。然后,我将 .pem 文件('./apple_pay.pem')放置在我的 Node js 路由的同一目录中。我生成证书或在我的 Node js 路由中传递证书的方式有什么问题吗?

不知道这里出了什么问题。任何代码示例或指针都会非常有帮助。

最佳答案

这似乎是由于证书有效性相关问题造成的。请您确认一下自签名证书是否有效。

希望这可能有所帮助。

关于node.js - 无法获取 Apple Pay 支付 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59492153/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com