init.lua 3.1 KB

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