util_3rd.lua 4.3 KB

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