Comments (5)
@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.
测试校验了一下,这个是官方沙箱环境的一个bug,他们在做返回值签名的时候,把金额0给漏了,即:
<cash_fee><![CDATA[0]]></cash_fee>
这个按照APIv2签名规范:
- 参数名ASCII码从小到大排序(字典序);
- 如果参数的值为空不参与签名;
- 参数名区分大小写;
- 验证调用返回或微信主动通知签名时,传送的sign参数不参与签名,将生成的签名与该sign值作校验。
0分金额需要参与签名,而沙箱环境给把这个值给过滤掉算签名了,你可以按照如下方法复现:
- 在实例化完
wxpay
代码之后,加入一个中间件打印返回XML:
Wechatpay.client.v2.defaults.transformResponse.unshift(data => (console.log(data), data));
- 按照 #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);
-
按照打印的 XML以及你的沙箱密钥,到官方验签工具上去校验,肯定不过(预期结果);
-
去掉
XML
中的<cash_fee><![CDATA[0]]></cash_fee>
或者置空值,验签通过;
我用PHP也验证了一下,均是这个问题,确信这个是官方沙箱环境的一个BUG。
from wechatpay-axios-plugin.
@TheNorthMemory 您好!
关于 <cash_fee><![CDATA[0]]></cash_fee>
的问题,我认为在技术上是一个BUG,但在实际操作中,可能是微信支付的一个特别设置,为了避免付款金额为0元时显示为收款成功。
from wechatpay-axios-plugin.
@TheNorthMemory 您好!
关于<cash_fee><![CDATA[0]]></cash_fee>
的问题,我认为在技术上是一个BUG,但在实际操作中,可能是微信支付的一个特别设置,为了避免付款金额为0元时显示为收款成功。
APIv2上,保证收单逻辑是正确的是return_code
及result_code
,这俩值都是SUCCESS
的时候,即表示业务逻辑(收单)成功;这个0元金额的,不应该是在数据签名出现错误(被忽略了),估摸着这仅是沙箱环境的问题,生产环境(未知)。
from wechatpay-axios-plugin.
@TheNorthMemory
0 元付款的生产环境返回参数(供参考):
{
return_code: 'SUCCESS',
result_code: 'FAIL',
err_code: 'PARAM_ERROR',
err_code_des: 'total_fee参数格式错误'
}
from wechatpay-axios-plugin.
Related Issues (20)
- Readme的示例代码有误 HOT 1
- 计划升级大版本至1.0版本 HOT 6
- v2付款接口无法使用的问题 HOT 9
- 初始化报错,求解答,谢谢 HOT 3
- 下单接口返回无法将 JSON 输入源映射到目标字段的错误 HOT 2
- jsapi下单成功回调在catch里面 HOT 2
- 有的机器验证返回签名报错 HOT 2
- 你好,微信支付平台证书, 这个的配置可以在描述一下么. HOT 3
- 想弄个证书自动获取发现源码大量的静态函数,静态字段,搞哭了 HOT 1
- 请问微信支付通知的签名验证和内容解密部分有代码样例吗? HOT 6
- 正则匹配有个问题,铁子 HOT 2
- 调用new Wechatapy 报AssertionError [ERR_ASSERTION]: Verify the response's data with:**** HOT 2
- 建议保留微信支付官方的错误码返回 HOT 1
- 多商户(实例)相关问题 HOT 2
- 根据商户订单号查询微信支付的订单的示例请求 HOT 6
- paySign跟JSSDK生成的签名是一样的? HOT 1
- v3的notify_url设置好了,wechatpay-axios-plugin有内置的verify和解密的方法吗? HOT 1
- 生成URL会转换成小写,导致潜在查询数据返回没有记录的情况产生 HOT 1
- 遇到个问题 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wechatpay-axios-plugin.