recharge.lua 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. local logger = require "logger"
  2. local redisdriver = require "skynet.db.redis"
  3. local stringify = require "stringify"
  4. local skynet = require "skynet"
  5. local queue = require "skynet.queue"
  6. local asset = require "model.asset"
  7. local synchronized = queue()
  8. local cjson = require "cjson"
  9. local md5 = require "md5"
  10. local trace = logger.trace
  11. --local trace = function(...) end
  12. local authz = {acc = "yytx", pwd = "lee@YY-Games.520"}
  13. -- Generate request data
  14. local content = {acc = authz.acc, pwd = authz.pwd, sign = false}
  15. content.sign = string.sub(md5.sumhexa(content.acc .. content.pwd), 9, 24)
  16. local whitelist = {
  17. ["127.0.0.1"] = true,
  18. ["39.97.97.91"] = true, -- IOS 测试服
  19. ["192.168.101.41"] = true, -- 淡心服务器
  20. ["222.212.88.4"] = true,
  21. }
  22. local redis
  23. local start
  24. local rechargeser
  25. local INDENT = "indent:"
  26. local KEYGEN_PAY = "%s:%s"
  27. local function start_pay()
  28. local conf = assert(option.redis)
  29. redis = redisdriver.connect(conf)
  30. redis:select(3)--切换到数据库db1
  31. rechargeser = rechargeser or skynet.localname(".recharge")
  32. return 1
  33. end
  34. --192.168.1.44:9001/recharge?cfid=128&uid=9999&orderid=98756
  35. local recharge = function(args, ipaddr)
  36. return synchronized(function()
  37. start = start or start_pay()
  38. trace("处理来自主机 %s 的充值请求", ipaddr)
  39. if not whitelist[ipaddr] then
  40. -- return { code=403, msg="Forbidden" }
  41. end
  42. -- 验证gm账号
  43. -- local code = string.sub(args.code, 1, 16)
  44. -- if code ~= content.sign then
  45. -- return cjson.encode({state = 403, msg = "账号或密码错误"})
  46. -- end
  47. trace("开始处理充值信息:%s",stringify(args))
  48. local uid = args.uid
  49. local cfid = tonumber(args.cfid)
  50. local orderid = args.orderid
  51. local appname = args.appname or "NULL"
  52. local giftid = tonumber(args.product_id)
  53. if not uid or not cfid or not orderid or not giftid then
  54. return { code=1 }--数据不足
  55. end
  56. local key = INDENT..string.format(KEYGEN_PAY,uid,orderid)
  57. -- HEXISTS
  58. if redis:hexists(key,"uid") == 1 then
  59. return { code=2 }--已存在
  60. end
  61. -- test recharge
  62. if not asset.RechargeConfig_proto[cfid] then
  63. return { code=3 }--错误的cfid
  64. end
  65. if not asset.GiftConfig_proto[giftid] then
  66. return { code=4 }--错误的礼包id
  67. end
  68. skynet.send(rechargeser,"lua", "orderid_record", uid, cfid, orderid, appname, giftid)
  69. return { code=0 }
  70. end)
  71. end
  72. return recharge