editor.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. 充值测试处理模块
  3. */
  4. var mysql = require('mysql');
  5. var mysqlcn = require('../../terry/mysqlcn.js');
  6. var query = mysqlcn.query;
  7. var qs = require('querystring');
  8. var encryption = require('../ordinary/encryption.js');
  9. var checkorder = require('../../terry/checkorder.js');
  10. var config = require('../config.js');
  11. var get_parameter = function(appid){
  12. var option = huosu_subset[appid];
  13. if (option){
  14. return option;
  15. }
  16. return null;
  17. }
  18. var pay_success = function(args,res){
  19. console.log("/editor 回调接收:%s", args);
  20. var receipt
  21. try {
  22. receipt = qs.parse(args)
  23. console.log("qs解析成功")
  24. } catch(e) {
  25. console.log(e)
  26. res.send("FAILURE");
  27. return;
  28. }
  29. var money = receipt.money // 玩家付款金额
  30. var copies = 1 // 购买份数: 付款金额 / 单价
  31. var moneytype = receipt.moneytype // 货币类型
  32. var cfid = receipt.cfid // 产品配置表id
  33. var overtime = receipt.overtime // SDK回调处理时间
  34. var channel_order_id = receipt.channel_order_id // SDK生成的订单号
  35. // var talkingdata = receipt.talkingdata // TD是否发送标识
  36. var payment_type = receipt.payment_type // 支付类型(具体使用的SDK)
  37. // var remarks = receipt.remarks // 附带信息
  38. var istest = 1 // 充值模式 istest=1沙盒测试 2:正式
  39. var cp_order_id = receipt.cp_order_id // CP订单号
  40. var channel = receipt.channel // 渠道
  41. // 玩家的付款金额、充值档位、购买份数 需要进行校验
  42. var product_id = cfid
  43. var sql = mysql.format("SELECT * FROM payinfo where orderid=?", [cp_order_id]);//在mysql库中检查订单号
  44. query(sql,function(qerr,vals,fields){
  45. if (qerr==null){
  46. if (vals[0]==null){
  47. console.log("[editor] 没有找到该订单");
  48. try{res.send("FAILURE");}
  49. catch(e){}
  50. return;
  51. }
  52. if (vals[0].overtime>0){
  53. console.log("[editor] 已经处理的订单");
  54. try{res.send("SUCCESS");}
  55. catch(e){}
  56. return;
  57. }
  58. var amountnum = money
  59. var platform = 'android';
  60. var channel = vals[0].channel
  61. var cfid = receipt.cfid
  62. var timestamp = Date.parse(new Date()) / 1000;
  63. console.log("################## cfid %s", cfid)
  64. console.log("platform:%s,channel:%s,amountnum:%s",platform,channel,amountnum)
  65. var option = config.parse(platform,channel,cfid)
  66. var cfid = option.cfid;
  67. if (cfid == 0){
  68. console.log("[editor] 获取cfid失败为cfid:%s,product_id:%s", cfid,product_id);
  69. try{res.send("FAILURE");}
  70. catch(e){}
  71. return
  72. }
  73. if (amountnum != option.price){
  74. console.log("[editor] 充值金额不同amountnum:%s,option.price:%s", amountnum, option.price);
  75. try{res.send("FAILURE");}
  76. catch(e){}
  77. return
  78. }
  79. //填充充值信息
  80. var sql_1 = "UPDATE payinfo SET \
  81. channel_order_id=?,\
  82. overtime=?,\
  83. flag=?,\
  84. money=?,\
  85. cfid=?,\
  86. platform=?,\
  87. channel=?,\
  88. moneytype=?,\
  89. product_id=?,\
  90. talkingdata=?,\
  91. payment_type=?, \
  92. copies=?,\
  93. istest=?\
  94. WHERE orderid=? \
  95. AND flag=2";//增加flag判断防止重复写入
  96. var values_2 = [channel_order_id,timestamp,1,amountnum,cfid,platform,channel,option.typename,product_id,1,payment_type,copies,istest,cp_order_id];
  97. var sql_2 = mysql.format(sql_1, values_2);
  98. query(sql_2,function(qerr,rows,fields_)
  99. {
  100. if (qerr){
  101. console.log("[editor]逻辑错误,请检查数据表结构和sql语句:\n\t%s", qerr);
  102. try{res.send("FAILURE");}
  103. catch(e){}
  104. return;
  105. }
  106. if (rows.affectedRows > 0){//判断修改了多少个记录
  107. console.log("[editor]支付成功了,现在通知游戏服务器, orderId:%s, uid:%s, serverid:%s ,cfid:%s",
  108. cp_order_id,vals[0].uid,vals[0].serverid,cfid);
  109. checkorder.pushproduct(query,vals[0].serverid, cp_order_id, function(ok){
  110. if (ok) {
  111. console.log("[editor] 订单 %s: 成功发货!", cp_order_id);
  112. } else{
  113. console.log("[editor] 订单 %s: 发货地址无效!", cp_order_id);//在无效时返回成功,我们自己补单中会派发flag为1支付成功但是没成功发货的单
  114. }
  115. try{res.send("SUCCESS");}
  116. catch(e){}
  117. });
  118. // 向 TalkingData 报告充值数据
  119. var appId = config.getAppID(channel);
  120. checkorder.pushtalkingdata(query,appId,platform,vals[0].uid,cp_order_id,option.price,option.typename,option.diamond,timestamp,payment_type,vals[0].serverid);
  121. res.send("SUCCESS");
  122. return;
  123. }else{
  124. console.log("SQL重复写入[editor]已经处理的订单");
  125. try{res.send("SUCCESS");}
  126. catch(e){}
  127. return;
  128. }
  129. })
  130. }else{
  131. console.log("[editor] 查询订单列表错误,请检查数据表结构和sql语句:\n\t%s", qerr);
  132. try{res.send("FAILURE");}
  133. catch(e){}
  134. return;
  135. }
  136. })
  137. }
  138. var express = require('express');
  139. var router = express.Router();
  140. router.post('/editor_pay_test', function(req, res) {
  141. var real_ip = req.get("X-Real-IP") || req.get("X-Forwarded-For") || req.ip;
  142. console.log("post wyhdpay,host:%s, ip:%s,path:%s,time:%s",req.hostname,real_ip,req.path,new Date());
  143. var data = "";
  144. req.on("data",function(chunk){
  145. data += chunk;
  146. });
  147. req.on("end",function(){
  148. try{
  149. pay_success(data,res)
  150. } catch(e) {
  151. console.log(e)
  152. res.send("FAILURE");
  153. }
  154. });
  155. req.on("error",function(err){
  156. console.log("error:%s",err);
  157. res.send("FAILURE");
  158. });
  159. });
  160. module.exports = router;