Bladeren bron

修改第三方工具,增加中宣部实名认证

neo 1 jaar geleden
bovenliggende
commit
0cae9c0caf
4 gewijzigde bestanden met toevoegingen van 173 en 52 verwijderingen
  1. 2 2
      dev/modules/user.lua
  2. 169 0
      dev/utils/util_3rd.lua
  3. 0 48
      dev/utils/util_sensitive.lua
  4. 2 2
      nodes/web/controllers/usr.lua

+ 2 - 2
dev/modules/user.lua

@@ -1,7 +1,7 @@
1 1
 local code = require("code")
2 2
 local util_player = require("utils.util_player")
3 3
 local util_global = require("utils.util_global")
4
-local util_sensitive = require("utils.util_sensitive")
4
+local util_3rd = require("utils.util_3rd")
5 5
 
6 6
 local playerData = require("data.player")
7 7
 
@@ -126,7 +126,7 @@ function root:itf_update_nickname(role, msg)
126 126
         return code.PARAMTER_ERROR
127 127
     end
128 128
     -- 检查敏感词
129
-    if util_sensitive:is_sensitive(nickname) then
129
+    if util_3rd:is_sensitive(nickname) then
130 130
         return code.USR.INCLUDE_SENSITIVE
131 131
     end
132 132
     self:redis_update_key_info("nickname", nickname)

+ 169 - 0
dev/utils/util_3rd.lua

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

+ 0 - 48
dev/utils/util_sensitive.lua

@@ -1,49 +0,0 @@
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
-
13
-local root = {}
14
-
15
-function root:is_sensitive(words)
16
-    if is_nil(words) then
17
-        return false
18
-    end
19
-    -- 过滤数字
20
-    local word = ""
21
-    for i = 1, string.len(words) do
22
-        local c = string.sub(words, i, i)
23
-        if not (c >= "0" and c <= "9") then
24
-            word = word .. c
25
-        end
26
-    end
27
-    set_log("is_sensitive words[%s] word[%s]", tostring(words), tostring(word))
28
-    if is_nil(word) then
29
-        return false
30
-    end
31
-
32
-    local host = skynet.getenv("server_3rd")
33
-    if is_empty(host) then
34
-        -- 不检查敏感词
35
-        return false
36
-    end
37
-    local url = "/sensitive/checkword?"
38
-    local body = string.format("word=%s", word)
39
-    local auth = md5.sumhexa(body .. const.SALT_MD5)
40
-    body = string.format("%s&sign=%s", body, auth)
41
-    local code, ret = httpc.get(host, url .. body)
42
-    if ret and string.match(ret, "false") then
43
-        return true
44
-    end
45
-    return false
46
-end
47
-
48
-return root

+ 2 - 2
nodes/web/controllers/usr.lua

@@ -5,7 +5,7 @@ local util_user = require("utils.util_user")
5 5
 local util_global = require("utils.util_global")
6 6
 local lib_game_mysql = require("lib_game_mysql")
7 7
 local lib_game_redis = require("lib_game_redis")
8
-local util_sensitive = require("utils.util_sensitive")
8
+local util_3rd = require("utils.util_3rd")
9 9
 
10 10
 local accountModule = require("modules.account")
11 11
 
@@ -155,7 +155,7 @@ function root.usr_register_by_phone(msg)
155 155
         return root.usr_login_by_phone(msg)
156 156
     end
157 157
     -- 敏感词
158
-    if util_sensitive:is_sensitive(msg.nickname) then
158
+    if util_3rd:is_sensitive(msg.nickname) then
159 159
         return code.USR.INCLUDE_SENSITIVE
160 160
     end
161 161
     local uid = util_global:gen_user_id()