Coder Social home page Coder Social logo

Comments (5)

qaoo8 avatar qaoo8 commented on May 20, 2024 1

@TheNorthMemory
更新代码,测试通过, 谢谢!
const { Wechatpay, Formatter, Transformer } = require("wechatpay-axios-plugin");

console.log("付款码沙箱用例:获取支付结果");
    console.log(
      (
        await wxpay.v2.sandboxnew.pay.orderquery(
          {
            appid,
            mch_id,
            nonce_str: Formatter.nonce(),
            out_trade_no,
          },
          { transformResponse: [Transformer.toObject] }
        )
      ).data
    );

from wechatpay-axios-plugin.

TheNorthMemory avatar TheNorthMemory commented on May 20, 2024

测试校验了一下,这个是官方沙箱环境的一个bug,他们在做返回值签名的时候,把金额0给漏了,即:

<cash_fee><![CDATA[0]]></cash_fee>

这个按照APIv2签名规范

  • 参数名ASCII码从小到大排序(字典序);
  • 如果参数的值为空不参与签名;
  • 参数名区分大小写;
  • 验证调用返回或微信主动通知签名时,传送的sign参数不参与签名,将生成的签名与该sign值作校验。

0分金额需要参与签名,而沙箱环境给把这个值给过滤掉算签名了,你可以按照如下方法复现:

  1. 在实例化完wxpay代码之后,加入一个中间件打印返回XML:
Wechatpay.client.v2.defaults.transformResponse.unshift(data => (console.log(data), data));
  1. 按照 #35 的方法,对返回值忽略验签,即:
  res = await wxpay.v2.sandboxnew.pay.orderquery({
    appid,
    mch_id,
    nonce_str: Formatter.nonce(),
    out_trade_no,
  }, {
      transformResponse: [Transformer.toObject],
  });
  console.info(res.data);
  1. 按照打印的 XML以及你的沙箱密钥,到官方验签工具上去校验,肯定不过(预期结果);

  2. 去掉XML中的<cash_fee><![CDATA[0]]></cash_fee>或者置空值,验签通过;

我用PHP也验证了一下,均是这个问题,确信这个是官方沙箱环境的一个BUG。

from wechatpay-axios-plugin.

qaoo8 avatar qaoo8 commented on May 20, 2024

@TheNorthMemory 您好!
关于 <cash_fee><![CDATA[0]]></cash_fee> 的问题,我认为在技术上是一个BUG,但在实际操作中,可能是微信支付的一个特别设置,为了避免付款金额为0元时显示为收款成功。

from wechatpay-axios-plugin.

TheNorthMemory avatar TheNorthMemory commented on May 20, 2024

@TheNorthMemory 您好!
关于 <cash_fee><![CDATA[0]]></cash_fee> 的问题,我认为在技术上是一个BUG,但在实际操作中,可能是微信支付的一个特别设置,为了避免付款金额为0元时显示为收款成功。

APIv2上,保证收单逻辑是正确的是return_coderesult_code,这俩值都是SUCCESS的时候,即表示业务逻辑(收单)成功;这个0元金额的,不应该是在数据签名出现错误(被忽略了),估摸着这仅是沙箱环境的问题,生产环境(未知)。

from wechatpay-axios-plugin.

qaoo8 avatar qaoo8 commented on May 20, 2024

@TheNorthMemory
0 元付款的生产环境返回参数(供参考):

 { 
     return_code: 'SUCCESS',
     result_code: 'FAIL',
     err_code: 'PARAM_ERROR',
     err_code_des: 'total_fee参数格式错误' 
 }

from wechatpay-axios-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.