tvrcgo / weixin-pay Goto Github PK
View Code? Open in Web Editor NEW微信支付 Nodejs SDK
License: MIT License
微信支付 Nodejs SDK
License: MIT License
在createUnifiedOrder方法中,callback返回err:
Error: mac verify failure
at Error (native)
at Object.createSecureContext (_tls_common.js:135:17)
at Object.exports.connect (_tls_wrap.js:997:48)
at Agent.createConnection (https.js:82:22)
at Agent.createSocket (http_agent.js:182:26)
at Agent.addRequest (http_agent.js:144:10)
at new ClientRequest (http_client.js:158:16)
at Object.exports.request (http.js:31:10)
at Object.exports.request (https.js:199:15)
at Request.start (/node/**/node_modules/request/request.js:740:32)
at Request.write (/node/**/node_modules/request/request.js:1380:10)
at end (/node/***/node_modules/request/request.js:552:18)
at Immediate.onImmediate (/node/**/node_modules/request/request.js:581:7)
at tryOnImmediate (timers.js:543:15)
at processImmediate as _immediateCallback
MD5模块用大写在linux里面有问题。
使用wxpay.getBrandWCPayRequestParams时有时会出现
TypeError: Cannot read property 'nonce_str' of undefined
at C:\node_modules\weixin-pay\lib\wxpay.js:87:18
at Parser. (C:\node_modules\weixin-pay\node_modules\xml2js\lib\xml2js.js:488:18)
at emitOne (events.js:77:13)
at Parser.emit (events.js:169:7)
at Parser.exports.Parser.Parser.parseString (C:\node_modules\weixin-pay\node_modules\xml2js\lib\xml2js.js:507:16)
at Parser.parseString (C:\node_modules\weixin-pay\node_modules\xml2js\lib\xml2js.js:7:59)
at Object.exports.parseXML (C:\node_modules\weixin-pay\lib\util.js:11:9)
at Request._callback (C:\node_modules\weixin-pay\lib\wxpay.js:75:8)
at self.callback (C:\node_modules\weixin-pay\node_modules\request\request.js:200:22)
at emitOne (events.js:77:13)
已传了total_fee,但是还是返回缺失该参数。
Msg: "requestPayment:fail"err_code: "2"err_desc: "调用支付JSAPI缺少参数: total_fee"
request({
url: "https://api.mch.weixin.qq.com/pay/unifiedorder",
method: 'POST',
body: util.buildXML(opts),
agentOptions: {
pfx: this.options.pfx,
passphrase: this.options.mch_id
}
}, function(err, response, body){
console.log(err);
util.parseXML(body, fn);
});
求解
1.可否增加企业付款到零钱接口?
2.可否增加支付/退款等通知结果的解密接口?
可否增加企业支付
WXPay.mix('getBrandWCPayRequestParams', function(order, fn){
order.trade_type = "JSAPI";
var _this = this;
this.createUnifiedOrder(order, function(err, data){
//TODO: check data['return_code'] and data['return_msg'] response here, otherwise client will get a callback data with like {..., nonceStr: undefined, package: "prepay_id=undefined"... } without any further debug infomation.
var reqparam = {
appId: _this.options.appid,
timeStamp: Math.floor(Date.now()/1000)+"",
nonceStr: data.nonce_str,
package: "prepay_id="+data.prepay_id,
signType: "MD5"
};
reqparam.paySign = _this.sign(reqparam);
fn(err, reqparam);
});
});
getBrandWCPayRequestParams 把trade_type写死为JSAPI,可app支付的话其实也差不多
是否应该增加个APP支付的方法以及对应的文档?
app.use(bodyParser.text({type: 'text/xml'}));
我看到有人提交了企业付款的代码,可是测试失败了。
#9
是因为echo "Error: no test specified" && exit 1,可以解决,加上这个特性吗
没有提供验证签名的接口
底层没有进行签名验证,太不安全。交由用户自己做,使用性不好
目前调用微信的接口都是直接写死的地址,能否支持一下沙箱环境?
微信的支付接口升级必须要用沙箱环境测试才可通过
https://mp.weixin.qq.com/wiki?t=resource/res_main&id=21515658940X5pIn
比如查询地址要改成:
(https://api.mch.weixin.qq.com/sandboxnew/pay/orderquery)
所以我建议用一个变量统一,比如
let host = 'https://api.mch.weixin.qq.com'
let sandboxName = '/sandboxnew'
...
url = host + sandboxName + '/orderquery'
大佬, 微信支付新增了商家转账到零钱的接口,而且必须使用这个接口,能否麻烦升级支持下?
https://pay.weixin.qq.com/docs/merchant/products/batch-transfer-to-balance/introduction.html
koa 使用router.use('/wxpay/native/callback', wxpay.useWXCallback(function(msg, req, res, next){...
使用这个方法报错:如下
node_modules/weixin-pay/lib/util.js:32:9)
该如何解决呢?
TypeError: stream.on is not a function
@tvrcgo
调用统一下单时 err返回值为这个
你好,想请问一下支付结果异步回调的中间件是否有做验签。
谢谢!
我的代码是这样:
wxpay.createUnifiedOrder(orderInfo, (err,rst)=>{
console.log(err);
console.log(rst);
});
然后输出错误:
TypeError: Cannot read property 'toString' of undefined
at Parser.exports.Parser.Parser.parseString (/Users/cos800/projxxx/node_modules/xml2js/lib/xml2js.js:497:18)
at Parser.parseString (/Users/cos800/projxxx/node_modules/xml2js/lib/xml2js.js:7:59)
at Object.exports.parseXML (/Users/cos800/projxxx/node_modules/weixin-pay/lib/util.js:11:9)
at Request._callback (/Users/cos800/projxxx/node_modules/weixin-pay/lib/wxpay.js:75:8)
at self.callback (/Users/cos800/projxxx/node_modules/request/request.js:188:22)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at Request.start (/Users/cos800/projxxx/node_modules/request/request.js:757:10)
at Request.write (/Users/cos800/projxxx/node_modules/request/request.js:1511:10)
at end (/Users/cos800/projxxx/node_modules/request/request.js:552:18)
at Immediate.<anonymous> (/Users/cos800/projxxx/node_modules/request/request.js:581:7)
at runCallback (timers.js:570:20)
at tryOnImmediate (timers.js:550:5)
at processImmediate [as _immediateCallback] (timers.js:529:5)
undefined
想要达到的效果:
想在后端拿到用于前端调起微信内支付(公众号支付)的相关参数
目前的效果:
取回的信息为中不正确,包含undefined,没有相关错误提示
使用接口的代码为:
router.get('/wexin/jsapi/:data', async function(req,res,next) {
try {
//我先在这里通过一些操作取到openid
const data = JSON.parse(req.params.data);
wxpay.getBrandWCPayRequestParams({
openid: openid,
body: '公众号支付测试',
detail: '公众号支付测试',
out_trade_no: data.orderId,
total_fee: data.total_fee,
spbill_create_ip: '192.168.2.210',
notify_url: 'https://47.75.40.253/wechat/callback',
}, function(err, result){
console.log(result);
});
} catch (e) {
console.log(e);
}
})
得到的结果:
{ appId: 'wxbbbe3315cf3d4d71',
timeStamp: '1531245546',
nonceStr: undefined,
package: 'prepay_id=undefined',
signType: 'MD5',
paySign: 'D3FA8F7B5D32C50E9863CFF0D71809FA' }
其中nonceStr为undefined,prepay_id应该是未正确生成。
用的是 createUnifiedOrder 返回的sign,然后在ios中调用微信支付。微信提示支付验证签名失败。。。
请问大神有遇过这种情况么。。。。
这个demo的启动命令,能做个介绍么?
node_modules/weixin-pay/lib/wxpay.js:87
nonceStr: data.nonce_str,
Cannot read property 'nonce_str' of undefined
如题,感谢!
我这边遇到一个奇怪的问题
根据
var url = wxpay.createMerchantPrepayUrl({ product_id: '123456' }); 返回的二维码,用户也扫描了,同时
商户后台也收到微信的回调之后,并且也调用 createUnifiedOrder() 生成预支付交易单,返回如下内容
{ return_code: 'SUCCESS',
server-1 return_msg: 'OK',
server-1 appid: 'wxf5b3c80720abf32f1',
server-1 mch_id: '1367153302',
server-1 nonce_str: 'EVAtWsAxfdRCr7ld',
server-1 sign: '714448185388A8D61C9B80926F56C662
server-1 result_code: 'SUCCESS',
server-1 prepay_id: 'wx201607231446087ccd9d044c02411844123',
server-1 trade_type: 'NATIVE',
server-1 code_url: 'weixin://wxpay/bizpayurl?pr=XL8favn' }
请问到这一步后,我是需要把这个json转换为xml后,返回给微信吗?如何返回呢?
支付定单返如如下结果:
{
"appId": "wx4909c6e97b8f1f9c",
"timeStamp": "1472203485",
"nonceStr": "8OIWcyYFglN5qYIj",
"package": "prepay_id=undefined",
"signType": "MD5",
"paySign": "7A11C65CBDFF98554AADC4059AAC70B6"
}.
微信接口有很多内容,但该包并没有返回,比如失败状态。
如果这些信息返回,就可以生产环境用了
我自己访问/wxpay/notify也会执行业务逻辑,此时msg=null,微信通知过来时,msg有订单信息。
那么问题来了,怎么判断通知是微信过来的,还是别人冒充微信发过来的?
// 支付结果异步通知
router.use('/wxpay/notify', wxpay.useWXCallback(function(msg, req, res, next){
// 处理商户业务逻辑
//这里的代码自己访问也会执行
// res.success() 向微信返回处理成功信息,res.fail()返回失败信息。
res.success();
}));
调用js支付时返回这样的参数:
nonceStr: undefined,
package: 'prepay_id=undefined',
求助!!!!!!
RT
相关的验证方法有吗?
试过多次,
wxpay.createUnifiedOrder({
body: '扫码支付测试',
out_trade_no: '20140703'+Math.random().toString().substr(2, 10),
total_fee: 1,
spbill_create_ip: '192.168.2.210',
notify_url: 'http://xxx.74.212.xxx:3000/order/notify', //发帖时隐藏下IP
trade_type: 'NATIVE',
product_id: pid,
openid:openid,
sign:sign,
nonce_str:nonce_str
}, function(err, result){
cb(err, result);
}
);
将结果变成XML, 然后通过res.send(xmlMessage);
始终没有收到任何来自微信的回调。理论上应该会call我的/order/notify的。 不知道为什么。。。卡在这里了
router.get('/notify', wxpay.useWXCallback(function(msg, req, res, next){
^
TypeError: Object function WXPay() {
if (!(this instanceof WXPay)) {
return new WXPay(arguments[0]);
};
this.options = arguments[0];
this.wxpayID = { appid:this.options.appid, mch_id:this.options.mch_id };
} has no method 'useWXCallback'
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.