klover2 / wechatpay-node-v3-ts Goto Github PK
View Code? Open in Web Editor NEW微信支付v3
License: MIT License
微信支付v3
License: MIT License
如下是代码:
const params = {
apiSecret: think.config('weixin.partner_key'), // API V3 密钥
body: body, // 请求体 body
signature: headers['wechatpay-signature'],
serial: headers['wechatpay-serial'],
nonce: headers['wechatpay-nonce'],
timestamp: headers['wechatpay-timestamp'],
};
const ret = await pay.verifySign(params); // 报错位置
如下是params参数:
{
apiSecret: "68d1df7c3ee038838d5fd349*******",
body: {
id: "34f3011d-efb1-5f7d-9658-ec5660d1be2e",
create_time: "2023-08-20T12:52:42+08:00",
resource_type: "encrypt-resource",
event_type: "TRANSACTION.SUCCESS",
summary: "支付成功",
resource: {
original_type: "transaction",
algorithm: "AEAD_AES_256_GCM",
ciphertext: "6vc434Am1l1iE6V1KtX+3pA1sc0HOqHQ3mHiCDl+7Vc1YVuRlYTLG9VJDYnYlEHEzoN00LT+NbRkuSuv29JoOLD3bKZVMjeqAGsXF5sS2cgJ+NDDwCM80PUrN/Im5XL9MhQ/Dt+rU54eeYiUKZuAsqoAOAxTVm6SNsdi3T21h+j8z3hK2UKd8XaMYplYg5FC4MC+WWFzkV3KMBAERWHTmgqEQ2w1nCuDpNV+W41oGNeufgFrANq/tC5zVkMOG/bAp4rLRq0tjf7/sI5rktgxgkzTxG3yMDKrJQBIOhMNBdnnfCO/aS/dE21i6Clf2dT/OyMfyVGRQLytFW5NxfSy7SNafkpo452qNX1mKfjYK0YH1rny+i0vkVV18+M5dnUvy+imu84cMOglFqSGL6Ir3hgfeTZIhOZB/iiGSxiqsYD1+XFRmL+IG37fH3Yu2hDCstZZKhX/llblzOXkiT7LdW1Da9CeyHlol5FNlrAHbREvUJqW9M34yMXjVe1xKgHRM5OLoHQDSuL6LM6YK3Oa5HJW2UHE4dabkezEwP6qvxsY50rezifob+zRSY4NhNpRR7Ek",
associated_data: "transaction",
nonce: "LFp4az9gqZqp",
},
},
signature: "gMkazVj9WWgvidlUkZz1d+HsRT8MLd5BKL0NlVwQhXln7kqblXrc7f+d0YDsYOwiggnPVoyyKnLhuUQgIHkz4r5BZEH+iAVwqB6X7pRsSHZ/zw+f+ViOwyrwkBxoY9er+eC8qxpQJkOvZebU2ZQiWDqik/U46igH0734JW75EAAfReRNRJbKqP6DPTzeHJ8sR7vhk/G48x2vqxz1fYfbU0pk+gROMBC+GsZJEfi8RmQeCfKyeiT+2bjvpBThUdmIi0ZSfagewbvaHf4F4n2BYMz4F6QVYJZFiBntiIB5YLkjkmhwrUfvz+tjoWifobUyY0DMI9ZB6iFRvWphPrfThw==",
serial: "3CB63C0CE605B7F1C32E85AA38465666C33C8FB0",
nonce: "KtbgY7BsQDFNzmFu2aqfdw5uJpvXjeoS",
timestamp: "1692507162",
}
import WxPay from 'wechatpay-node-v3'
fails and show error like this wechatpay_node_v3_1.default is not a constructor
.
Currently I fix this problem by editing the node module with following codes:
// in index.d.js
export = Pay;
export default Pay; // add this
// in index.js
module.exports = Pay;
module.exports.default = Pay; // add this
能不能加个现金红包的v2功能啊。不知道怎么整。或者v3的怎么改成v2的呢?
错误描述:Error: Unsupported state or unable to authenticate data
2022-04-15 09:51:29,428 ERROR 4860 [-/::ffff:127.0.0.1/-/242ms POST /api/orderCallback] Error: Unsupported state or unable to authenticate data
at Decipheriv.final (internal/crypto/cipher.js:174:29)
at Pay.decipher_gcm (D:\haocuan\midway_mon\node_modules\wechatpay-node-v3\dist\index.js:396:14)
at D:\haocuan\midway_mon\node_modules\wechatpay-node-v3\dist\index.js:208:50
at Array.forEach ()
at Pay. (D:\haocuan\midway_mon\node_modules\wechatpay-node-v3\dist\index.js:207:20)
at step (D:\haocuan\midway_mon\node_modules\wechatpay-node-v3\dist\index.js:139:21)
at Object.next (D:\haocuan\midway_mon\node_modules\wechatpay-node-v3\dist\index.js:76:16)
at fulfilled (D:\haocuan\midway_mon\node_modules\wechatpay-node-v3\dist\index.js:30:26)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
好像是解析不了数据,请教下如何处理这种问题
除了微信支付”接口规则“(https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay-1.shtml),
中需要API调用端进行签名(本repo实现的内容),微信支付其他API也有需要(不同规则的)签名的,
比如:
https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_5_4.shtml
希望repo也能实现它们,方便开发者。
https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter5_1_4.shtml
微信支付支持合单支付,很有用的场景。
{
status: 'PROCESSING',
amount: {
...
},
channel: 'ORIGINAL',
...
}
官方文档中小程序和jsapi提交时候的appid参数分别为 appid和appId,是这个导致的问题吗?
你好,我在使用的时候,发现签名失败,请问这个是什么问题呢?
const signature = pay.getSignature('POST', nonce_str, timestamp, '/v3/pay/transactions/jsapi', params)
出现报错:
Error: error:0909006C:PEM routines:get_name:no start line
我是证书是使用WXCert生成的
修改index.ts后已修复,准备提交pr
Error: Unsupported state or unable to authenticate data
at Decipheriv.final (node:internal/crypto/cipher:193:29)
at Pay2.Pay2.decipher_gcm (/home9/chatgpt-web/chatgpt-web/service/node_modules/wechatpay-node-v3/dist/index.js:332:18)
这是什么原因吗?解密方式不对吗?如下是信息:
{
description: '计算机电脑',
out_trade_no: '79568867678022209',
notify_url: 'https://gpt89.shiliucrm.com/pay/notify',
amount: { total: 1 },
scene_info: { payer_client_ip: '::ffff:127.0.0.1' }
}
{ status: 200, code_url: 'weixin://wxpay/bizpayurl?pr=IGZN4mtzz' }
接收信息2: F3FNBOLGTtrK02e+CTqwnWcJycCh6jy9C4+SK/mLcuz1iDS3M1y4OSI6kSMU2sombf5Kh8z4qTRfUdMXh35I7e15jH1ys7NZzKBmvCOS88pWIz1YsRhuSxefqgwiS89KGh3MjZfbB/NU5SgVyiQ5tezTJFito2GG9/UwttqahC4jWwvuR9P4NPpJYIebFsiudOKA1inKLZXIxhs5CEkbxxgnpAz5aPbDxj8I8JtKLaSNO5H0ZZ4DhwS9l8OfIo9VBGTRyEn5BZwbFtEc94chJZrZw+2JtnHuGdYM0kigtkzcB4goze3BDXFTGpgo7rLc/YfoaiYRZrExrJ6FkbuecTFlI+NjRxMnBKyu1JJnHb1517zPOHqPa3kJ3Q2Xe+fUtgw5zig+iFft+BxVgrCv/9TAIopfk8FNn1+swGhfyGjkFJaCKUV1u2+9UheP3kXFOIdK0cePP0GBIsFNyj6m2220BavBGF1U6+FMjjQvU8uK0e2sizBJSqMx11ghaZXnWtm0wzeZZJ4ctL1JEPh8BCWheCoO1ijHhYyJMY/5TGAiGeJf4lV/H6NYBOeyFyhf7w==
接收信息22: Ui0GBRYeMZ6Y
接收信息23: transaction
解密出错: Error: Unsupported state or unable to authenticate data
求大佬帮忙看看,已经测试过好多回了
2023-01-14 10:35:55,877 ERROR 479036 [-/140.207.54.79/-/1ms POST /wx-notify] nodejs.Error: Unsupported state or unable to authenticate data
at Decipheriv.final (node:internal/crypto/cipher:193:29)
at Pay.decipher_gcm (/www/wwwroot/text-to-speech.com/node_modules/.pnpm/[email protected]/node_modules/wechatpay-node-v3/dist/index.js:332:18)
at WxController.notify (/www/wwwroot/text-to-speech.com/app/controller/wx.js:51:24)
at Object.callFn (/www/wwwroot/text-to-speech.com/node_modules/.pnpm/[email protected]/node_modules/egg-core/lib/utils/index.js:44:21)
at Object.classControllerMiddleware (/www/wwwroot/text-to-speech.com/node_modules/.pnpm/[email protected]/node_modules/egg-core/lib/loader/mixin/controller.js:87:20)
at Object.callFn (/www/wwwroot/text-to-speech.com/node_modules/.pnpm/@[email protected]/node_modules/@eggjs/router/lib/utils.js:12:21)
at wrappedController (/www/wwwroot/text-to-speech.com/node_modules/.pnpm/@[email protected]/node_modules/@eggjs/router/lib/egg_router.js:322:18)
at dispatch (/www/wwwroot/text-to-speech.com/node_modules/.pnpm/[email protected]/node_modules/koa-compose/index.js:44:32)
at next (/www/wwwroot/text-to-speech.com/node_modules/.pnpm/[email protected]/node_modules/koa-compose/index.js:45:18)
at /www/wwwroot/text-to-speech.com/node_modules/.pnpm/@[email protected]/node_modules/@eggjs/router/lib/router.js:186:18
微信请求的参数
{
'content-length': '915',
connection: 'Keep-Alive',
'user-agent': 'Mozilla/4.0',
accept: '*/*',
host: '124.71.58.207',
'wechatpay-nonce': '4WiViQ2LN9P3oniM5oKUDCk1E601oWco',
'content-type': 'application/json',
'wechatpay-serial': '476A463785C200B7A7D13CB6A521663B91EECB53',
'wechatpay-signature': 'QYVsHeRe5gOxntBAUyZaCvtF4Exc2T/JkhGMNwBgbopejYPSGpH5+lGoRpwoSF0R+9Q5IR0jZUoLIg3nR91Koot7sIE6WzdaeRVXP0NTFVgPVUZmbH7E1q3NqJU0nNSD45+wXVZfbThZrfw5eVYFUeVicukXqcTtZpXiY/Efu76fgl+ePVkAYM+F/nqGPA/Tk8NG0KAIKBoZylr+OVh6wlwECpfRv0IAxRfvvv+7o6S0ebxbGDd2C2XXnoNooP/ZHarM0wI+F5XGOWXPD7Baj/KuzcuPC3d5I+VRLhnk1fm/XRskNucIQZW/X30P4LBCPhheSHPksHm2UpJZe7AP4Q==',
'wechatpay-signature-type': 'WECHATPAY2-SHA256-RSA2048',
pragma: 'no-cache',
'wechatpay-timestamp': '1673663801'
}
/Users/soulmac/code/node/Nest/src/app.controller.ts:11
const pay = new Pay(
^
TypeError: wechatpay_node_v3_1.default is not a constructor
用在nestjs里时一使用就报这个错误,请问有人能解答一下吗
{"status":400,"error":{"code":"PARAM_ERROR","message":"HTTP header缺少微信支付平台证书序列号(Wechatpay-Serial)"}}
参考样例代码格式 报错。
大佬好,
使用敏感信息加密,出现平台证书序列号Wechatpay-Serial错误,按照#31的方法增加key没有用,我看到2.0.2增加敏感信息加密方法后,
'serial_no="' +
this.serial_no +
'",' +
替换了
'Wechatpay-Serial="' +
this.serial_no +
'",' +
https://pay.weixin.qq.com/wiki/doc/apiv3_partner/wechatpay/wechatpay7_2.shtml
这个错误出现在上送参数需要敏感信息加密的接口中。请参考申明加密使用的平台证书
当证书序列号错误或者不是请求商户号对应的平台证书时,微信支付会返回问题中的错误提示。请检查:
加密使用的证书是否是微信支付平台证书。有时会误用商户证书导致该错误。
是否是请求商户对应的微信支付平台证书,如用了其他商户号的平台证书。
证书是否过期。请按照指引检查证书是否过期,并更新并部署新证书。
请问是不是要把Wechatpay-Serial加回去?
pay.batches_transfer这个方法会报平台证书序列号Wechatpay-Serial错误
去平台下载的证书如何在调用时携带呢
我看到退款接口没有实现,我效仿下单接口实现可以吗?
/root/wechat/wechat-server/node_modules/wechatpay-node-v3/dist/index.js:323
throw new Error('缺少key');
^
Error: 缺少key
at Pay.decipher_gcm (/root/wechat/wechat-server/node_modules/wechatpay-node-v3/dist/index.js:323:19)
at /root/wechat/wechat-server/node_modules/wechatpay-node-v3/dist/index.js:162:64
at Array.forEach ()
at Pay. (/root/wechat/wechat-server/node_modules/wechatpay-node-v3/dist/index.js:161:34)
at step (/root/wechat/wechat-server/node_modules/wechatpay-node-v3/dist/index.js:59:23)
at Object.next (/root/wechat/wechat-server/node_modules/wechatpay-node-v3/dist/index.js:40:53)
at fulfilled (/root/wechat/wechat-server/node_modules/wechatpay-node-v3/dist/index.js:31:58)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
const pay = new WxPay({
appid: WX_APPID,
mchid: WX_MCHID,
publicKey: fs.readFileSync(API_CLIENT_CERT_PEM), // 公钥
privateKey: fs.readFileSync(API_CLIENT_KEY_PEM), // 秘钥
});
`
TypeError: wechatpay_node_v3_1.default is not a constructor
报错如下:RangeError: Invalid key length
多次确认了apiv3key,associatedData,ciphertext,nonce都没有问题,解密回调的时候报错Invalid key length
非常好的库,希望能够添加支付以后签名验证的功能。这也是支付过程中官方文档中推荐的必要流程。
具体流程请见:
https://wechatpay-api.gitbook.io/wechatpay-api-v3/qian-ming-zhi-nan-1/qian-ming-yan-zheng
const params = {
apiSecret: apiV3Key,
body: bodys,
signature: headers["wechatpay-signature"],
serial: headers["wechatpay-serial"],
nonce: headers["wechatpay-nonce"],
timestamp: headers["wechatpay-timestamp"],
};
const ret = await pay.verifySign(params);
验签返回false
调用pay.decipher_gcm解密接口数据都返回正确
能否支持unicloud使用,unicloud阿里云时需要固定出口ip,否则会出现此ip不支持调用此接口
现在只能调用写好的方法,请问能否加上分账接口?
另外,是否可以在ts提示中开放内部的方法,便于拓展新接口。
TypeError: Cannot read properties of undefined (reading 'text')
at Pay.<anonymous> (/root/node_modules/wechatpay-node-v3/dist/lib/base.js:105:94)
at step (/root/node_modules/wechatpay-node-v3/dist/lib/base.js:44:23)
at Object.throw (/root/node_modules/wechatpay-node-v3/dist/lib/base.js:25:53)
at rejected (/root/node_modules/wechatpay-node-v3/dist/lib/base.js:17:65)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
有可能是 err.response
空值的问题:
微信提现到零钱,使用pay.batches_transfer可正常支付,但是使用
// 商家批次单号查询批次单API
const res = await pay.query_batches_transfer_list()
// 商家明细单号查询明细单API
const res = await pay.query_batches_transfer_detail()
都会提示错误的签名,验签失败?
老兄,这是开源吗?怎么看不到源码
微信退款报错,业务正常进行,方法报错,据分析是接口请求成功但解析响应报错
报错信息如下
Error: incorrect header check
at Zlib.zlibOnError [as onerror] (node:zlib:190:17)
at Zlib.callbackTrampoline (node:internal/async_hooks:130:17) {
errno: -3,
code: 'Z_DATA_ERROR',
response: null
}
商家转账到零钱增加了场景参数transfer_scene_id,该批次转账使用的转账场景,
可在「商家转账到零钱 - 产品设置」中查看详情,如不填写则使用商家的默认转账场景
如:1001 - 现金营销
示例值:1001
默认值不能超过200,也无法提额,只能通过改变场景来提额。请大佬有空的时候添加一下这个参数,感谢!!!
您好,是否可以添加企业付款到个人零钱账户的api,这个用的也挺多的
wechatpay-node-v3-ts/package.json
Line 14 in af51852
superagent v6 已经被标记为 deprecated
回调解密 (支付成功通知 退款通知)的入参请详细说明一下,各个参数代表什么意思,如何获取,请详细说明下 ,小白不太懂,谢谢!
微信支付商户号支持绑定多个 appid ,但是现在 sdk 只能在 constructor 中设置一个固定的 appid 。
如果需要支持多个 appid 就需要创建多个实例,然后根据 appid 动态选择对应实例来操作,不是很方便。
可以考虑将 constructor 中的值作为默认值,然后在各个方法中支持传入 appid 参数来覆盖默认值。
调试了native支付,还有查询关闭的接口,都调试通了,但调试分账接口时候,报错:
{"code":"PARAM_ERROR","message":"请确认待处理的消息是否为加密后的密文"}
是目前不支持分账吗?还是什么问题?
2021-07-07 微信h5支付突然异常,代码没动过, 发起h5支付 调用 transactions_h5出现Cannot read property 'text' of null,({code:Z_DATA_ERROR,errno:-3,response:null}})
已参考以下链接暂时解决
#8
vercel edge环境里报错,有循环引入
APP支付的时候 签名参数应该是下面几个
应用id
时间戳
随机字符串
预支付交易会话ID
现在代码里面写的是package=sign=wxpay,文档上应该是预支付交易会话ID
有支持v3服务订单的相关的封装嘛,主要是支付分这一块的
请问一下,回调解密参数怎么来的呢 ---------已经在微信支付文档找到了,感谢
调用refunds退款接口的时候报错:
TypeError: Cannot read property 'text' of null
at Pay. (/Users/zhangzhen/baomu/baomu_frontBack/node_modules/wechatpay-node-v3/dist/index.js:226:98)
at step (/Users/zhangzhen/baomu/baomu_frontBack/node_modules/wechatpay-node-v3/dist/index.js:44:23)
at Object.throw (/Users/zhangzhen/baomu/baomu_frontBack/node_modules/wechatpay-node-v3/dist/index.js:25:53)
at rejected (/Users/zhangzhen/baomu/baomu_frontBack/node_modules/wechatpay-node-v3/dist/index.js:17:65)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
调用参数:
{"transaction_id":"420xxxxxxx877351","out_refund_no":"BJY1Exxxxxxxxxx47949","notify_url":"https://www.baidu.com/xxxxxxx/xxxxxxx","amount":{"refund":20,"total":20,"currency":"CNY"}}
这个错误好像是偶发的,不知道什么原因
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.