1
This commit is contained in:
35
tool/node-wxpay/utils/refund_middleware.js
Normal file
35
tool/node-wxpay/utils/refund_middleware.js
Normal file
@@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
const xml2js = require('xml2js');
|
||||
|
||||
module.exports = () => {
|
||||
return async (ctx, next) => {
|
||||
let paramsJson = null;
|
||||
let contentType = ctx.headers['content-type'] || 'application/json';
|
||||
if (contentType.indexOf('xml') !== -1) { // xml格式参数获取
|
||||
let data = '';
|
||||
ctx.req.setEncoding('utf8');
|
||||
ctx.req.on('data', function(chunk) {
|
||||
data += chunk;
|
||||
});
|
||||
|
||||
const getxml = await new Promise(function(resolve) {
|
||||
ctx.req.on('end', function() {
|
||||
resolve(data);
|
||||
});
|
||||
});
|
||||
const parseObj = await new Promise(function(resolve) {
|
||||
xml2js.parseString(getxml, {
|
||||
'explicitArray': false,
|
||||
}, function(err, json) {
|
||||
if (err) throw err;
|
||||
return resolve(json);
|
||||
});
|
||||
});
|
||||
if (parseObj.xml) delete parseObj.xml._;
|
||||
paramsJson = parseObj.xml;
|
||||
|
||||
}
|
||||
ctx.request.body = paramsJson;
|
||||
await next();
|
||||
};
|
||||
};
|
||||
7
tool/node-wxpay/utils/util.js
Normal file
7
tool/node-wxpay/utils/util.js
Normal file
@@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
getNonceStr() {
|
||||
return Math.random().toString(36).substr(2, 15);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user