util_3rd.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 code = require("code")
  13. local root = {}
  14. ----------------------------------------
  15. -- 敏感词
  16. ----------------------------------------
  17. -- 是否包含敏感词
  18. function root:is_sensitive(words)
  19. if is_nil(words) then
  20. return false
  21. end
  22. -- 过滤数字
  23. local word = ""
  24. for i = 1, string.len(words) do
  25. local c = string.sub(words, i, i)
  26. if not (c >= "0" and c <= "9") then
  27. word = word .. c
  28. end
  29. end
  30. set_log("is_sensitive words[%s] word[%s]", tostring(words), tostring(word))
  31. if is_nil(word) then
  32. return false
  33. end
  34. local host = skynet.getenv("server_3rd")
  35. if is_empty(host) then
  36. -- 不检查敏感词
  37. return false
  38. end
  39. local url = "/sensitive/checkword?"
  40. local body = string.format("word=%s", word)
  41. local auth = md5.sumhexa(body .. const.SALT_MD5)
  42. body = string.format("%s&sign=%s", body, auth)
  43. local code, ret = httpc.get(host, url .. body)
  44. if ret and string.match(ret, "false") then
  45. return true
  46. end
  47. return false
  48. end
  49. ----------------------------------------
  50. -- 实名认证
  51. ----------------------------------------
  52. -- 检验账号
  53. function root:real_name_check(uid, channel, name, idNum)
  54. log.info(
  55. "real_name_check uid[%s] channel[%s] name[%s] idNum[%s]",
  56. tostring(uid),
  57. tostring(channel),
  58. tostring(name),
  59. tostring(idNum)
  60. )
  61. if uid == nil or channel == nil or name == nil or idNum == nil then
  62. return -1
  63. end
  64. local host = skynet.getenv("server_3rd")
  65. if is_nil(host) then
  66. if IS_TEST then
  67. return 0
  68. end
  69. return -1
  70. end
  71. local url =
  72. string.format(
  73. "/nppa/check_id?uid=%s&channel=%s&name=%s&idNum=%s",
  74. tostring(uid),
  75. tostring(channel),
  76. tostring(name),
  77. tostring(idNum)
  78. )
  79. local errCode, res = httpc.get(host, url)
  80. log.info(
  81. "real_name_check uid[%s] errCode[%s] res[%s] host[%s] url[%s]",
  82. tostring(uid),
  83. tostring(errCode),
  84. tostring(res),
  85. tostring(host),
  86. tostring(url)
  87. )
  88. if errCode ~= 200 or is_nil(res) then
  89. return -1
  90. end
  91. res = cjson_decode(res)
  92. if is_nil(res) then
  93. return -1
  94. end
  95. if res.code ~= 200 then
  96. return -1
  97. end
  98. return res.status, res.pi
  99. end
  100. -- 获取账号校验结果
  101. function root:real_name_query_player_result(uid, channel)
  102. if uid == nil or channel == nil then
  103. return
  104. end
  105. local host = skynet.getenv("server_3rd")
  106. if is_nil(host) then
  107. return -1
  108. end
  109. local url = string.format("/nppa/query_id?uid=%s&channel=%s", tostring(uid), tostring(channel))
  110. local errCode, res = httpc.get(host, url)
  111. if code.is_not_ok(errCode) or is_nil(res) then
  112. return -1
  113. end
  114. res = cjson_decode(res)
  115. if is_nil(res) then
  116. return -1
  117. end
  118. return res.status, res.pi
  119. end
  120. -- 玩家行为上报
  121. -- channel:渠道
  122. -- si:游戏内部会话标识
  123. -- bt:用户行为类型 0:下线 1:上线
  124. -- ot:行为发生时间戳
  125. -- ct:用户行为数据上报类型 0:已认证用户 2:游客
  126. -- di:游客模式设备标识
  127. -- pi:实名用户唯一标识
  128. function root:real_name_report_collect_login_and_out(channel, si, bt, ot, ct, di, pi)
  129. log.info(
  130. "real_name_report_collect_login_and_out channel[%s] si[%s] bt[%s]",
  131. tostring(channel),
  132. tostring(si),
  133. tostring(bt)
  134. )
  135. local host = skynet.getenv("server_3rd")
  136. if is_nil(host) then
  137. return
  138. end
  139. local url =
  140. string.format(
  141. "/nppa/loginout?channel=%s&si=%s&bt=%s&ot=%s&ct=%s&di=%s&pi=%s",
  142. tostring(channel),
  143. tostring(si),
  144. tostring(bt),
  145. tostring(ot),
  146. tostring(ct),
  147. tostring(di),
  148. tostring(pi)
  149. )
  150. local errCode, res = httpc.get(host, url)
  151. log.info(
  152. "real_name_report_collect_login_and_out host[%s] url[%s] errCode[%s] res[%s]",
  153. tostring(host),
  154. tostring(url),
  155. tostring(errCode),
  156. tostring(res)
  157. )
  158. end
  159. return root