init.lua 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. local skynet = require "skynet"
  2. local s = require "service"
  3. local tools = require "tools"
  4. local cjson = require "cjson"
  5. local mysql = require "skynet.db.mysql"
  6. local back_response = require "back_response"
  7. local urllib = require "http.url"
  8. local crypt = require "skynet.crypt"
  9. local tg_temp_app = require "tg_temp_app"
  10. local tg_platform = require "tg_platform"
  11. local tg_zhanghu = require "tg_zhanghu"
  12. local tg_max_zhuanhua = require "tg_max_zhuanhua"
  13. local user = require "user"
  14. local tg_app = require "tg_app"
  15. local tg_main = require "tg_main"
  16. local db_filter_config = require "db_filter_config"
  17. local push_msg = require "push_msg"
  18. local filter_task = require "filter_task"
  19. local status_200 = 200
  20. local CMD = {
  21. }
  22. CMD["tg_temp_app"] = tg_temp_app;
  23. CMD["tg_platform"] = tg_platform;
  24. CMD["tg_zhanghu"] = tg_zhanghu;
  25. CMD["tg_max_zhuanhua"] = tg_max_zhuanhua;
  26. CMD["tg_app"] = tg_app;
  27. CMD["user"] = user;
  28. CMD["tg_main"] = tg_main;
  29. CMD["db_filter_config"] = db_filter_config;
  30. CMD["push_msg"] = push_msg;
  31. CMD["filter_task"] = filter_task;
  32. function run(target,fun,msg_body,fd)
  33. if target~=nil and fun~=nil and target[fun]~=nil then
  34. local isok,data,total = target[fun](msg_body)
  35. if isok then
  36. if data~=nil then
  37. if total~=nil then
  38. tools.response(fd,status_200,cjson.encode({code=10000,data=data,total=total}))
  39. else
  40. tools.response(fd,status_200,cjson.encode({code=10000,data=data}))
  41. end
  42. else
  43. tools.response(fd,status_200,cjson.encode({code=10000,msg="OK!"}))
  44. end
  45. else
  46. tools.response(fd,status_200,cjson.encode({code=10001,msg=data}))
  47. end
  48. else
  49. return tools.response(fd,status_200,{code=10002,msg="没找到方法!"})
  50. end
  51. end
  52. CMD.api = function(msg_body,fd)
  53. if msg_body~=nil and msg_body~="" then
  54. if CMD[msg_body['cmd']] then
  55. run(CMD[msg_body['cmd']],msg_body['fun'],msg_body['data'],fd)
  56. end
  57. end
  58. end
  59. CMD.ws_push_msg = function(msg_body)
  60. CMD['push_msg'].push(msg_body.cmd,msg_body.data)
  61. end
  62. --接口end
  63. s.resp.on_recv = function (source, fd, msg_id, msg_body)
  64. if CMD[msg_id]~=nil then
  65. tools.dump(msg_body)
  66. CMD[msg_id](cjson.decode(msg_body),fd)
  67. end
  68. end
  69. s.init = function()
  70. end
  71. s.start(...)