init.lua 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 fq_book = require "fq_book"
  20. local book_black_list = require "book_black_list"
  21. local video_titles = require "video_titles"
  22. local pull_data_config = require "pull_data_config"
  23. local pull_data_status = require "pull_data_status"
  24. local status_200 = 200
  25. local CMD = {
  26. }
  27. CMD["tg_temp_app"] = tg_temp_app;
  28. CMD["tg_platform"] = tg_platform;
  29. CMD["tg_zhanghu"] = tg_zhanghu;
  30. CMD["tg_max_zhuanhua"] = tg_max_zhuanhua;
  31. CMD["tg_app"] = tg_app;
  32. CMD["user"] = user;
  33. CMD["tg_main"] = tg_main;
  34. CMD["db_filter_config"] = db_filter_config;
  35. CMD["push_msg"] = push_msg;
  36. CMD["filter_task"] = filter_task;
  37. CMD["fq_book"] = fq_book;
  38. CMD["book_black_list"] = book_black_list;
  39. CMD["video_titles"] = video_titles;
  40. CMD["pull_data_config"] = pull_data_config;
  41. CMD["pull_data_status"] = pull_data_status;
  42. function run(target,fun,msg_body,fd)
  43. if target~=nil and fun~=nil and target[fun]~=nil then
  44. local isok,data,total = target[fun](msg_body)
  45. if isok then
  46. if data~=nil then
  47. if total~=nil then
  48. tools.response(fd,status_200,cjson.encode({code=10000,data=data,total=total}))
  49. else
  50. tools.response(fd,status_200,cjson.encode({code=10000,data=data}))
  51. end
  52. else
  53. tools.response(fd,status_200,cjson.encode({code=10000,msg="OK!"}))
  54. end
  55. else
  56. tools.response(fd,status_200,cjson.encode({code=10001,msg=data}))
  57. end
  58. else
  59. return tools.response(fd,status_200,{code=10002,msg="没找到方法!"})
  60. end
  61. end
  62. CMD.api = function(msg_body,fd)
  63. if msg_body~=nil and msg_body~="" then
  64. if CMD[msg_body['cmd']] then
  65. run(CMD[msg_body['cmd']],msg_body['fun'],msg_body['data'],fd)
  66. end
  67. end
  68. end
  69. CMD.ws_push_msg = function(msg_body)
  70. CMD['push_msg'].push(msg_body.cmd,msg_body.data)
  71. end
  72. --接口end
  73. s.resp.on_recv = function (source, fd, msg_id, msg_body)
  74. if CMD[msg_id]~=nil then
  75. tools.dump(msg_body)
  76. CMD[msg_id](cjson.decode(msg_body),fd)
  77. end
  78. end
  79. s.init = function()
  80. end
  81. s.start(...)