You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Node.js Apple Pay部署至Railway时验证商户遇"unsupported"错误

解决部署到Railway.app后Apple Pay商户验证的TLS "unsupported"错误

可能原因及解决方案

1. 证书路径问题

本地相对路径在部署环境中可能失效,Railway的工作目录和本地不一致,导致无法正确读取证书文件。

  • 改用绝对路径读取证书:
    const path = require('path');
    // 替换原路径定义
    const certFilePath = path.resolve(__dirname, './merchent_certificate/Certificates.p12');
    

2. 证书文件未完整部署

确认Railway部署后的文件系统中,Certificates.p12是否存在且大小和本地一致。可以通过Railway控制台执行ls merchent_certificate/命令检查文件状态,若缺失需重新上传或调整.gitignore规则(避免证书被忽略)。

3. Node.js版本不兼容

本地和Railway使用的Node.js版本差异可能导致PKCS12证书处理逻辑不一致:

  • 检查Railway项目的Node版本配置(可在项目设置或package.json的engines字段指定),确保和本地开发环境版本一致。
  • 若使用较新Node版本(v18+),旧证书的加密算法可能被默认禁用,可在agent配置中指定兼容的安全协议:
    agentOptions: {
      pfx: cert,
      passphrase: '********',
      secureProtocol: 'TLSv1_2_method' // 强制使用TLS 1.2
    }
    

4. 废弃的request库问题

request库已停止维护,在现代Node环境中可能存在兼容性问题,建议替换为axios或node-fetch:

  • 示例(使用axios):
    const axios = require('axios');
    const https = require('https');
    const fs = require('fs');
    const path = require('path');
    
    async function validateMerchant() {
      let response = {};
      const certFilePath = path.resolve(__dirname, './merchent_certificate/Certificates.p12');
      const cert = fs.readFileSync(certFilePath);
    
      try {
        const httpsAgent = new https.Agent({
          pfx: cert,
          passphrase: '********',
          secureProtocol: 'TLSv1_2_method'
        });
    
        response = await axios.post(
          'https://apple-pay-gateway.apple.com/paymentservices/startSession',
          {
            merchantIdentifier: 'merchant.com.zeebuz.pay',
            displayName: 'Your Store Name',
            initiative: 'web',
            initiativeContext: 'dev-app.zeebuz.com',
          },
          { httpsAgent }
        );
      } catch (error) {
        console.error(error.response?.data || error.stack);
      }
      return response.data;
    }
    

5. 证书本身的兼容性问题

如果证书使用了过时的签名算法(如SHA-1),现代Node.js会拒绝加载:

  • 重新生成符合Apple Pay最新要求的PKCS12证书,确保使用SHA-256及以上的签名算法。

内容的提问来源于stack exchange,提问作者Nadav

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 21:45:17