123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- /*
- * @Descripttion:实名认证
- * @version:
- * @Author: Neo,Huang
- * @Date: 2021-04-17 11:04:16
- * @LastEditors: Neo,Huang
- * @LastEditTime: 2022-04-12 20:27:24
- */
- package nppa
- import (
- "bufio"
- "encoding/json"
- "fmt"
- "io"
- "log"
- "os"
- "strconv"
- "strings"
- "time"
- "box-3rdServer/utils"
- "github.com/astaxie/beego"
- "github.com/bitly/go-simplejson"
- "github.com/garyburd/redigo/redis"
- )
- func getNextTime(now time.Time, startTime string) time.Time {
- arr := strings.Split(startTime, ":")
- hour, _ := strconv.Atoi(arr[0])
- min, _ := strconv.Atoi(arr[1])
- next := time.Date(now.Year(), now.Month(), now.Day(), hour, min, 0, 0, now.Location())
- if now.Before(next) {
- return next
- }
- next = now.Add(time.Hour * 24)
- next = time.Date(next.Year(), next.Month(), next.Day(), hour, min, 0, 0, next.Location())
- return next
- }
- // 备份程序初始化
- func InitRecheckProc() {
- title := "存量用户实名认证数据检验"
- timeBackup := utils.GetKeyConf("nppa", "recheck_time")
- if timeBackup == "" {
- // 不开启存量用户同步
- return
- }
- go func() {
- for {
- now := time.Now()
- //返回一个指定时间的下次执行的时间戳
- next := getNextTime(now, timeBackup)
- t := time.NewTimer(next.Sub(now))
- log.Printf("下一次【麻将】 [%s] 开始时间为[%s]", title, next.String())
- <-t.C
- log.Printf("%s--> 神手麻将", title)
- RecheckTimeout()
- }
- }()
- }
- // 存量用户 - 重新校验玩家列表key
- func RecheckDataKey(isAddDay bool) string {
- now := time.Now()
- if isAddDay {
- now = now.Add(time.Hour * 24)
- }
- keyRecheck := fmt.Sprintf("idRecheck:%d%02d%02d", now.Year(), now.Month(), now.Day())
- return keyRecheck
- }
- // 通知游戏服 - 存量用户验证结果
- func UpdatePlayerIdentifyInfo(uid int, m map[string]interface{}) {
- idInfo := utils.GetPlayerInfoFromRedis(uid, utils.GetKeyConf("nppa", "key_id_info"))
- if idInfo == "" {
- idInfo = "{}"
- }
- j, err := simplejson.NewJson([]byte(idInfo))
- if err != nil {
- log.Println("UpdatePlayerIdentifyInfo err:", err)
- return
- }
- if m["status"] == 0 || m["status"] == 1 {
- j.Set("nppaStatus", m["status"])
- j.Set("pi", m["pi"])
- j.Set("jmIDName", m["name"])
- j.Set("jmIDCard", m["idNum"])
- j.Set("lastCheckTime", time.Now().Unix())
- j.Set("award", true)
- } else {
- j.Del("nppaStatus")
- j.Del("birthType")
- j.Del("jmBirthDate")
- j.Del("jmName")
- j.Del("jmIDCard")
- }
- buff, _ := json.Marshal(j)
- idInfo = string(buff)
- utils.SetPlayerInfoFromRedis(uid, utils.GetKeyConf("nppa", "key_id_info"), idInfo)
- }
- // 存量玩家重新实名认证
- func RecheckPlayerId(uid int) {
- // 玩家信息是否已备份
- if !utils.IsPlayerExistInRedis(uid) {
- return
- }
- // 根据项目获取玩家已实名认证数据
- // name:玩家实名认证姓名
- // idNum:玩家实名认证身份证号码
- idInfo := GetJiamiIdInfo(uid)
- if idInfo["name"] == "" || idInfo["idNum"] == "" || idInfo["chn"] == "" {
- return
- }
- ret := NppaCheckPlayerId(utils.StringToInt(idInfo["chn"]), fmt.Sprintf("%032d", uid), idInfo["name"], idInfo["idNum"])
- // log.Printf("RecheckPlayerId uid[%d] ret[%v]", uid, ret)
- keyRecheck := RecheckDataKey(true)
- // 认证中 - 放入重新校验列表
- if ret["code"] == 200 {
- if ret["status"] == 1 {
- utils.Sadd(keyRecheck, utils.IntToString(uid))
- } else {
- ret["name"] = idInfo["name"]
- ret["idNum"] = idInfo["idNum"]
- UpdatePlayerIdentifyInfo(uid, ret)
- }
- }
- }
- // 存量玩家重新实名认证
- func RecheckQueryPlayerId(uid int) {
- // 根据项目获取玩家已实名认证数据
- // name:玩家实名认证姓名
- // idNum:玩家实名认证身份证号码
- idInfo := GetJiamiIdInfo(uid)
- if idInfo["name"] == "" || idInfo["idNum"] == "" || idInfo["chn"] == "" {
- // 旧数据已删除
- return
- }
- ret := NppaQueryPlayerId(fmt.Sprintf("%032d", uid), utils.StringToInt(idInfo["chn"]))
- keyRecheck := RecheckDataKey(true)
- // 失败 - 放入重新校验列表
- if ret["code"] == 200 {
- if ret["status"] == 1 {
- utils.Sadd(keyRecheck, utils.IntToString(uid))
- } else {
- ret["name"] = idInfo["name"]
- ret["idNum"] = idInfo["idNum"]
- UpdatePlayerIdentifyInfo(uid, ret)
- }
- }
- }
- // 获取玩家uid列表 - 文件形式
- func RecheckPlayersFromFile() {
- // 已经跑过文件
- if utils.GetAccountKeyInfo("idRecheck") != "" {
- return
- }
- project := utils.GetConfigPath()
- sFile := fmt.Sprintf("%srecheck_uids.txt", project)
- if beego.AppConfig.String("runmode") == "test" {
- sFile = fmt.Sprintf("%srecheck_uids_test.txt", project)
- }
- // 重新创建
- f, err2 := os.OpenFile(sFile, os.O_CREATE|os.O_RDONLY, 0666)
- if err2 != nil {
- log.Println("打开配置文件失败 ", sFile)
- return
- }
- defer f.Close()
- title := "重新验证玩家实名认证数据"
- log.Printf("开始 - %s - 文件", title)
- buff := bufio.NewReader(f)
- pos := 0
- for {
- // line, err := buff.ReadString('\n')
- line, _, err := buff.ReadLine()
- if err != nil || io.EOF == err {
- break
- }
- // line = strings.TrimSpace(line)
- uid := utils.StringToInt(strings.TrimSpace(string(line)))
- log.Printf("%s uid[%d]", title, uid)
- pos += 1
- if uid >= 1000000 {
- RecheckPlayerId(uid)
- time.Sleep(100 * time.Millisecond)
- }
- }
- utils.SetAccountKeyInfo("idRecheck", time.Now().Format("2006-01-02"))
- log.Printf("结束 - %s - 文件", title)
- }
- // key数据是否存在
- func IsKeyExistInRedis(key string) bool {
- pool := utils.GetAccountRedisPool()
- if pool == nil {
- fmt.Println("get redis pool fail")
- return false
- }
- rd := pool.Get()
- defer rd.Close()
- is_key_exit, _ := redis.Bool(rd.Do("EXISTS", key))
- return is_key_exit
- }
- // 定时器 - 结束
- func RecheckTimeout() {
- keyRecheck := RecheckDataKey(false)
- if IsKeyExistInRedis(keyRecheck) {
- pool := utils.GetAccountRedisPool()
- if pool == nil {
- fmt.Println("get redis pool fail")
- return
- }
- rd := pool.Get()
- defer rd.Close()
- title := "查询结果玩家实名认证数据"
- log.Printf("开始 - %s - 查询结果", title)
- result, _ := redis.Values(rd.Do("smembers", keyRecheck))
- for _, v2 := range result {
- uid := utils.StringToInt(string(v2.([]byte)))
- log.Printf("%s uid[%d]", title, uid)
- RecheckQueryPlayerId(uid)
- time.Sleep(100 * time.Millisecond)
- }
- log.Printf("结束 - %s - 查询结果", title)
- } else {
- RecheckPlayersFromFile()
- }
- }
|