interface.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*
  2. * @Descripttion:实名认证
  3. * @version:
  4. * @Author: Neo,Huang
  5. * @Date: 2021-04-17 11:04:16
  6. * @LastEditors: Neo,Huang
  7. * @LastEditTime: 2022-07-06 14:32:44
  8. */
  9. package nppa
  10. import (
  11. "crypto/md5"
  12. "encoding/hex"
  13. "encoding/json"
  14. "fmt"
  15. "log"
  16. "net/http"
  17. "box-3rdServer/utils"
  18. )
  19. // 是否开启功能
  20. func IsModule() bool {
  21. status := utils.StringToInt(utils.GetKeyConf("nppa", "status"))
  22. return status > 0
  23. }
  24. // 初始化
  25. func Init() {
  26. log.Println("nppa:Init")
  27. initConf()
  28. mapAidToConf.Range(func(k, v interface{}) bool {
  29. aid := k.(int)
  30. key := fmt.Sprintf(aidKey, aid)
  31. for utils.Zcard(key) > 0 {
  32. sendCollections(aid, key)
  33. }
  34. return true
  35. })
  36. ReportCollections()
  37. // InitRecheckProc()
  38. }
  39. // 实名认证 - 校验
  40. // 方法:get/post
  41. // 参数:
  42. //
  43. // uid:玩家ID
  44. // channel:渠道
  45. // name:实名-姓名
  46. // idNum:实名-身份证ID
  47. //
  48. // 返回
  49. //
  50. // true/false
  51. func HttpCheckPlayerID(w http.ResponseWriter, r *http.Request) {
  52. req := r.URL.Query()
  53. uid := utils.StringToInt(req.Get("uid"))
  54. chn := utils.StringToInt(req.Get("channel"))
  55. name := req.Get("name")
  56. idNum := req.Get("idNum")
  57. ret := CheckPlayerId(uid, chn, name, idNum)
  58. log.Printf("玩家[%d] 实名认证结果[%d] msg[%s]", uid, utils.StringToInt(ret["status"]), ret["msg"])
  59. pack, _ := json.Marshal(ret)
  60. // 发送成功
  61. w.Write(pack)
  62. }
  63. // 实名认证 - 查询
  64. // 方法:get/post
  65. // 参数:
  66. //
  67. // uid:玩家ID
  68. // channel:渠道
  69. //
  70. // 返回
  71. //
  72. // ture/false
  73. func HttpQueryPlayerID(w http.ResponseWriter, r *http.Request) {
  74. req := r.URL.Query()
  75. uid := utils.StringToInt(req.Get("uid"))
  76. chn := utils.StringToInt(req.Get("channel"))
  77. ret := QueryPlayerId(uid, chn)
  78. pack, _ := json.Marshal(ret)
  79. // 发送成功
  80. w.Write(pack)
  81. }
  82. // 实名认证 - 用户行为数据上报
  83. // 方法:get/post
  84. // 参数:
  85. //
  86. // channel:渠道
  87. // si:游戏内部会话标识
  88. // bt:用户行为类型 0:下线 1:上线
  89. // ot:行为发生时间戳
  90. // ct:用户行为数据上报类型 0:已认证用户 2:游客
  91. // di:游客模式设备标识
  92. // pi:实名用户唯一标识
  93. func HttpLoginout(w http.ResponseWriter, r *http.Request) {
  94. req := r.URL.Query()
  95. channel := req.Get("channel")
  96. si := req.Get("si")
  97. bt := utils.StringToInt(req.Get("bt"))
  98. ot := utils.StringToInt(req.Get("ot"))
  99. ct := utils.StringToInt(req.Get("ct"))
  100. di := req.Get("di")
  101. pi := req.Get("pi")
  102. ret := make(map[string]interface{})
  103. ret["code"] = 400
  104. if channel == "" {
  105. log.Println("参数错误 channel")
  106. ret["msg"] = "缺少参数 channel"
  107. pack, _ := json.Marshal(ret)
  108. // 发送成功
  109. w.Write(pack)
  110. return
  111. }
  112. if si == "" {
  113. log.Println("参数错误 si")
  114. ret["msg"] = "缺少参数 uid"
  115. pack, _ := json.Marshal(ret)
  116. // 发送成功
  117. w.Write(pack)
  118. return
  119. }
  120. if bt != 0 && bt != 1 {
  121. log.Println("参数错误 bt")
  122. ret["msg"] = "参数值错误 bt"
  123. pack, _ := json.Marshal(ret)
  124. // 发送成功
  125. w.Write(pack)
  126. return
  127. }
  128. if ct != 0 && ct != 2 {
  129. log.Println("参数错误 ct")
  130. ret["msg"] = "参数值错误 ct"
  131. pack, _ := json.Marshal(ret)
  132. // 发送成功
  133. w.Write(pack)
  134. return
  135. }
  136. if ct == 0 && pi == "" {
  137. log.Println("参数错误 pi")
  138. ret["msg"] = "缺少参数 pi"
  139. pack, _ := json.Marshal(ret)
  140. // 发送成功
  141. w.Write(pack)
  142. return
  143. }
  144. if ct == 2 && di == "" {
  145. log.Println("参数错误 di si:", si)
  146. ret["msg"] = "缺少参数 di"
  147. pack, _ := json.Marshal(ret)
  148. // 发送成功
  149. w.Write(pack)
  150. return
  151. }
  152. chn := utils.StringToInt(channel)
  153. v, ok := mapChannelToConf.Load(chn)
  154. if !ok {
  155. ret["msg"] = "服务器缺少渠道配置"
  156. pack, _ := json.Marshal(ret)
  157. // 发送成功
  158. w.Write(pack)
  159. return
  160. }
  161. v, ok = mapCollections.Load(v.(*ConfApp).aId)
  162. if !ok {
  163. // log.Println(fmt.Sprintf("缺少渠道配置 %d", chn))
  164. ret["msg"] = "服务器缺少渠道配置"
  165. pack, _ := json.Marshal(ret)
  166. // 发送成功
  167. w.Write(pack)
  168. return
  169. }
  170. go func() {
  171. if ct == 2 {
  172. h := md5.Sum([]byte(di))
  173. di = hex.EncodeToString(h[:])
  174. }
  175. v.(*nppaCollections).collection <- &Collection{
  176. Si: si,
  177. Bt: bt,
  178. Ot: ot,
  179. Ct: ct,
  180. Di: di,
  181. Pi: pi,
  182. }
  183. }()
  184. ret["code"] = 200
  185. ret["msg"] = "成功"
  186. pack, _ := json.Marshal(ret)
  187. // 发送成功
  188. w.Write(pack)
  189. }
  190. // 实名认证 - 配置更新
  191. func HttpUpdateConfig(w http.ResponseWriter, r *http.Request) {
  192. ConfUpdate()
  193. ReportCollections()
  194. }
  195. // 实名认证 - 测试校验
  196. func HttpTestCheckPlayerID(w http.ResponseWriter, r *http.Request) {
  197. req := r.URL.Query()
  198. testCode := req.Get("testCode")
  199. uid := req.Get("uid")
  200. name := req.Get("name")
  201. idNum := req.Get("idNum")
  202. ret := TestCheckPlayerId(testCode, uid, name, idNum)
  203. pack, _ := json.Marshal(ret)
  204. // 发送成功
  205. w.Write(pack)
  206. }
  207. // 实名认证 - 测试查询结果
  208. func HttpTestQueryPlayerID(w http.ResponseWriter, r *http.Request) {
  209. req := r.URL.Query()
  210. testCode := req.Get("testCode")
  211. uid := req.Get("uid")
  212. ret := TestQueryPlayerId(testCode, uid)
  213. pack, _ := json.Marshal(ret)
  214. // 发送成功
  215. w.Write(pack)
  216. }
  217. // 实名认证 - 测试数据上报
  218. func HttpTestLoginout(w http.ResponseWriter, r *http.Request) {
  219. req := r.URL.Query()
  220. testCode := req.Get("testCode")
  221. si := req.Get("si")
  222. bt := utils.StringToInt(req.Get("bt"))
  223. ct := utils.StringToInt(req.Get("ct"))
  224. di := req.Get("di")
  225. pi := req.Get("pi")
  226. ret := TestLoginout(testCode, si, bt, ct, di, pi)
  227. pack, _ := json.Marshal(ret)
  228. // 发送成功
  229. w.Write(pack)
  230. }