我们正在尝试在我的项目中通过网络实施ApplePay。根据苹果的文档,我从applejs api onvalidatemerchant函数获取验证网址,并且我将此验证网址传递给节点js路由以获取苹果付款会话。这是我要获得苹果付款会话(https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_js_api/requesting_an_apple_pay_payment_session)所遵循的文档。
以下是我为获得Apple付款会话而编写的自定义节点js代码。传递到此节点js路由代码的验证URL(即req.query.url)为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开发门户网站下载.cer格式的商户身份证书来生成证书,并通过在Mac的KeyChain访问中导入.cer文件并将其导出到.pem中,将从Apple门户网站下载的证书转换为.pem格式。钥匙串访问。然后,我将.pem文件('./apple_pay.pem')放在我的节点js路由的同一目录中。我如何生成证书或在我的节点js路由中传递证书有什么问题吗?
不确定在这里出了什么问题。任何代码示例或指针都将非常有用。
似乎是由于证书有效性相关问题。请确保自签名证书有效。
希望这会有所帮助。