//QUICK var https = require('https'); var http = require('http'); var mysql = require('mysql'); var config = require('../../pay/config'); var crypto = require('crypto'); var qs = require('querystring'); var checkorder = require('../checkorder'); var url = require('url'); var xml2js = require('xml2js'); var parser = new xml2js.Parser(); //xml -> json var builder = new xml2js.Builder(); // JSON->xml //md5加密 var md5 = function (str){ var md5sum = crypto.createHash('md5'); md5sum.update(str); str = md5sum.digest('hex'); return str; }; //quick解密操作 function stringToBytes (str) { var ch, st, re = []; for (var i = 0; i < str.length; i++ ) { ch = str.charCodeAt(i); st = []; do { st.push( ch & 0xFF ); ch = ch >> 8; }while ( ch ); re = re.concat( st.reverse() ); } return re; } function bytesToString(array) { return String.fromCharCode.apply(String, array); } //将quick的加密文件解密成XML文件 function decode(str,key){ if(str.length <= 0){ return ''; } var list = new Array(); var resultMatch = str.match(/\d+/g); for(var i= 0;i0){ console.log(outputname+"quick已经处理的订单"); try{res.send("SUCCESS");} catch(e){} return; } var genSign = md5(nt_data+sign+md5_key); if(md5Sign != genSign){ console.log(outputname+"quick支付签名验证失败,md5Sign:%s,genSign:%s",md5Sign,genSign); try{res.send("FAILED");} catch(e){} return; } //var des = "null";//描述订单支付成功或失败的系统备注 var platform = 'android'; // 只存储 ios 和 android var channel = quick_proto.channel; // 只存储 qianxun、zaya、limayao, zhangyu, friday, wudiyongshi, banli, zhiyu, cloud var payment_type = pay_channel.toString(); // 具体的子渠道,比如 quick 的 微信、手Q、UC、应用宝等, 新增一个 paymentType 字段来填充 var timestamp = Date.parse(new Date()) / 1000; var option = config.parse(platform,channel,extras_params)//extras_params var cfid = option.cfid//config.quick_dollar(parseInt(amount));//购买商品ID--parseInt转int if (cfid == 0){ console.log(outputname+"QUICK获取cfid失败为:%s,extras_params:%s", cfid,extras_params); try{res.send("FAILED");} catch(e){} return; } if (amount != option.price){ console.log(outputname+"QUICK金额不一致为amount:%s,option.price:%s", amount,option.price); try{res.send("FAILED");} catch(e){} return; } var sql_2 = sql_update_quick(order_no,timestamp,1,amount,cfid,platform,channel,payment_type,option.typename,game_order) query(sql_2,function(qerr,rows,fields_) { if (qerr){ console.log(qerr); try{res.send("FAILED");} //"逻辑错误,请检查数据表结构和sql语句"} catch(e){} return; } if (rows.affectedRows <= 0){//判断修改了多少个记录 console.log(outputname+"quick已经处理的订单"); try{res.send("SUCCESS");} catch(e){} return; } console.log(outputname+"quick支付成功了,现在通知游戏服务器, game_order:%s, username:%s, playerid:%s, serverid:%s ,cfid:%s", game_order,vals[0].username,vals[0].playerid,vals[0].serverid,cfid); //send_2_game(query,game_order,vals[0].username,vals[0].playerid,vals[0].serverid,cfid, function(ok){ checkorder.pushproduct(query,game_order,vals[0].uid,vals[0].serverid,cfid, function(ok){ if (ok) { console.log(outputname+"QUICK 订单 %s: 成功发货!", game_order); try{res.send("SUCCESS");} catch(e){} } else{ console.log(outputname+"QUICK 订单 %s: 发货地址无效!", game_order); try{res.send("FAILED");} catch(e){} } }); // 向 TalkingData 报告充值数据 var appId = config.getAppID(channel); checkorder.pushtalkingdata(query,appId,platform,vals[0].uid,game_order,option.price,option.typename,option.diamond,timestamp,payment_type,vals[0].serverid); }) }); }catch(err){ console.log(outputname+"quick_err ,%s",err); try{res.send("FAILED");} catch(e){} } } } }) }