|
@@ -84,7 +84,7 @@ func (m *MiniProgram) AutoLogin() {
|
|
})
|
|
})
|
|
status := m.createSession(jsonPram.Unionid, jsonPram.Openid, miniprogramCode)
|
|
status := m.createSession(jsonPram.Unionid, jsonPram.Openid, miniprogramCode)
|
|
if status == -1 {
|
|
if status == -1 {
|
|
- if m.createUser(jsonPram.Unionid, jsonPram.Openid, miniprogramCode, jsonPram.Phone, "") > 0 {
|
|
|
|
|
|
+ if m.createUser(jsonPram.Unionid, jsonPram.Openid, miniprogramCode, jsonPram.Phone) > 0 {
|
|
status = m.createSession(jsonPram.Unionid, jsonPram.Openid, miniprogramCode)
|
|
status = m.createSession(jsonPram.Unionid, jsonPram.Openid, miniprogramCode)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -121,13 +121,8 @@ func (m *MiniProgram) Login() error {
|
|
return 0
|
|
return 0
|
|
}
|
|
}
|
|
//缓存记录来源来源source
|
|
//缓存记录来源来源source
|
|
- source := m.GetByOpenId(openid)
|
|
|
|
- if source == "" {
|
|
|
|
- source = jsonPram.Source
|
|
|
|
- if source != "" {
|
|
|
|
- //首次记录
|
|
|
|
- m.SetByOpenId(openid, source)
|
|
|
|
- }
|
|
|
|
|
|
+ if jsonPram.Source != "" {
|
|
|
|
+ m.SetSource(openid, jsonPram.Source)
|
|
}
|
|
}
|
|
|
|
|
|
if sessErr := m.Session().SetMultiple(map[string]interface{}{
|
|
if sessErr := m.Session().SetMultiple(map[string]interface{}{
|
|
@@ -171,19 +166,19 @@ func (m *MiniProgram) BindPhone() error {
|
|
sessVal := m.Session().GetMultiple()
|
|
sessVal := m.Session().GetMultiple()
|
|
unionid := common.ObjToString(sessVal["unionid"])
|
|
unionid := common.ObjToString(sessVal["unionid"])
|
|
openid := common.ObjToString(sessVal["openid"])
|
|
openid := common.ObjToString(sessVal["openid"])
|
|
- source := common.ObjToString(sessVal["source"])
|
|
|
|
- if createRes := m.createUser(unionid, openid, jsonPram.MiniProgramInfo.Code, phone, source); createRes > 0 {
|
|
|
|
|
|
+ //source := common.ObjToString(sessVal["source"])
|
|
|
|
+ if createRes := m.createUser(unionid, openid, jsonPram.MiniProgramInfo.Code, phone); createRes > 0 {
|
|
status := m.createSession(unionid, openid, jsonPram.MiniProgramInfo.Code)
|
|
status := m.createSession(unionid, openid, jsonPram.MiniProgramInfo.Code)
|
|
nsqPath, _ := config.Sysconfig["nsq"].(string)
|
|
nsqPath, _ := config.Sysconfig["nsq"].(string)
|
|
- nsq_topic, _ := config.Sysconfig["nsq_topic"].(string)
|
|
|
|
- sessVal := m.Session().GetMultiple()
|
|
|
|
|
|
+ nsqTopic, _ := config.Sysconfig["nsq_topic"].(string)
|
|
|
|
+ sessVal = m.Session().GetMultiple()
|
|
mgoUserId := common.ObjToString(sessVal["mgoUserId"])
|
|
mgoUserId := common.ObjToString(sessVal["mgoUserId"])
|
|
if createRes == 1 {
|
|
if createRes == 1 {
|
|
- if err := jy.Publish(public.Mgo_Log, nsqPath, nsq_topic, jy.Jyapp_phone_register, mgoUserId, jy.Jyapp_node1, nil); err != nil {
|
|
|
|
|
|
+ if err := jy.Publish(public.Mgo_Log, nsqPath, nsqTopic, jy.Jyapp_phone_register, mgoUserId, jy.Jyapp_node1, nil); err != nil {
|
|
log.Println("nsq队列写入失败-->", err, jy.Jyapp_phone_register, mgoUserId)
|
|
log.Println("nsq队列写入失败-->", err, jy.Jyapp_phone_register, mgoUserId)
|
|
}
|
|
}
|
|
} else if createRes == 2 {
|
|
} else if createRes == 2 {
|
|
- if err := jy.Publish(public.Mgo_Log, nsqPath, nsq_topic, "task", mgoUserId, jy.Jyweb_node2, map[string]interface{}{
|
|
|
|
|
|
+ if err := jy.Publish(public.Mgo_Log, nsqPath, nsqTopic, "task", mgoUserId, jy.Jyweb_node2, map[string]interface{}{
|
|
"code": 1007,
|
|
"code": 1007,
|
|
"types": "bindPhone",
|
|
"types": "bindPhone",
|
|
"num": 50,
|
|
"num": 50,
|
|
@@ -252,7 +247,7 @@ func (m *MiniProgram) check(jsonParam *JsonParam) bool {
|
|
return true
|
|
return true
|
|
}
|
|
}
|
|
|
|
|
|
-func (m *MiniProgram) createUser(unionid, openid, miniprogramCode, phone, source string) int {
|
|
|
|
|
|
+func (m *MiniProgram) createUser(unionid, openid, miniprogramCode, phone string) int {
|
|
if phone == "" || unionid == "" || openid == "" {
|
|
if phone == "" || unionid == "" || openid == "" {
|
|
log.Println("phone", phone, "unionid", unionid, "openid", openid, "创建用户失败,缺少phone、unionid、openid")
|
|
log.Println("phone", phone, "unionid", unionid, "openid", openid, "创建用户失败,缺少phone、unionid、openid")
|
|
return 0
|
|
return 0
|
|
@@ -270,10 +265,7 @@ func (m *MiniProgram) createUser(unionid, openid, miniprogramCode, phone, source
|
|
},
|
|
},
|
|
}, `{"s_phone":-1}`, `{"_id":1,"s_phone":1,"s_m_phone":1,"s_unionid":1}`, false, 0, 1)
|
|
}, `{"s_phone":-1}`, `{"_id":1,"s_phone":1,"s_m_phone":1,"s_unionid":1}`, false, 0, 1)
|
|
}
|
|
}
|
|
- _source := m.GetByOpenId(openid)
|
|
|
|
- if _source != "" {
|
|
|
|
- source = _source
|
|
|
|
- }
|
|
|
|
|
|
+ source := m.GetSource(openid)
|
|
nowUnix := gtime.Timestamp()
|
|
nowUnix := gtime.Timestamp()
|
|
if !ok {
|
|
if !ok {
|
|
log.Println(miniprogramCode, unionid, openid, phone, "查询mog库user表失败")
|
|
log.Println(miniprogramCode, unionid, openid, phone, "查询mog库user表失败")
|
|
@@ -366,16 +358,47 @@ func (m *MiniProgram) createSession(unionid, openid, miniprogramCode string) int
|
|
return 1
|
|
return 1
|
|
}
|
|
}
|
|
|
|
|
|
-func (m *MiniProgram) GetByOpenId(openId string) (source string) {
|
|
|
|
- sourceKey := fmt.Sprintf("mini_source_%s", openId)
|
|
|
|
- source = redis.GetStr("limitation", sourceKey)
|
|
|
|
|
|
+var (
|
|
|
|
+ redisCode = "limitation"
|
|
|
|
+ cacheTime = 3600 * 24 * 7
|
|
|
|
+ sourceCacheKey = "mini_source_%s"
|
|
|
|
+ sevenSourceCacheKey = "mini_seven_source_%s"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+func (m *MiniProgram) GetSevenByOpenId(openId string) (source string) {
|
|
|
|
+ source = redis.GetStr(redisCode, fmt.Sprintf(sevenSourceCacheKey, openId))
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-func (m *MiniProgram) SetByOpenId(openId, source string) {
|
|
|
|
- sourceKey := fmt.Sprintf("mini_source_%s", openId)
|
|
|
|
- ok := redis.Put("limitation", sourceKey, source, 3600*24*30)
|
|
|
|
|
|
+func (m *MiniProgram) SetSevenByOpenId(openId, source string) {
|
|
|
|
+ ok := redis.Put(redisCode, fmt.Sprintf(sevenSourceCacheKey, openId), source, cacheTime)
|
|
if !ok {
|
|
if !ok {
|
|
- log.Println("招标网小程序来源缓存存异常")
|
|
|
|
|
|
+ log.Println("招标网小程序来源 7天 缓存存异常")
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (m *MiniProgram) GetSource(openId string) (source string) {
|
|
|
|
+ //七天
|
|
|
|
+ source = m.GetSevenByOpenId(openId)
|
|
|
|
+ if source == "" {
|
|
|
|
+ //永久
|
|
|
|
+ source = redis.GetStr(redisCode, fmt.Sprintf(sourceCacheKey, openId))
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (m *MiniProgram) SetSource(openId, source string) {
|
|
|
|
+ //七天
|
|
|
|
+ sevenSource := m.GetSevenByOpenId(openId)
|
|
|
|
+ if sevenSource == "" {
|
|
|
|
+ m.SetSevenByOpenId(openId, source)
|
|
|
|
+ //永久
|
|
|
|
+ permanentSource := redis.GetStr(redisCode, fmt.Sprintf(sourceCacheKey, openId))
|
|
|
|
+ if permanentSource == "" {
|
|
|
|
+ ok := redis.PutCKV(redisCode, fmt.Sprintf(sourceCacheKey, openId), source)
|
|
|
|
+ if !ok {
|
|
|
|
+ log.Println("招标网小程序首次来源 redis 缓存存异常")
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|