微信小程序 在线支付功能的实现(2)

function paysignjs(appid, nonceStr, package, signType, timeStamp) { var ret = { appId: appid, nonceStr: nonceStr, package: package, signType: signType, timeStamp: timeStamp }; var string = raw1(ret); string = string + '&key='+key; console.log(string); var crypto = require('crypto'); return crypto.createHash('md5').update(string, 'utf8').digest('hex'); }; function raw1(args) { var keys = Object.keys(args); keys = keys.sort() var newArgs = {}; keys.forEach(function(key) { newArgs[key] = args[key]; }); var string = ''; for(var k in newArgs) { string += '&' + k + '=' + newArgs[k]; } string = string.substr(1); return string; }; function paysignjsapi(appid, attach, body, mch_id, nonce_str, notify_url, openid, out_trade_no, spbill_create_ip, total_fee, trade_type) { var ret = { appid: appid, attach: attach, body: body, mch_id: mch_id, nonce_str: nonce_str, notify_url: notify_url, openid: openid, out_trade_no: out_trade_no, spbill_create_ip: spbill_create_ip, total_fee: total_fee, trade_type: trade_type }; var string = raw(ret); string = string + '&key='+key; var crypto = require('crypto'); return crypto.createHash('md5').update(string, 'utf8').digest('hex'); }; function raw(args) { var keys = Object.keys(args); keys = keys.sort() var newArgs = {}; keys.forEach(function(key) { newArgs[key.toLowerCase()] = args[key]; }); var string = ''; for(var k in newArgs) { string += '&' + k + '=' + newArgs[k]; } string = string.substr(1); return string; }; function getXMLNodeValue(node_name, xml) { var tmp = xml.split("<" + node_name + ">"); var _tmp = tmp[1].split("</" + node_name + ">"); return _tmp[0]; }

这样简单3步,小程序的微信支付功能就接上了,下面是测试的支付效果图

微信小程序 在线支付功能的实现

微信小程序 在线支付功能的实现

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwwdjg.html