-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
v2付款接口无法使用的问题 #35
Comments
这个接口我还真没仔细看,确实 |
已PR #36. 如无问题的话可以merge。 |
- fix #35, `v2.mmpaymkttransfers.promotion.transfers.post` not works well issue.
v0.7.10 已发布。 |
…n#35 It used to get the merchant id only from data.mch_id, which is not suitable for some API like https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2 . After the modification, the merchant id can be passed through the SDK client by the xml[mch_id] or xml[mchid] data.
另外,给将来可能会使用这个接口的朋友们提个醒:
如果要解决此问题,可能只能是写一个特判的逻辑、根据请求的路径决定这个接口需不需要验签之类的办法......但这样我觉得太麻烦也太奇怪了。作者您如果愿意的话可以考虑解决一下,但不解决我觉得也没啥问题、毕竟是这个接口本身太奇怪了,所以我就先不开个Issue了,只是放在这给之后可能用到的朋友们提个醒。 我目前解决的方法是这样的: import {Transformer} from "wechatpay-axios-plugin"; // ts的写法,如果是js的话可以写成const Transformer = require("wechatpay-axios-plugin").Transformer
const reqObj = {
mch_appid: wxmpAppId,
mchid: wxpayMchid,
nonce_str: nanoid(32),
partner_trade_no: dbObj._id,
openid: user.openId,
check_name: "NO_CHECK",
amount: Math.round(amount * 100),
desc: description
}
const resp = await wxpay.v2.mmpaymkttransfers.promotion.transfers.post(reqObj, {
transformResponse: [Transformer.toObject]
}) // 覆盖掉默认的transformResponse配置 其原理是这样的: wechatpay-axios-plugin/lib/transformer.js Lines 98 to 103 in e387092
WechatPay对象里面的post等请求方法,默认配置的transformResponse是Transformer.toObject, Transformer.verifier两个,前一个是用来把xml转成js对象的,后一个是验签的。现在既然接口不返回签名,那就不验签,手动指定transformResponse为只留Transformer.toObject一个、不使用Transformer.verifier就行了。 |
v2上有几个接口,是比较嗝咛,返回值没 // 返回值无`sign`字段,无需数据校验
transformResponse: [Transformer.toObject], |
哦哦确实,我之前没看到那里。这么解决挺好的 |
v2 刷卡支付验收用例3 沙箱测试报错, 请帮忙看看如何解决,谢谢!用例说明: “用例3:【刷卡-正常】订单金额0.03元(含0.01元代金券和0.02元免充值现金券),用户支付成功 “
请求支付成功,获取支付结果时报错信息:
|
@qaoo8 稍等我来按你的方式本地校验一下 |
@TheNorthMemory 感谢! |
事情是这样的:微信的向用户付款到零钱的接口,目前没有v3、只有v2,文档在这里
![image](https://user-images.githubusercontent.com/46821571/129172950-8104d7c3-d717-4ac0-8c78-fb4433d59f7a.png)
令人吐血的是,这个接口的商户号字段名称是"mchid",而非绝大多数接口使用的"mch_id"。
因此我的代码如下:
这样的代码产生如下报错:
经过我分析,原因是:
wechatpay-axios-plugin/lib/transformer.js
Lines 34 to 38 in 4826863
这段代码是判断请求数据中的mch_id字段的值和创建WechatPay对象时配置的mchid是否一致,但偏偏有些接口的商户号字段不叫mch_id而叫mchid......(这波微信的锅很大)
我的建议是将上面第35行改为:
应该就可以解决这个问题。
不知道您觉得是否可以,如果可以的话,我可以发布pull request上来。
最后,对您长期以来编写和维护这样一个很好用的库,表示衷心的感谢!
The text was updated successfully, but these errors were encountered: