produce.lua 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. --[[
  2. 彩票奖励库测试接口
  3. ]]
  4. local skynet = require "skynet"
  5. local codecache = require "skynet.codecache"
  6. require "skynet.manager"
  7. local logger = require "logger"
  8. local stringify = require "stringify"
  9. local cjson = require "cjson"
  10. local assetcenter
  11. local watchdog
  12. local traceback = debug.traceback
  13. local md5 = require "md5"
  14. local authz = {
  15. acc="yytx",
  16. pwd="lee@YY-Games.520"
  17. }
  18. -- Generate request data
  19. local content = {
  20. acc = authz.acc,
  21. pwd = authz.pwd,
  22. sign = false
  23. }
  24. content.sign = string.sub(md5.sumhexa(content.acc .. content.pwd),9,24)
  25. local whitelist = {
  26. ["192.168.1.23"] = true,
  27. ["192.168.1.127"] = true,
  28. ["192.168.1.50"] = true,
  29. ["14.29.136.211"] = true,
  30. ["192.168.1.41"] = true,
  31. ["222.212.88.4"] = true,
  32. }
  33. --[[
  34. example:
  35. 参数说明:
  36. sid 奖励id
  37. times 奖励生成多少份
  38. begin 第几次生成奖励
  39. nameconf 具体使用那个彩票奖励库
  40. http://192.168.1.102:9002/produce?code=xxx&vjson=[
  41. sid = 701003,
  42. nameconf = "lottery_proto",
  43. begin = 1,
  44. times = 3,
  45. ]
  46. ]]
  47. local function produce(args, ipaddr, header)
  48. logger.warn("处理来自主机 %s 的 produce 请求,:%s", ipaddr,stringify(args))
  49. -- 验证gm账号
  50. local code = string.sub(args.code, 1, 16)
  51. if code ~= content.sign then
  52. return cjson.encode({state = 403, msg = "账号或密码错误"})
  53. end
  54. logger.trace(" === %s", cjson.encode({
  55. sid = 701003,
  56. nameconf = "lottery_proto",
  57. begin = 1,
  58. times = 3,
  59. }))
  60. local para = cjson.decode(args.vjson)
  61. local produce_award = require "produce_award"
  62. local ok, info = xpcall(produce_award, traceback, tonumber(para.sid), tonumber(para.times), tonumber(para.begin), para.nameconf)
  63. if not ok then
  64. logger.trace(" 奖励库生成异常 %s:%s", stringify(para), info)
  65. return cjson.encode({state = 403, info = info})
  66. end
  67. logger.warn("hotfix (%s, %s)", args.user, ipaddr)
  68. return cjson.encode({errno = 0, info = info})
  69. end
  70. return produce