123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- /*
- * @Descripttion:实名认证
- * @version:
- * @Author: Neo,Huang
- * @Date: 2021-04-17 11:04:16
- * @LastEditors: Neo,Huang
- * @LastEditTime: 2022-07-06 14:32:44
- */
- package nppa
- import (
- "crypto/md5"
- "encoding/hex"
- "encoding/json"
- "fmt"
- "log"
- "net/http"
- "box-3rdServer/utils"
- )
- // 是否开启功能
- func IsModule() bool {
- status := utils.StringToInt(utils.GetKeyConf("nppa", "status"))
- return status > 0
- }
- // 初始化
- func Init() {
- log.Println("nppa:Init")
- initConf()
- mapAidToConf.Range(func(k, v interface{}) bool {
- aid := k.(int)
- key := fmt.Sprintf(aidKey, aid)
- for utils.Zcard(key) > 0 {
- sendCollections(aid, key)
- }
- return true
- })
- ReportCollections()
- // InitRecheckProc()
- }
- // 实名认证 - 校验
- // 方法:get/post
- // 参数:
- //
- // uid:玩家ID
- // channel:渠道
- // name:实名-姓名
- // idNum:实名-身份证ID
- //
- // 返回
- //
- // true/false
- func HttpCheckPlayerID(w http.ResponseWriter, r *http.Request) {
- req := r.URL.Query()
- uid := utils.StringToInt(req.Get("uid"))
- chn := utils.StringToInt(req.Get("channel"))
- name := req.Get("name")
- idNum := req.Get("idNum")
- ret := CheckPlayerId(uid, chn, name, idNum)
- log.Printf("玩家[%d] 实名认证结果[%d] msg[%s]", uid, utils.StringToInt(ret["status"]), ret["msg"])
- pack, _ := json.Marshal(ret)
- // 发送成功
- w.Write(pack)
- }
- // 实名认证 - 查询
- // 方法:get/post
- // 参数:
- //
- // uid:玩家ID
- // channel:渠道
- //
- // 返回
- //
- // ture/false
- func HttpQueryPlayerID(w http.ResponseWriter, r *http.Request) {
- req := r.URL.Query()
- uid := utils.StringToInt(req.Get("uid"))
- chn := utils.StringToInt(req.Get("channel"))
- ret := QueryPlayerId(uid, chn)
- pack, _ := json.Marshal(ret)
- // 发送成功
- w.Write(pack)
- }
- // 实名认证 - 用户行为数据上报
- // 方法:get/post
- // 参数:
- //
- // channel:渠道
- // si:游戏内部会话标识
- // bt:用户行为类型 0:下线 1:上线
- // ot:行为发生时间戳
- // ct:用户行为数据上报类型 0:已认证用户 2:游客
- // di:游客模式设备标识
- // pi:实名用户唯一标识
- func HttpLoginout(w http.ResponseWriter, r *http.Request) {
- req := r.URL.Query()
- channel := req.Get("channel")
- si := req.Get("si")
- bt := utils.StringToInt(req.Get("bt"))
- ot := utils.StringToInt(req.Get("ot"))
- ct := utils.StringToInt(req.Get("ct"))
- di := req.Get("di")
- pi := req.Get("pi")
- ret := make(map[string]interface{})
- ret["code"] = 400
- if channel == "" {
- log.Println("参数错误 channel")
- ret["msg"] = "缺少参数 channel"
- pack, _ := json.Marshal(ret)
- // 发送成功
- w.Write(pack)
- return
- }
- if si == "" {
- log.Println("参数错误 si")
- ret["msg"] = "缺少参数 uid"
- pack, _ := json.Marshal(ret)
- // 发送成功
- w.Write(pack)
- return
- }
- if bt != 0 && bt != 1 {
- log.Println("参数错误 bt")
- ret["msg"] = "参数值错误 bt"
- pack, _ := json.Marshal(ret)
- // 发送成功
- w.Write(pack)
- return
- }
- if ct != 0 && ct != 2 {
- log.Println("参数错误 ct")
- ret["msg"] = "参数值错误 ct"
- pack, _ := json.Marshal(ret)
- // 发送成功
- w.Write(pack)
- return
- }
- if ct == 0 && pi == "" {
- log.Println("参数错误 pi")
- ret["msg"] = "缺少参数 pi"
- pack, _ := json.Marshal(ret)
- // 发送成功
- w.Write(pack)
- return
- }
- if ct == 2 && di == "" {
- log.Println("参数错误 di si:", si)
- ret["msg"] = "缺少参数 di"
- pack, _ := json.Marshal(ret)
- // 发送成功
- w.Write(pack)
- return
- }
- chn := utils.StringToInt(channel)
- v, ok := mapChannelToConf.Load(chn)
- if !ok {
- ret["msg"] = "服务器缺少渠道配置"
- pack, _ := json.Marshal(ret)
- // 发送成功
- w.Write(pack)
- return
- }
- v, ok = mapCollections.Load(v.(*ConfApp).aId)
- if !ok {
- // log.Println(fmt.Sprintf("缺少渠道配置 %d", chn))
- ret["msg"] = "服务器缺少渠道配置"
- pack, _ := json.Marshal(ret)
- // 发送成功
- w.Write(pack)
- return
- }
- go func() {
- if ct == 2 {
- h := md5.Sum([]byte(di))
- di = hex.EncodeToString(h[:])
- }
- v.(*nppaCollections).collection <- &Collection{
- Si: si,
- Bt: bt,
- Ot: ot,
- Ct: ct,
- Di: di,
- Pi: pi,
- }
- }()
- ret["code"] = 200
- ret["msg"] = "成功"
- pack, _ := json.Marshal(ret)
- // 发送成功
- w.Write(pack)
- }
- // 实名认证 - 配置更新
- func HttpUpdateConfig(w http.ResponseWriter, r *http.Request) {
- ConfUpdate()
- ReportCollections()
- }
- // 实名认证 - 测试校验
- func HttpTestCheckPlayerID(w http.ResponseWriter, r *http.Request) {
- req := r.URL.Query()
- testCode := req.Get("testCode")
- uid := req.Get("uid")
- name := req.Get("name")
- idNum := req.Get("idNum")
- ret := TestCheckPlayerId(testCode, uid, name, idNum)
- pack, _ := json.Marshal(ret)
- // 发送成功
- w.Write(pack)
- }
- // 实名认证 - 测试查询结果
- func HttpTestQueryPlayerID(w http.ResponseWriter, r *http.Request) {
- req := r.URL.Query()
- testCode := req.Get("testCode")
- uid := req.Get("uid")
- ret := TestQueryPlayerId(testCode, uid)
- pack, _ := json.Marshal(ret)
- // 发送成功
- w.Write(pack)
- }
- // 实名认证 - 测试数据上报
- func HttpTestLoginout(w http.ResponseWriter, r *http.Request) {
- req := r.URL.Query()
- testCode := req.Get("testCode")
- si := req.Get("si")
- bt := utils.StringToInt(req.Get("bt"))
- ct := utils.StringToInt(req.Get("ct"))
- di := req.Get("di")
- pi := req.Get("pi")
- ret := TestLoginout(testCode, si, bt, ct, di, pi)
- pack, _ := json.Marshal(ret)
- // 发送成功
- w.Write(pack)
- }
|