login-flow-plantuml.puml 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. @startuml login-flow
  2. !theme plain
  3. skinparam backgroundColor #FEFEFE
  4. skinparam shadowing false
  5. skinparam defaultFontName "Microsoft YaHei"
  6. skinparam defaultFontSize 12
  7. ' ============================================================
  8. ' 1. 整体请求处理流程
  9. ' ============================================================
  10. title 1. 整体请求处理流程
  11. |客户端|
  12. start
  13. :发送请求;
  14. |服务端 - Api._initialize|
  15. :设备识别 (header/body);
  16. :AES-128-ECB 解密 body;
  17. if (解密成功?) then (是)
  18. :JSON 解析参数;
  19. else (否)
  20. :尝试明文 input();
  21. endif
  22. :MD5 签名校验;
  23. if (签名校验通过?) then (是)
  24. else (否)
  25. :返回 -124 签名拒绝;
  26. stop
  27. endif
  28. switch (路由分发)
  29. case (/login/index)
  30. :普通登录 index();
  31. case (/login/third)
  32. :第三方登录 third();
  33. case (/login/checkToken)
  34. :Token 校验 checkToken();
  35. case (/login/logout)
  36. :退出登录 logout();
  37. endswitch
  38. stop
  39. @enduml
  40. ' ============================================================
  41. ' 2. 普通登录 index() 流程
  42. ' ============================================================
  43. @startuml login-index
  44. !theme plain
  45. skinparam backgroundColor #FEFEFE
  46. skinparam shadowing false
  47. skinparam defaultFontName "Microsoft YaHei"
  48. title 2. 普通登录 index() 流程
  49. start
  50. :接收参数\nusername, password, imeil,\ngameid, device, channel_id;
  51. if (海外游戏 && 国内IP?) then (是)
  52. :返回 -110 国内用户禁止登录;
  53. stop
  54. endif
  55. if (参数完整?) then (否)
  56. :返回 -100 缺少参数;
  57. stop
  58. endif
  59. if (渠道存在且启用?) then (否)
  60. :返回 -120 渠道不存在或已禁用;
  61. stop
  62. endif
  63. if (渠道 level=3?) then (否)
  64. :返回 -120 非推广员渠道;
  65. stop
  66. endif
  67. if (游戏存在且未下架?) then (否)
  68. :返回 -120 游戏信息不存在;
  69. stop
  70. endif
  71. if (游戏开启登录白名单?) then (是)
  72. if (用户在白名单中?) then (否)
  73. :返回 -120 当前游戏禁止登录;
  74. stop
  75. endif
  76. endif
  77. if (渠道被封禁?) then (是)
  78. :返回 -120 渠道禁止登录;
  79. stop
  80. endif
  81. :密码加密 auth_code(password, ENCODE, auth_key);
  82. :查询用户 where username + password;
  83. if (用户存在?) then (否)
  84. :返回 -120 账号不存在或密码不正确;
  85. stop
  86. endif
  87. if (主账号冻结 flag=1?) then (是)
  88. :返回 -120 账号已冻结;
  89. stop
  90. endif
  91. if (子账号冻结?) then (是)
  92. :返回 -120 子账号已冻结;
  93. stop
  94. endif
  95. :FkStrategiesService 风控策略检查;
  96. if (触发风控?) then (是)
  97. :返回 -120 风控冻结;
  98. stop
  99. endif
  100. :调用 loginProcess();
  101. stop
  102. @enduml
  103. ' ============================================================
  104. ' 3. 第三方登录 third() 流程
  105. ' ============================================================
  106. @startuml login-third
  107. !theme plain
  108. skinparam backgroundColor #FEFEFE
  109. skinparam shadowing false
  110. skinparam defaultFontName "Microsoft YaHei"
  111. title 3. 第三方登录 third() 流程
  112. start
  113. :接收参数\nusername(第三方UID), imeil, gameid,\ndevice, channel_id, type_id;
  114. if (参数校验通过?) then (否)
  115. :返回错误;
  116. stop
  117. endif
  118. if (渠道/游戏校验通过?) then (否)
  119. :返回错误;
  120. stop
  121. endif
  122. switch (type_id)
  123. case (1 = 微信)
  124. :查询 wx_uid;
  125. case (2 = QQ)
  126. :查询 qq_uid;
  127. case (3 = 抖音)
  128. :查询 dy_uid;
  129. endswitch
  130. if (用户已存在?) then (是)
  131. :调用 loginProcess();
  132. else (否)
  133. :自动生成随机用户名 (11位);
  134. :创建账号 (密码固定, fromflag=type);
  135. :插入 cy_member_history;
  136. :插入 cy_memberstwo 实名扩展;
  137. :调用 loginProcess();
  138. endif
  139. stop
  140. @enduml
  141. ' ============================================================
  142. ' 4. loginProcess 公共处理流程
  143. ' ============================================================
  144. @startuml login-process
  145. !theme plain
  146. skinparam backgroundColor #FEFEFE
  147. skinparam shadowing false
  148. skinparam defaultFontName "Microsoft YaHei"
  149. title 4. loginProcess 公共处理流程
  150. start
  151. :接收 userinfo, gameid, imeil, device, channelId;
  152. if (IP 被封禁?) then (是)
  153. :钉钉告警;
  154. :返回 IP禁止登录;
  155. stop
  156. endif
  157. if (IMEI 被封禁?) then (是)
  158. :钉钉告警;
  159. :返回 设备禁止登录;
  160. stop
  161. endif
  162. if (渠道被封禁?) then (是)
  163. :返回 渠道禁止登录;
  164. stop
  165. endif
  166. if (开启防沉迷? isPreventHook==2) then (是)
  167. :查询实名信息 MembersTwo + Subaccount;
  168. if (中宣部实名认证? game_auth_type==1) then (是)
  169. :使用子账号的 auth_status 判断;
  170. endif
  171. if (未实名 或 未成年人?) then (是)
  172. if (法定节假日?) then (是)
  173. if (20:00-21:00?) then (是)
  174. :设置 offline_time = 21:00;
  175. else (否)
  176. :返回 未成年限制;
  177. stop
  178. endif
  179. else (否)
  180. if (周五/六/日?) then (是)
  181. if (20:00-21:00?) then (是)
  182. :设置 offline_time = 21:00;
  183. else (否)
  184. :返回 未成年限制;
  185. stop
  186. endif
  187. else (否)
  188. :返回 未成年限制;
  189. stop
  190. endif
  191. endif
  192. endif
  193. endif
  194. :Db::startTrans() 开启事务;
  195. if (首次登录该游戏?) then (是)
  196. :创建 MemberChannelGame 绑定;
  197. :插入玩家游戏渠道绑定记录;
  198. else (否)
  199. :更新最后登录时间;
  200. endif
  201. if (子账号已存在 sub_username?) then (是)
  202. :更新子账号时间和设备;
  203. else (否)
  204. :生成 sub_username = userid_APP_STATUS;
  205. :创建或更新 Subaccount 记录;
  206. endif
  207. :MemberDevice::addDevice() 更新设备列表;
  208. :Logininfo::limitInsert() 写入登录日志;
  209. :saveDevices() 收集设备信息;
  210. :更新 Members 最后登录时间;
  211. :Db::commit() 提交事务;
  212. :生成 Token;
  213. note right
  214. Token = auth_code(
  215. userid|username|gameid|
  216. sub_username|随机码|sdk,
  217. ENCODE, auth_key
  218. )
  219. end note
  220. :Redis 存储;
  221. note right
  222. token → imeil (15天)
  223. token|sdk|{userid}|{gameid} → 随机码 (15天)
  224. end note
  225. if (中宣部防沉迷?) then (是)
  226. :Authentication::loginout() 上报登录状态;
  227. endif
  228. :返回 token, username, sub_username, offline_time;
  229. stop
  230. @enduml
  231. ' ============================================================
  232. ' 5. Token 校验机制
  233. ' ============================================================
  234. @startuml token-check
  235. !theme plain
  236. skinparam backgroundColor #FEFEFE
  237. skinparam shadowing false
  238. skinparam defaultFontName "Microsoft YaHei"
  239. title 5. Token 校验机制 (checkLogin)
  240. start
  241. if (在 noNeedLogin 列表中?) then (是)
  242. :跳过校验;
  243. stop
  244. endif
  245. :获取 token 和 imeil;
  246. if (token 为空?) then (是)
  247. :返回 -132 未登录;
  248. stop
  249. endif
  250. :Redis 获取 token→imei;
  251. if (Redis 中存在?) then (否)
  252. :返回 -133 登录失效;
  253. stop
  254. endif
  255. if (imei 匹配?) then (否)
  256. :返回 -134 异地登录;
  257. stop
  258. endif
  259. :解密 token\nauth_code(token, DECODE, auth_key);
  260. :提取 userid, username, gameid,\nsub_username, 随机码, type;
  261. :Redis 获取 token|{type}|{userid}|{gameid}→随机码;
  262. if (随机码存在?) then (否)
  263. :删除 token;
  264. :返回 -137 登录异常;
  265. stop
  266. endif
  267. if (随机码匹配?) then (否)
  268. :删除 token;
  269. :返回 -138 登录异常;
  270. stop
  271. endif
  272. :校验通过;
  273. :注入 userid, gameid, username, token, sub_username;
  274. stop
  275. @enduml
  276. ' ============================================================
  277. ' 6. 数据模型关系
  278. ' ============================================================
  279. @startuml login-er
  280. !theme plain
  281. skinparam backgroundColor #FEFEFE
  282. skinparam shadowing false
  283. skinparam defaultFontName "Microsoft YaHei"
  284. title 6. 数据模型关系 (ER 图)
  285. entity "Members" as M {
  286. *id : int <<PK>>
  287. --
  288. username : string
  289. password : string
  290. wx_uid : string
  291. qq_uid : string
  292. dy_uid : string
  293. flag : int
  294. channel_id : int
  295. reg_time : int
  296. login_time : int
  297. nickname : string
  298. }
  299. entity "Subaccount" as S {
  300. *id : int <<PK>>
  301. --
  302. member_id : int <<FK>>
  303. game_id : int <<FK>>
  304. sub_username : string
  305. channel_id : int
  306. auth_status : int
  307. real_name : string
  308. idcard_num : string
  309. auth_pi : string
  310. flag : int
  311. create_time : int
  312. update_time : int
  313. last_imeil : string
  314. }
  315. entity "MemberChannelGame" as MCG {
  316. *mcgr_id : int <<PK>>
  317. --
  318. member_id : int <<FK>>
  319. game_id : int <<FK>>
  320. channel_id : int <<FK>>
  321. mcgr_imeil : string
  322. mcgr_ip : string
  323. mcgr_createtime : int
  324. update_time : int
  325. }
  326. entity "MembersTwo" as MT {
  327. *id : int <<PK>>
  328. --
  329. userid : int <<FK>>
  330. username : string
  331. realname : string
  332. idcard : string
  333. create_time : int
  334. }
  335. entity "Logininfo" as LI {
  336. *id : int <<PK>>
  337. --
  338. userid : int <<FK>>
  339. sub_id : int
  340. gameid : int
  341. imeil : string
  342. device : int
  343. channel_id : int
  344. login_time : int
  345. ip : string
  346. }
  347. entity "Game" as G {
  348. *id : int <<PK>>
  349. --
  350. name : string
  351. cooperation_status : int
  352. is_login : int
  353. game_auth_type : string
  354. game_bizid : string
  355. }
  356. entity "Channel" as C {
  357. *id : int <<PK>>
  358. --
  359. name : string
  360. mark : string
  361. level : int
  362. status : int
  363. }
  364. entity "GameBanned" as GB {
  365. *id : int <<PK>>
  366. --
  367. game_id : int <<FK>>
  368. banned_type : string
  369. banned_device : string
  370. }
  371. entity "GameRestrict" as GR {
  372. *id : int <<PK>>
  373. --
  374. game_id : int <<FK>>
  375. restrict_type : string
  376. restrict_status : int
  377. }
  378. entity "MemberDevice" as MD {
  379. *id : int <<PK>>
  380. --
  381. member_id : int <<FK>>
  382. game_id : int <<FK>>
  383. imeil : string
  384. device : int
  385. }
  386. M ||--o{ S : "1:N 子账号"
  387. M ||--o{ MCG : "1:N 游戏绑定"
  388. M ||--o{ LI : "1:N 登录日志"
  389. M ||--o| MT : "1:1 实名信息"
  390. M ||--o{ MD : "1:N 设备记录"
  391. G ||--o{ S : "1:N"
  392. G ||--o{ GB : "1:N 封禁"
  393. G ||--o{ GR : "1:N 防沉迷"
  394. C ||--o{ MCG : "1:N"
  395. @enduml