util_sensitive.lua 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. --[[
  2. Descripttion:敏感词
  3. version:
  4. Author: Neo,Huang
  5. Date: 2023-11-19 21:20:05
  6. LastEditors: Neo,Huang
  7. LastEditTime: 2023-11-19 21:23:40
  8. --]]
  9. local const = require("const.const")
  10. local httpc = require("http.httpc")
  11. local md5 = require("md5")
  12. local root = {}
  13. -- 是否包含敏感词
  14. function root:is_sensitive(words)
  15. if is_nil(words) then
  16. return false
  17. end
  18. -- 过滤数字
  19. local word = ""
  20. for i = 1, string.len(words) do
  21. local c = string.sub(words, i, i)
  22. if not (c >= "0" and c <= "9") then
  23. word = word .. c
  24. end
  25. end
  26. set_log("is_sensitive words[%s] word[%s]", tostring(words), tostring(word))
  27. if is_nil(word) then
  28. return false
  29. end
  30. local host = skynet.getenv("server_3rd")
  31. if is_empty(host) then
  32. -- 不检查敏感词
  33. return false
  34. end
  35. local url = "/sensitive/checkword?"
  36. local body = string.format("word=%s", word)
  37. local auth = md5.sumhexa(body .. const.SALT_MD5)
  38. body = string.format("%s&sign=%s", body, auth)
  39. local code, ret = httpc.get(host, url .. body)
  40. if ret and string.match(ret, "false") then
  41. return true
  42. end
  43. return false
  44. end
  45. return root