wangkaiyue преди 6 години
родител
ревизия
3624e73760

+ 9 - 19
src/jfw/modules/app/src/app/front/login.go

@@ -964,6 +964,10 @@ func afterLogin(user map[string]interface{}, session *httpsession.Session, rid,
 			},
 			"$pull": map[string]interface{}{"a_jpushid": rid},
 		})
+		//删除未登录的pushid
+		if rid != "" {
+			jyutil.UnLoginPush.DeleteBuff(rid)
+		}
 	}()
 	user["s_jpushid"] = rid
 	user["s_opushid"] = oid
@@ -1223,32 +1227,18 @@ func (l *Login) ChannelSign() {
 	})
 }
 
+//未登录状态,打开5分钟内没有登录存储推送id
 func (l *Login) SavePushIdMsg() {
 	result := false
 	deviceId := l.GetString("id")
 	phoneType := l.GetString("phoneType")
 	rid := l.GetString("rid")
 	oid := l.GetString("oid")
-	if rid != "" && deviceId != "" {
-		data := map[string]interface{}{
-			"s_rid": rid,
-		}
-		now := time.Now().Unix()
-		if mongodb.Count("jyapp_pushId", data) == 0 {
-			data["i_cometime"] = now
-			data["s_oid"] = oid
-			data["phoneType"] = phoneType
-			data["s_deviceId"] = deviceId
-			data["i_lastTime"] = now
-			mongodb.Save("jyapp_pushId", data)
-		} else {
-			mongodb.Update("jyapp_pushId", data, map[string]interface{}{"$set": map[string]interface{}{
-				"i_lastTime": now,
-			}}, false, true)
-		}
-		result = true
+	if rid != "" && (deviceId != "" || phoneType == "ios") {
+		pd := &jyutil.PushDetail{Rid: rid, Oid: oid, DeviceId: deviceId, PhoneType: phoneType, Createtime: time.Now().Unix()}
+		log.Printf("%+v", pd)
+		result = jyutil.UnLoginPush.SaveBuff(pd)
 	}
-	log.Printf("deviceId:%s phoneType:%s rid:%s oid:%s\n", deviceId, phoneType, rid, oid)
 	l.ServeJson(map[string]interface{}{
 		"success": result,
 	})

+ 78 - 0
src/jfw/modules/app/src/app/jyutil/pushId.go

@@ -0,0 +1,78 @@
+package jyutil
+
+import (
+	"jfw/config"
+	"jfw/public"
+	"log"
+	"qfw/util"
+	"sync"
+	"time"
+)
+
+type PushDetail struct {
+	Rid        string `json:"rid"`
+	Oid        string `json:"oid"`
+	DeviceId   string `json:"deviceId"`
+	PhoneType  string `json:"phoneType"`
+	Createtime int64  `json:"createtime"`
+}
+
+type UnLoginPushManager struct {
+	Lock sync.Mutex
+	Date map[string]*PushDetail
+}
+
+var UnLoginPush *UnLoginPushManager
+var mongodb = public.MQFW
+
+func init() {
+	UnLoginPush = &UnLoginPushManager{Date: make(map[string]*PushDetail)}
+	go UnLoginPush.Work()
+}
+
+func (u *UnLoginPushManager) SaveBuff(p *PushDetail) bool {
+	u.Lock.Lock()
+	defer u.Lock.Unlock()
+	u.Date[p.Rid] = p
+	return true
+}
+
+func (u *UnLoginPushManager) DeleteBuff(rid string) {
+	u.Lock.Lock()
+	defer u.Lock.Unlock()
+	delete(u.Date, rid)
+	log.Printf("DeleteBuff size %d ,this rid:%s\n", len(u.Date), rid)
+}
+
+func (u *UnLoginPushManager) savePushId(p *PushDetail) {
+	data := map[string]interface{}{
+		"s_rid": p.Rid,
+	}
+	if mongodb.Count("jyapp_pushId", data) == 0 {
+		log.Println("save", p.Rid)
+		data["i_cometime"] = p.Createtime
+		data["s_oid"] = p.Oid
+		data["phoneType"] = p.PhoneType
+		data["s_deviceId"] = p.DeviceId
+		data["i_lastTime"] = p.Createtime
+		mongodb.Save("jyapp_pushId", data)
+	} else {
+		log.Println("update", p.Rid)
+		mongodb.Update("jyapp_pushId", data, map[string]interface{}{"$set": map[string]interface{}{
+			"i_lastTime": p.Createtime,
+		}}, false, true)
+	}
+}
+
+func (u *UnLoginPushManager) Work() {
+	u.Lock.Lock()
+	defer u.Lock.Unlock()
+	log.Printf("Work----Buff size %d\n", len(u.Date))
+	for _, v := range u.Date {
+		if v.Createtime+util.Int64All(config.Seoconfig["aftefSavePushId"]) < time.Now().Unix() {
+			u.savePushId(v)
+			delete(u.Date, v.Rid)
+		}
+	}
+	time.AfterFunc(time.Minute, u.Work)
+}

+ 4 - 3
src/jfw/modules/app/src/config.json

@@ -22,7 +22,7 @@
 	},
     "cacheflag": false,
     "agreement": "http",
-    "webdomain": "http://webws.qmx.top",
+    "webdomain": "http://web-jydev-wky.jianyu360.cn",
     "redirect": {
         "wxpushlist": "/jyapp/wxpush/bidinfo/%s",
         "newInfoFollow": "/jyapp/followent/newInfo/%s",
@@ -73,7 +73,7 @@
         "version": "1.0.7",
         "mustupdate": false,
 		"tipspace": 86400,
-		"ios_version": "1.0.3",
+		"ios_version": "2.7.3",
         "ios_mustupdate": false,
         "apkurl": "http://web-jydev-wky.jianyu360.cn/jyapp/res/%s/jianyu360.apk",
         "channelDir":{
@@ -114,5 +114,6 @@
     "appPushServiceRpc": "127.0.0.1:5566",
     "appPower": {
         "grayflag": false
-    }
+    },
+    "aftefSavePushId":60
 }

+ 8 - 5
src/jfw/modules/app/src/web/staticres/jyapp/js/common.js

@@ -68,8 +68,6 @@ $(function(){
 			sendChannelSign();
 		}catch(e){}
 	}
-	//记录推送id
-	savePushIdMsg();
 });
 var EasyAlert = {
 	timeout: null,
@@ -389,6 +387,8 @@ function afterPageInit(){
 			}
 		}
 	});
+	//记录推送id
+	savePushIdMsg();
 }
 function redSpotOnMenu(){
 	$.post("/jyapp/free/showRedSpotOnMenu?t="+new Date().getTime(),null,function(r){
@@ -584,7 +584,7 @@ function sendChannelSign(){
 function savePushIdMsg(){
 	var sign = JyObj.getUserToken();
 	var save = sessionStorage.getItem("savePush")
-	if(sign != ""||save=="1"){
+	if(!(sign == ""||sign==undefined)||save=="1"){
 		sessionStorage.setItem("savePush","1")//每次打开只执行一次
 		return;
 	}
@@ -595,9 +595,12 @@ function savePushIdMsg(){
 			var phoneType=getPhoneType();
 			var rid = JyObj.getPushRid();
 			var oid = getOtherPushId();
-			if (id==""||phoneType==""||rid==""){
-				return
+			if(mySysIsIos()){
+				phoneType="ios"
 			}
+			if(rid==""||rid==undefined){
+				return
+			}	
 			$.post("/jyapp/free/savePushIdMsg",{"id":id,"phoneType":phoneType,"rid":rid,"oid":oid},function(data){
 				if(data.success){
 					clearInterval(interval);