web_recharge_query.lua 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. --[[
  2. author:{zlf}
  3. time:2019-12-14 14:42:28
  4. note: web网页充值查询玩家数据
  5. jira: PK3-1102
  6. ]]--
  7. local skynet = require "skynet"
  8. require "skynet.manager"
  9. local logger = require "logger"
  10. local queue = require "skynet.queue"
  11. local cjson = require "cjson"
  12. local stringify = require "stringify"
  13. local pipeline = require "pipeline"
  14. local loader = require "model.loader"
  15. local elf = require "model.elf"
  16. local equipment = require "model.equipment"
  17. local redisdriver = require "skynet.db.redis"
  18. local asset = require "model.asset"
  19. local md5 = require "md5"
  20. local ti=require "model.title"
  21. local synchronized = queue()
  22. local skynet_send = skynet.send
  23. local skynet_call = skynet.call
  24. local status = 0
  25. local db_character
  26. local authz = {acc = "yytx", pwd = "lee@YY-Games.520"}
  27. local content = {acc = authz.acc, pwd = authz.pwd, sign = false}
  28. content.sign = string.sub(md5.sumhexa(content.acc .. content.pwd), 9, 24)
  29. local whitelist = {
  30. ["192.168.1.23"] = true,
  31. ["192.168.1.127"] = true,
  32. ["192.168.1.50"] = true,
  33. ["14.29.136.211"] = true,
  34. ["192.168.1.41"] = true,
  35. ["222.212.88.4"] = true,
  36. }
  37. local function initialize()
  38. status = 1
  39. local conf = assert(option.redis)
  40. db_character = redisdriver.connect(conf)
  41. db_character:select(0)
  42. end
  43. --请求方式1: http://服务器ip地址:端口号/web_recharge_query?code=xxx&玩家uid
  44. --示例: http://192.168.1.102:8002/web_recharge_query?code=xxx&uid=00-6565406671068221440
  45. local web_recharge_query = function(args, ipaddr,header)
  46. return synchronized(function()
  47. logger.trace("处理来自主机 %s 的获取玩家数据请求", ipaddr)
  48. logger.trace(" args %s", stringify(args))
  49. if status == 0 then
  50. initialize()
  51. end
  52. if not whitelist[ipaddr] then
  53. -- return cjson.encode({state = 403, host = header.host, info = "不信任ip"})
  54. end
  55. -- 验证gm账号
  56. local code=string.sub(args.code,1,16)
  57. if code ~= content.sign then
  58. return cjson.encode({state = 403,msg= "账号或密码错误"})
  59. end
  60. local uid
  61. if args.uid then
  62. uid=args.uid
  63. elseif not args.uid then
  64. return cjson.encode({state = 403,msg= "请输入玩家uid或者玩家name"})
  65. end
  66. local key = string.format("character:%s", uid)
  67. local info = db_character:HMGET(key, "nickname", "sid")
  68. -- return cjson.encode({state = 400,msg = "加载玩家数据失败", content= uid})
  69. if next(info) then
  70. local retdata = {
  71. name = info[1],
  72. svrid = info[2],
  73. }
  74. logger.trace(" retdata.recharge = %s", stringify(retdata))
  75. return cjson.encode({state=0,msg="success",content=retdata,})
  76. else
  77. return cjson.encode({state = 400, msg = "未找到该玩家"})
  78. end
  79. end)
  80. end
  81. return web_recharge_query