Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invalid-signature #25

Closed
Maples7 opened this issue Mar 11, 2019 · 4 comments
Closed

invalid-signature #25

Maples7 opened this issue Mar 11, 2019 · 4 comments

Comments

@Maples7
Copy link

Maples7 commented Mar 11, 2019

    this.alipaySdk = new AlipaySdk({
      appId: alipayConfig.appId,
      gateway: alipayConfig.gateway,
      privateKey: fs
        .readFileSync(path.join(__dirname, './app-private-key.pem'), 'ascii')
        .trim(),
      alipayPublicKey: fs
        .readFileSync(path.join(__dirname, './alipay-public-key.pem'), 'ascii')
        .trim(),
      charset: 'utf-8',
      signType: 'RSA2',
    });
    const formData = new AlipayFormData();
    formData.setMethod('get');
    formData.addField(
      'notifyUrl',
      new URL(
        path.join(this.configService.apiPrefix, 'transactions/alipay/notify'),
        this.configService.website,
      ).toString(),
    );
    formData.addField(
      'returnUrl',
      new URL('/alipay/result', this.configService.website).toString(),
    );
    formData.addField('bizContent', {
      outTradeNo: tradeNo,
      productCode: 'FAST_INSTANT_TRADE_PAY',
      totalAmount: totalFee,
      subject: this.subject,
      body: this.description,
    });

    try {
      const result = await this.alipaySdk.exec(
        'alipay.trade.page.pay',
        {},
        {
          formData,
          validateSign: true,
          log: console,
        },
      );
      if (_.isString(result)) {
        return result;
      } else {
        throw new Error(
          `[main] [${result.code}] ${result.msg} - [sub] [${result.sub_code} ${
            result.sub_msg
          }]`,
        );
      }
    } catch (err) {
      this.logger.error('Fail to create direct payment url of alipay', err);
      throw new ApiException(ERRORS.PROXY_ERROR, '创建阿里云支付链接失败');
    }

沙箱环境下:

生成的付款地址调用一直返回:

错误代码 invalid-signature 错误原因: 验签出错,建议检查签名字符串或签名私钥与应用公钥是否匹配,网关生成的验签字符串为:alipay_sdk=alipay-sdk-nodejs-3.0.4&app_id=2016092500596274&biz_content={"out_trade_no":"201900123Test","product_code":"FAST_INSTANT_TRADE_PAY","total_amount":"0.01","subject":"心知天气服务费","body":"心知天气为你提供准确、稳定、全面的天气数据服务。"}&charset=utf-8&method=alipay.trade.page.pay&notify_url=http://hansel-dev.seniverse.com/api/v1/transactions/alipay/notify&return_url=http://hansel-dev.seniverse.com/alipay/result&sign_type=RSA2&timestamp=2019-03-11 13:12:03&version=1.0

生成的调用地址:

https://openapi.alipaydev.com/gateway.do?method=alipay.trade.page.pay&app_id=2016092500596274&charset=utf-8&version=1.0&sign_type=RSA2&timestamp=2019-03-11%2013:12:03&notify_url=http://hansel-dev.seniverse.com/api/v1/transactions/alipay/notify&return_url=http://hansel-dev.seniverse.com/alipay/result&sign=psu3WygBOcDgkt95tTXfV7yo1oIOB6c9mgnXKqKioTbh77wkaZhSBRTeZBLCJU6V6bwyP8Hxh7V0Jblx8Wg8FYNlb29FIFVQ30edccHbrblBN0kVFa4QBDdhwKFLOoYxmKSVYK5J/hz5CfiMrkxD1T5uM1NFit0eX/5ZelX8hjr3xDmjy3JsyZvrn+TTLHIp3khI5ZMKSAmcWEclx81MJGGQajsE+zV8b1FZHDvWtKVOmCnBNUJE7QMLJUoGLqIWqasFsyLY02/URsQUV5pAH+Sx1oNNMdpPp7gfSpCQANBcKqNSJ/HX3+LlRXtovOp8w8DOeD2nETtPUpKdn5o0YQ==&alipay_sdk=alipay-sdk-nodejs-3.0.4&biz_content=%7B%22out_trade_no%22:%22201900123Test%22,%22product_code%22:%22FAST_INSTANT_TRADE_PAY%22,%22total_amount%22:%220.01%22,%22subject%22:%22%E5%BF%83%E7%9F%A5%E5%A4%A9%E6%B0%94%E6%9C%8D%E5%8A%A1%E8%B4%B9%22,%22body%22:%22%E5%BF%83%E7%9F%A5%E5%A4%A9%E6%B0%94%E4%B8%BA%E4%BD%A0%E6%8F%90%E4%BE%9B%E5%87%86%E7%A1%AE%E3%80%81%E7%A8%B3%E5%AE%9A%E3%80%81%E5%85%A8%E9%9D%A2%E7%9A%84%E5%A4%A9%E6%B0%94%E6%95%B0%E6%8D%AE%E6%9C%8D%E5%8A%A1%E3%80%82%22%7D

但是用验签工具确定公钥私钥是匹配的,Help! 🤕

@Maples7
Copy link
Author

Maples7 commented Mar 11, 2019

Fixed:Chrome 自动转义,生成的 URL 是没问题的。

@Maples7 Maples7 closed this as completed Mar 11, 2019
@Maples7
Copy link
Author

Maples7 commented Mar 11, 2019

证实跟 VSCode 的行为有关:microsoft/vscode#70197

@fatetop
Copy link

fatetop commented May 21, 2019

验签出错后 怎么验签成功的 help 同样的问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants