wangchuanjin преди 7 години
родител
ревизия
db3327b05e

+ 11 - 0
src/jfw/front/front.go

@@ -397,6 +397,17 @@ func (f *Front) AjaxPolling() {
 			reply = "qrToLab_ok_open_ok"
 		}
 		f.ServeJson(map[string]string{"result": reply})
+	} else if reqType == 4 {
+		openid, _ := f.GetSession("s_m_openid").(string)
+		ok := false
+		if openid != "" {
+			key := fmt.Sprintf("pcbiddetail_shareTimeline_%s", openid)
+			ok, _ = redis.Exists("other", key)
+			if ok {
+				redis.Del("other", key)
+			}
+		}
+		f.ServeJson(map[string]interface{}{"result": ok})
 	}
 }
 

+ 101 - 101
src/jfw/front/shorturl.go

@@ -31,9 +31,9 @@ func init() {
 
 type Short struct {
 	*xweb.Action
-	article xweb.Mapper `xweb:"/article/(\\w+)/(.*).html"` //([pm])
-	qr      xweb.Mapper `xweb:"/biddetail/(\\w+)/qr/(.+)"`
-	updateShareStatus      xweb.Mapper `xweb:"/share/updateShareStatus"`
+	article           xweb.Mapper `xweb:"/article/(\\w+)/(.*).html"` //([pm])
+	qr                xweb.Mapper `xweb:"/biddetail/(\\w+)/qr/(.+)"`
+	updateShareStatus xweb.Mapper `xweb:"/share/updateShareStatus"`
 }
 
 var mobileReg = regexp.MustCompile("(?i)(Android|Mobile|Phone)")
@@ -176,7 +176,7 @@ func (s *Short) Article(stype, id string) error {
 				}
 			}
 			//
-			s.T["forceShareFlag"] = CheckUserNeedForceShare(ssOpenid.(string),shareType_detail)
+			s.T["forceShareFlag"] = CheckUserNeedForceShare(ssOpenid.(string), shareType_detail)
 			content, _ := s.Render4Cache("/weixin/wxinfocontent"+rec+".html", &s.T)
 			//	redis.Put("other", "jywxdetail_"+sid+kds, string(content), 60*60*2)
 			return s.SetBody(content)
@@ -186,39 +186,40 @@ func (s *Short) Article(stype, id string) error {
 			return s.Redirect(surl)
 		}
 	} else {
-		isForceShare := false
-		if stype == "content" {
-			//判断是否需要强制分享
-			isForceShare = true
-		}
-		s.T["isForceShare"] = isForceShare
 		sids := util.CommonDecodeArticle(stype, id)
 		if len(sids) == 0 {
 			s.Redirect("/notin/page", 302)
 			return nil
 		}
+		isForceShare := false
 		sid := sids[0]
 		//log.Println("sid", sid)
-		kds := s.GetString("kds")
-		industry := s.GetString("industry")
 		var rec = ""
-		if !isForceShare && ssOpenid != nil && ssOpenid != "" {
-			if redis.Get("recovery", "rec-"+ssOpenid.(string)) != nil {
-				rec = "_rec"
+		if ssOpenid != nil && ssOpenid != "" {
+			if stype == "content" {
+				//判断是否需要强制分享
+				isForceShare = CheckUserNeedForceShare(ssOpenid.(string), shareType_detail)
+			}
+			if !isForceShare {
+				if redis.Get("recovery", "rec-"+ssOpenid.(string)) != nil {
+					rec = "_rec"
+				}
 			}
 		}
 		var res interface{}
 		if !isForceShare {
 			res = redis.Get("other", "jypcdetail_"+rec+sid)
 		}
-		var shareid = s.GetString("id")
-		if len(shareid) == 0 {
-			shareid = "10"
-		}
-		s.T["logid"] = config.Seoconfig["jysskzy"].(string)
-		s.T["shareid"] = se.EncodeString(shareid)
 		if res == nil || res == "" {
-			s.T["keywords"] = kds
+			industry := s.GetString("industry")
+			var shareid = s.GetString("id")
+			if len(shareid) == 0 {
+				shareid = "10"
+			}
+			s.T["isForceShare"] = isForceShare
+			s.T["logid"] = config.Seoconfig["jysskzy"].(string)
+			s.T["shareid"] = se.EncodeString(shareid)
+			s.T["keywords"] = s.GetString("kds")
 			s.DisableHttpCache()
 			po, bo, wo, obj := pcVRT(sid, industry)
 			if obj != nil && len(obj) > 0 {
@@ -297,11 +298,11 @@ func CheckUserIsSubscribe(openid string) bool {
 //20180831
 const (
 	shareType_detail = 1 //分享类型 1-详情页
-	shareType_push = 2 //2-推送列表
-	shareType_lab = 3 //3-实验室
+	shareType_push   = 2 //2-推送列表
+	shareType_lab    = 3 //3-实验室
 
 	shareProperty_passive = 1 // 1-被动分享
-	shareProperty_active = 2 // 2-主动分享
+	shareProperty_active  = 2 // 2-主动分享
 
 	prefix_shareTimes = "shareTimes_" //redis 分享次数上限前缀
 
@@ -309,27 +310,27 @@ const (
 )
 
 /**
-	判断是否需要强制分享
+判断是否需要强制分享
 
-	return - true-需要强制分享 false-不需强制分享
- */
-func CheckNeedShared(stl1,stl2 ,stlt1 ,stlt2 interface{}) bool {
+return - true-需要强制分享 false-不需强制分享
+*/
+func CheckNeedShared(stl1, stl2, stlt1, stlt2 interface{}) bool {
 	reFlag := false
 	var shareTimeLine int
 	var shareTimeLineTime int
 	shareIntervalDays := int((config.Sysconfig["share"].(map[string]interface{}))["shareIntervalDays"].(float64))
 	if stl1 != nil && stlt1 != nil && stl2 != nil && stlt2 != nil {
-		if stl1.(int) == shareProperty_passive  && stl2.(int) == shareProperty_passive {
-			if stlt1.(int)-stlt2.(int) > 0{
+		if stl1.(int) == shareProperty_passive && stl2.(int) == shareProperty_passive {
+			if stlt1.(int)-stlt2.(int) > 0 {
 				shareTimeLineTime = stlt1.(int)
-			}else{
+			} else {
 				shareTimeLineTime = stlt2.(int)
 			}
-		}else if stl1.(int) == shareProperty_passive {
+		} else if stl1.(int) == shareProperty_passive {
 			shareTimeLineTime = stlt1.(int)
-		}else if stl2.(int) == shareProperty_passive {
+		} else if stl2.(int) == shareProperty_passive {
 			shareTimeLineTime = stlt2.(int)
-		}else {
+		} else {
 			reFlag = true
 		}
 		if shareTimeLineTime != 0 {
@@ -338,9 +339,9 @@ func CheckNeedShared(stl1,stl2 ,stlt1 ,stlt2 interface{}) bool {
 				reFlag = true
 			}
 		}
-	}else if stl1 != nil && stlt1 != nil{
+	} else if stl1 != nil && stlt1 != nil {
 		shareTimeLine = stl1.(int)
-		if shareTimeLine == shareProperty_passive{
+		if shareTimeLine == shareProperty_passive {
 			shareTimeLineTime = stlt1.(int)
 			interval := GetIntervalDayFromLastToNow(shareTimeLineTime)
 			if interval > shareIntervalDays {
@@ -349,9 +350,9 @@ func CheckNeedShared(stl1,stl2 ,stlt1 ,stlt2 interface{}) bool {
 		} else {
 			reFlag = true
 		}
-	}else if stl2 != nil && stlt2 != nil{
+	} else if stl2 != nil && stlt2 != nil {
 		shareTimeLine = stl2.(int)
-		if shareTimeLine == shareProperty_passive{
+		if shareTimeLine == shareProperty_passive {
 			shareTimeLineTime = stlt2.(int)
 			interval := GetIntervalDayFromLastToNow(shareTimeLineTime)
 			if interval > shareIntervalDays {
@@ -360,7 +361,7 @@ func CheckNeedShared(stl1,stl2 ,stlt1 ,stlt2 interface{}) bool {
 		} else {
 			reFlag = true
 		}
-	}else {
+	} else {
 		reFlag = true
 	}
 	return reFlag
@@ -368,19 +369,19 @@ func CheckNeedShared(stl1,stl2 ,stlt1 ,stlt2 interface{}) bool {
 
 //当前时间距上个时间的间隔天数
 func GetIntervalDayFromLastToNow(lasttime int) int {
-	return (int(time.Now().Unix())-lasttime)/(60*60*24)
+	return (int(time.Now().Unix()) - lasttime) / (60 * 60 * 24)
 }
 
 /**
-	判断用户是否需要强制分享
+判断用户是否需要强制分享
 
-	opentid - 用户openid
-	shareType - 分享类型 1-详情页 2-推送列表 3-实验室
-	return - true-需强制分享 false-不需强制分享
- */
-func CheckUserNeedForceShare(openid string,shareType int) bool {
-	log.Println("----------","判断用户是否需要强制分享start",openid,"shareType:",shareType,"----------")
-	userInfo,ok := mongodb.FindOne("user",map[string]interface{}{
+opentid - 用户openid
+shareType - 分享类型 1-详情页 2-推送列表 3-实验室
+return - true-需强制分享 false-不需强制分享
+*/
+func CheckUserNeedForceShare(openid string, shareType int) bool {
+	log.Println("----------", "判断用户是否需要强制分享start", openid, "shareType:", shareType, "----------")
+	userInfo, ok := mongodb.FindOne("user", map[string]interface{}{
 		"s_m_openid": openid,
 	})
 	shareConfigMap := config.Sysconfig["share"].(map[string]interface{})
@@ -389,128 +390,128 @@ func CheckUserNeedForceShare(openid string,shareType int) bool {
 		isNewUserFlag := false
 		if shareType == shareType_detail {
 			//是否为新用户-详情页分享
-			if (*userInfo)["l_registedate"] !=nil {
+			if (*userInfo)["l_registedate"] != nil {
 				regDate := (*userInfo)["l_registedate"].(int64)
 				onlineDate := shareConfigMap["onlineDate"].(string)
 				regDaysForNewUser := int(shareConfigMap["regDaysForNewUser"].(float64))
-				onlineTime,_ := time.ParseInLocation("2006-01-02 15:04:05",onlineDate,time.Local)
+				onlineTime, _ := time.ParseInLocation("2006-01-02 15:04:05", onlineDate, time.Local)
 				onlineTimeI := onlineTime.Unix()
 				interval := GetIntervalDayFromLastToNow(int(regDate))
-				log.Println("----------",openid,"userRegisterDays:",interval,regDate,onlineTimeI,"----------")
-				if regDate - onlineTimeI > 0 && interval >= regDaysForNewUser{
+				log.Println("----------", openid, "userRegisterDays:", interval, regDate, onlineTimeI, "----------")
+				if regDate-onlineTimeI > 0 && interval >= regDaysForNewUser {
 					isNewUserFlag = true
-				}else {
+				} else {
 					isNewUserFlag = false
 				}
 			}
 		}
-		log.Println("----------",openid,"isNewUserFlag:",isNewUserFlag,"----------")
+		log.Println("----------", openid, "isNewUserFlag:", isNewUserFlag, "----------")
 		// 1.详情页-只新用户,需强制分享(分享次数未达上限 && 未分享)
 		// 2.推送消息、实验室-不区分新老用户,均需强制分享(分享次数未达上限 && 未分享)
-		if ( shareType == shareType_detail && isNewUserFlag ) || shareType == shareType_push || shareType == shareType_lab {
+		if (shareType == shareType_detail && isNewUserFlag) || shareType == shareType_push || shareType == shareType_lab {
 			//分享次数是否超过上限
-			hour,_,_ := time.Now().Clock()
+			hour, _, _ := time.Now().Clock()
 			startHour := int(shareConfigMap["startHour"].(float64))
 			endHour := int(shareConfigMap["endHour"].(float64))
-			shareTimesUpperLimitR := int(shareConfigMap["shareTimesUpperLimitR"].(float64))/(endHour - startHour)
+			shareTimesUpperLimitR := int(shareConfigMap["shareTimesUpperLimitR"].(float64)) / (endHour - startHour)
 			shareTimesUpperLimitIrr := int(shareConfigMap["shareTimesUpperLimitIrr"].(float64))
 			reachedUpperLimitFlag := false
-			if hour >=startHour && hour <= endHour {
-				shareTimes := redis.GetInt(redisPoolCode,prefix_shareTimes + time.Now().Format("2006010215"))
-				log.Println("----------",openid,"redis-shareTimes_",time.Now().Format("2006010215"),shareTimes,"----------")
+			if hour >= startHour && hour <= endHour {
+				shareTimes := redis.GetInt(redisPoolCode, prefix_shareTimes+time.Now().Format("2006010215"))
+				log.Println("----------", openid, "redis-shareTimes_", time.Now().Format("2006010215"), shareTimes, "----------")
 				if shareTimes >= shareTimesUpperLimitR {
 					reachedUpperLimitFlag = true
 				}
-			}else {
-				shareTimes := redis.GetInt(redisPoolCode,prefix_shareTimes + time.Now().Format("20060102"))
-				log.Println("----------",openid,"redis-shareTimes_",time.Now().Format("20060102"),shareTimes,"----------")
+			} else {
+				shareTimes := redis.GetInt(redisPoolCode, prefix_shareTimes+time.Now().Format("20060102"))
+				log.Println("----------", openid, "redis-shareTimes_", time.Now().Format("20060102"), shareTimes, "----------")
 				if shareTimes >= shareTimesUpperLimitIrr {
 					reachedUpperLimitFlag = true
 				}
 			}
-			log.Println("----------",openid,"reachedUpperLimitFlag:",reachedUpperLimitFlag,"----------")
+			log.Println("----------", openid, "reachedUpperLimitFlag:", reachedUpperLimitFlag, "----------")
 			//分享次数未超上限,判断是否已分享
 			if !reachedUpperLimitFlag {
 				//是否已分享
 				sharedFlag := false
-				detailSTL := (*userInfo)["i_detailsharetimeline"]//公告详情页分享标志
-				pushSTL := (*userInfo)["i_pushsharetimeline"]//推送列表分享标志
-				labSTL := (*userInfo)["i_labsharetimeline"]//实验室分享标志
+				detailSTL := (*userInfo)["i_detailsharetimeline"] //公告详情页分享标志
+				pushSTL := (*userInfo)["i_pushsharetimeline"]     //推送列表分享标志
+				labSTL := (*userInfo)["i_labsharetimeline"]       //实验室分享标志
 				var shareTimeLine interface{}
-				if shareType == shareType_detail{
+				if shareType == shareType_detail {
 					shareTimeLine = detailSTL
-				}else if shareType == shareType_push{
+				} else if shareType == shareType_push {
 					shareTimeLine = pushSTL
-				}else if shareType == shareType_lab{
+				} else if shareType == shareType_lab {
 					shareTimeLine = labSTL
 				}
-				if shareTimeLine != nil && (shareTimeLine.(int64) == shareProperty_passive || shareTimeLine.(int64) == shareProperty_active){
+				if shareTimeLine != nil && (shareTimeLine.(int64) == shareProperty_passive || shareTimeLine.(int64) == shareProperty_active) {
 					sharedFlag = true
 				}
-				log.Println("----------",openid,"sharedFlag:",sharedFlag,"----------")
+				log.Println("----------", openid, "sharedFlag:", sharedFlag, "----------")
 				//未分享时,判断是否需强制分享
 				if !sharedFlag {
 					detailSTLT := (*userInfo)["i_detailsharetimelinetime"]
 					pushSTLT := (*userInfo)["i_pushsharetimelinetime"]
 					labSTLT := (*userInfo)["i_labsharetimelinetime"]
-					if shareType == shareType_detail{
-						needForceShareFlag = CheckNeedShared(pushSTL,labSTL,pushSTLT,labSTLT)
-					}else if shareType == shareType_push{
-						needForceShareFlag = CheckNeedShared(detailSTL,labSTL,detailSTLT,labSTLT)
-					}else if shareType == shareType_lab{
-						needForceShareFlag = CheckNeedShared(detailSTL,pushSTL,detailSTLT,pushSTLT)
+					if shareType == shareType_detail {
+						needForceShareFlag = CheckNeedShared(pushSTL, labSTL, pushSTLT, labSTLT)
+					} else if shareType == shareType_push {
+						needForceShareFlag = CheckNeedShared(detailSTL, labSTL, detailSTLT, labSTLT)
+					} else if shareType == shareType_lab {
+						needForceShareFlag = CheckNeedShared(detailSTL, pushSTL, detailSTLT, pushSTLT)
 					}
 				}
 			}
 		}
 	}
-	log.Println("----------",openid,"needForceShareFlag:",needForceShareFlag,"----------")
-	log.Println("----------","判断用户是否需要强制分享end",openid,"----------")
+	log.Println("----------", openid, "needForceShareFlag:", needForceShareFlag, "----------")
+	log.Println("----------", "判断用户是否需要强制分享end", openid, "----------")
 	return needForceShareFlag
 }
 
 /**
-	成功分享后 保存分享相关信息
+成功分享后 保存分享相关信息
 
-	shareType - 分享类型 1-详情页 2-推送列表 3-实验室
-	shareProperty - 分享性质 1-被动分享 2-主动分享
- */
+shareType - 分享类型 1-详情页 2-推送列表 3-实验室
+shareProperty - 分享性质 1-被动分享 2-主动分享
+*/
 func (s *Short) UpdateShareStatus() error {
 	openId := s.Session().Get("s_m_openid")
-	shareType,_ := s.GetInt("shareType")
-	shareProperty,_ := s.GetInt("shareProperty")
-	if openId != nil && shareType != 0  && shareProperty != 0 {
+	shareType, _ := s.GetInt("shareType")
+	shareProperty, _ := s.GetInt("shareProperty")
+	if openId != nil && shareType != 0 && shareProperty != 0 {
 		queryM := map[string]interface{}{
 			"s_m_openid": openId.(string),
 		}
 		setM := map[string]interface{}{}
 		now := time.Now()
-		if shareType == shareType_detail{
+		if shareType == shareType_detail {
 			setM["i_detailsharetimeline"] = shareProperty
 			setM["i_detailsharetimelinetime"] = now.Unix()
-			isforceshare,_ := s.GetInt("isforceshare")
+			isforceshare, _ := s.GetInt("isforceshare")
 			if isforceshare == 1 {
-				redis.Put(redisPoolCode,"pcbiddetail_shareTimeline_"+openId.(string),1,60)
+				redis.Put(redisPoolCode, "pcbiddetail_shareTimeline_"+openId.(string), 1, 60)
 			}
-		}else if shareType == shareType_push{
+		} else if shareType == shareType_push {
 			setM["i_pushsharetimeline"] = shareProperty
 			setM["i_pushsharetimelinetime"] = now.Unix()
-		}else if shareType == shareType_lab{
+		} else if shareType == shareType_lab {
 			setM["i_labsharetimeline"] = shareProperty
 			setM["i_labsharetimelinetime"] = now.Unix()
 		}
-		flag := mongodb.Update("user",queryM,map[string]interface{}{
+		flag := mongodb.Update("user", queryM, map[string]interface{}{
 			"$set": setM,
-		},false,false)
+		}, false, false)
 		if flag {
-			hour,_,_ := now.Clock()
+			hour, _, _ := now.Clock()
 			shareConfigMap := config.Sysconfig["share"].(map[string]interface{})
 			startHour := int(shareConfigMap["startHour"].(float64))
 			endHour := int(shareConfigMap["endHour"].(float64))
-			if hour >=startHour && hour <= endHour {
-				redis.Incr(redisPoolCode,prefix_shareTimes + now.Format("2006010215"))
-			}else {
-				redis.Incr(redisPoolCode,prefix_shareTimes + now.Format("20060102"))
+			if hour >= startHour && hour <= endHour {
+				redis.Incr(redisPoolCode, prefix_shareTimes+now.Format("2006010215"))
+			} else {
+				redis.Incr(redisPoolCode, prefix_shareTimes+now.Format("20060102"))
 			}
 		}
 	}
@@ -533,4 +534,3 @@ func (s *Short) Qr(t, id string) error {
 	_, err := w.Write(pngdat)
 	return err
 }
-

+ 55 - 0
src/jfw/front/websocket.go

@@ -261,3 +261,58 @@ func QrToLabWss(conn *websocket.Conn) {
 		}
 	}
 }
+
+//电脑端强制分享,扫码分享到朋友圈
+func QrToShareTimeline(conn *websocket.Conn) {
+	defer qutil.Catch()
+	var receive string
+	//接收消息
+	sess := xweb.RootApp().SessionManager.Session(conn.R, conn.W)
+	openid, _ := sess.Get("s_m_openid").(string)
+	key := ""
+	if openid != "" {
+		key = fmt.Sprintf("pcbiddetail_shareTimeline_%s", openid)
+	}
+	go func() {
+		defer qutil.Catch()
+		for {
+			err := websocket.Message.Receive(conn, &receive)
+			if err != nil {
+				receive = "close"
+				//log.Println("websocket接收失败!", err)
+				return
+			}
+			if receive == "close" { //关闭
+				return
+			} else if receive == "HeartBeat" { //心跳监测
+				websocket.Message.Send(conn, "HeartBeat")
+			}
+		}
+	}()
+	//发送消息
+	for {
+		time.Sleep(2 * time.Second)
+		if receive == "close" { //接收到关闭信息
+			conn.Close()
+			return
+		}
+		reply := "n"
+		if key != "" {
+			ok, _ := redis.Exists("other", key)
+			if ok {
+				reply = "y"
+			}
+		}
+		if err := websocket.Message.Send(conn, reply); err != nil {
+			redis.Del("other", key)
+			//log.Println("websocket发送失败!", err)
+			conn.Close()
+			return
+		}
+		if reply == "y" {
+			redis.Del("other", key)
+			conn.Close()
+			return
+		}
+	}
+}

+ 1 - 0
src/main.go

@@ -79,6 +79,7 @@ func main() {
 		mux1.Handle("/ws", websocket.Handler(front.ServeWss))
 		//mux1.HandleFunc("/ws", front.ServeWss)
 		mux1.Handle("/qrToLab", websocket.Handler(front.QrToLabWss))
+		mux1.Handle("/webscoket/qrToShareTimeline", websocket.Handler(front.QrToShareTimeline))
 		//mux1.HandleFunc("/qrToLab", front.QrToLabWss)
 		xweb.RunBase(":"+Sysconfig["webport"].(string), mux1)
 		//xweb.Run(":" + Sysconfig["webport"].(string))

+ 175 - 91
src/web/staticres/js/jyWebScoket.js

@@ -1,13 +1,15 @@
-var qrToLabWSHC = new WebSocketHeartCheck("qrToLab");
-//webScoket封装
+var isIE9=false;
+if(navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.match(/[6789]./i)) { 
+	isIE9=true
+}
 var JyWebScoket = {
-	url: "ws"+(!bIE9&&"https:"==document.location.protocol?"s":"")+"://"+window.location.host,
+	url: "ws"+(!isIE9&&"https:"==document.location.protocol?"s":"")+"://"+window.location.host,
 	//pc端扫码进入实验室之后,自动关闭二维码,页面刷新
 	qrToLab: function() {
 		var thisClass = this;
-		var sock = null;
 		var isCanClolse = true;
 		var type = "s";
+		var cws = null;
 		//二维码关闭之后,关闭socket连接
 		$("#labModal").on('show.bs.modal', function (e) {
 			if(typeof(qr_type) != "undefined"){
@@ -16,110 +18,191 @@ var JyWebScoket = {
 			if(!$("#labImg").attr("src")){
 				$("#labImg").attr("src","/jylab/supsearch/qr/"+type);
 			}
-			//开始轮询
-			QrToLabPolling.start(thisClass,encryptId);
 			//打开scoket连接,监听扫码完成之后,页面刷新
-			thisClass.init(encryptId);
+			cws = new CommonWebScoket(JyWebScoket.url+"/qrToLab",encryptId,thisClass).init();
 		});
 		$("#labModal").on('hide.bs.modal', function (e) {
-			if(isCanClolse){
-				thisClass.close();
-			}
-		});
-		//初始化scoket连接
-		this.sendmsg = "";
-		this.isOver = false;
-		this.init = function(msg){
-			var thisClass = this;
-			this.sendmsg = msg;
-			if(window.WebSocket == undefined) {
-				//console.error("浏览器不支持webscoket!");
+			isCanClolse&&cws.close();
+		}); 
+		this.complete = function(result,flag){
+			cws.wshc.reset();
+			cws.isOver = true;
+			if(result == "qrToLab_ok"){
+				if(flag){
+					WSpolling.stop();
+				}
+				isCanClolse = false;
+				$("#labModal").modal("hide");
 				return
+			}else if(result == "qrToLab_open_ok"){
+				$(".superSearch").remove();
+				cws.close();
+			}else if(result == "qrToLab_ok_open_ok"){
+				isCanClolse = false;
+				$("#labModal").modal("hide");
+				$(".superSearch").remove();
+				cws.close();
 			}
+			WSpolling.stop();
+		}
+		this.ajaxReq = function(){
+			$.ajax({
+				type: "POST",
+				url: "/front/ajaxPolling",
+				data: {userId: encryptId,reqType:3},
+				dataType: "json",
+				timeout: 3000,
+				success: function(r){
+					if(r.result != ""){
+						thisClass.complete(r.result,false);
+					}
+				}
+			});
+		}
+	},
+	qrToShareTimeline: function() {
+		var thisClass = this;
+		var cws = new CommonWebScoket(JyWebScoket.url+"/webscoket/qrToShareTimeline","",this).init();
+		this.complete = function(result,flag){
+			if(result == "y"){
+				cws.over();
+				window.location.reload();
+			}
+		}
+		this.ajaxReq = function(){
+			$.ajax({
+				type: "POST",
+				url: "/front/ajaxPolling",
+				data: {reqType:4},
+				dataType: "json",
+				timeout: 3000,
+				success: function(r){
+					if(r.result){
+						thisClass.complete("y",false);
+					}
+				}
+			});
+		}
+	}
+}
+var CommonWebScoket = function(url,param,obj){
+	var thisClass = this;
+	this.sock = null;
+	this.wshc = new WebSocketHeartCheck();
+	this.isOver = false;
+	//开始轮询
+	WSpolling.start(obj);
+	this.init = function(){
+		if(window.WebSocket == undefined) {
+			//console.error("浏览器不支持webscoket!");
+		}else{
 			try{
-				sock = new WebSocket(JyWebScoket.url+"/qrToLab");
-			    sock.onopen = function() {
-					//console.log("connection success!"+msg);
-					sock.send(msg);
+				this.sock = new WebSocket(url);
+			    this.sock.onopen = function() {
+					//console.log("connection success!"+param);
+					thisClass.sock.send(param);
 					//心跳检测重置
-        			qrToLabWSHC.reset().start(sock,false);
+		      		thisClass.wshc.reset().start(thisClass.sock,false);
 			    }
-				sock.onerror = function(e){
+				this.sock.onerror = function(e){
 					//console.info("onerror");
 					thisClass.reconnect();
 				}
-			    sock.onclose = function(e) {
+			    this.sock.onclose = function(e) {
 			        //console.info("onclose");
 					thisClass.reconnect();
 			    }
-			    sock.onmessage = function(e) {
-					QrToLabPolling.isPostLoginPolling = false;
+			    this.sock.onmessage = function(e) {
+					WSpolling.isPostLoginPolling = false;
 					if(e.data=="HeartBeat"){//心跳检测
 						//如果获取到消息,心跳检测重置
 				        //拿到任何消息都说明当前连接是正常的
-				        qrToLabWSHC.reset().start(sock,false);
+				        thisClass.wshc.reset().start(thisClass.sock,false);
 						return;
 					}
-					thisClass.complete(e.data,true);
+					obj.complete(e.data,true);
 			    }
 			}catch(e){
 				//console.error("JyWebScoket "+e);
-				thisClass.reconnect();
+				this.reconnect();
 			}
 		}
-		this.complete = function(result,flag){
-			qrToLabWSHC.reset();
-			this.isOver = true;
-			if(result == "qrToLab_ok"){
-				if(flag){
-					QrToLabPolling.stop();
-				}
-				isCanClolse = false;
-				$("#labModal").modal("hide");
-				return
-			}else if(result == "qrToLab_open_ok"){
-				$(".superSearch").remove();
-				this.close();
-			}else if(result == "qrToLab_ok_open_ok"){
-				isCanClolse = false;
-				$("#labModal").modal("hide");
-				$(".superSearch").remove();
-				this.close();
-			}
-			QrToLabPolling.stop();
+		return this;
+	}
+	this.reconnect = function() {
+		if(this.wshc.lockReconnect || this.isOver){
+			return;
 		}
-		this.close = function(){
-			if(sock == null){
-				return;
-			}
-			try{
-				sock.send("close");
-				sock.close();
-				sock = null;
-			}catch(e){
-				//console.error("JyWebScoket "+e);
-			}
+		WSpolling.isPostLoginPolling = true;
+	    this.wshc.lockReconnect = true;
+	    //没连接上会一直重连,设置延迟避免请求过多
+		var thisClass = this;
+	    setTimeout(function () {
+	        thisClass.init(param);
+			thisClass.wshc.lockReconnect = false;
+	    }, 2000);
+	}
+	this.close = function(){
+		if(this.sock == null){
+			return;
 		}
-		this.reconnect = function() {
-			if(qrToLabWSHC.lockReconnect || this.isOver){
-				return;
-			}
-			QrToLabPolling.isPostLoginPolling = true;
-		    qrToLabWSHC.lockReconnect = true;
-		    //没连接上会一直重连,设置延迟避免请求过多
-			var thisClass = this;
-		    setTimeout(function () {
-		        thisClass.init(thisClass.sendmsg);
-				qrToLabWSHC.lockReconnect = false;
-		    }, 2000);
+		try{
+			this.sock.send("close");
+			this.sock.close();
+			this.sock = null;
+		}catch(e){
+			//console.error("JyWebScoket "+e);
 		}
 	}
+	this.over = function(){
+		this.wshc.reset();
+		this.isOver = true;
+		this.close();
+		WSpolling.stop();
+	}
 }
-//轮询查询
-var QrToLabPolling = {
+//心跳检测
+var WebSocketHeartCheck = function(obj){
+	this.lockReconnect = false;//避免重复连接
+    this.timeout = 5000;//60秒
+    this.timeoutObj = null;
+    this.serverTimeoutObj = null;
+    this.reset = function(){
+        clearTimeout(this.timeoutObj);
+        clearTimeout(this.serverTimeoutObj);
+        return this;
+    }
+    this.start = function(w,f){
+		if(f){
+			return;
+		}
+        var self = this;
+        this.timeoutObj = setTimeout(function(){
+            //这里发送一个心跳,后端收到后,返回一个心跳消息,
+            //onmessage拿到返回的心跳就说明连接正常
+			if(w.readyState==1){
+            	w.send("HeartBeat");
+			}
+            self.serverTimeoutObj = setTimeout(function(){//如果超过一定时间还没重置,说明后端主动断开了
+				//用自己的超时,如果用w.colse()执行之后,大概要一分钟才会执行webscoket自己的close方法,时间太长
+				//进行ajax轮询
+				if(typeof(obj) == "undefined"){
+					WSpolling.isPostLoginPolling = true;
+				}else{
+					obj.isPostLoginPolling = true;
+				}
+                w.close();//如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
+            }, self.timeout);
+        }, this.timeout);
+    }
+}
+//轮询请求
+var WSpolling = {
+	isPageHidden: false,
 	isPostLoginPolling: false,//是否发起轮询请求
 	loginPollingInterval: null,
-	start: function(obj,msg){
+	start: function(obj){
+		var thisClass = this;
 		//防止重复调用
 		if(this.loginPollingInterval != null){
 			return;
@@ -128,23 +211,12 @@ var QrToLabPolling = {
 		this.loginPollingInterval = setInterval(function(){
 			//如果浏览器不支持webscoket,走ajax轮询方式
 			if(window.WebSocket == undefined) {
-				QrToLabPolling.isPostLoginPolling = true;
+				thisClass.isPostLoginPolling = true;
 			}
-			if(isPageHidden || !QrToLabPolling.isPostLoginPolling){
+			if(thisClass.isPageHidden || !thisClass.isPostLoginPolling){
 				return;
 			}
-			$.ajax({
-				type: "POST",
-				url: "/front/ajaxPolling",
-				data: {userId: msg,reqType:3},
-				dataType: "json",
-				timeout: 3000,
-				success: function(r){
-					if(r.result != ""){
-						obj.complete(r.result,false);
-					}
-				}
-			});
+			obj.ajaxReq();
 		},3000);
 	},
 	stop: function(){
@@ -153,3 +225,15 @@ var QrToLabPolling = {
 		this.isPostLoginPolling = false;
 	}
 }
+//页面是否被切换走
+try{
+	if(window.addEventListener) {    
+		document.addEventListener('visibilitychange',function () {
+		    if(document.hidden){
+				WSpolling.isPageHidden = true;
+		    }else {
+				WSpolling.isPageHidden = false;
+		    }
+		});
+	} 
+}catch(e){}

+ 3 - 51
src/web/staticres/js/login.js

@@ -27,54 +27,6 @@ var unseatflag = false;//未登录情况下,用户点击超级搜索等开启
 var unseatzbqyflag = false;//未登录情况下,用户点击中标企业等开启按钮或者功能,根据此状态看是否弹出二维码
 var sendMsgInterval = null;
 var entjumpflag = false;
-//页面是否被切换走
-var isPageHidden = false;
-try{
-	if(window.addEventListener) {    
-		document.addEventListener('visibilitychange',function () {
-		    if(document.hidden){
-				isPageHidden = true;
-		    }else {
-				isPageHidden = false;
-		    }
-		});
-	} 
-}catch(e){}
-//心跳检测
-var WebSocketHeartCheck = function(scoketType){
-	this.lockReconnect = false;//避免重复连接
-    this.timeout = 5000;//60秒
-    this.timeoutObj = null;
-    this.serverTimeoutObj = null;
-    this.reset = function(){
-        clearTimeout(this.timeoutObj);
-        clearTimeout(this.serverTimeoutObj);
-        return this;
-    }
-    this.start = function(w,f){
-		if(f){
-			return;
-		}
-        var self = this;
-        this.timeoutObj = setTimeout(function(){
-            //这里发送一个心跳,后端收到后,返回一个心跳消息,
-            //onmessage拿到返回的心跳就说明连接正常
-			if(w.readyState==1){
-            	w.send("HeartBeat");
-			}
-            self.serverTimeoutObj = setTimeout(function(){//如果超过一定时间还没重置,说明后端主动断开了
-				//用自己的超时,如果用w.colse()执行之后,大概要一分钟才会执行webscoket自己的close方法,时间太长
-				//进行ajax轮询
-				if(scoketType=="login"){
-					LoginPolling.isPostLoginPolling = true;
-				}else if(scoketType=="qrToLab"){
-					QrToLabPolling.isPostLoginPolling = true;
-				}
-                w.close();//如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
-            }, self.timeout);
-        }, this.timeout);
-    }
-}
 //轮询查询
 var LoginPolling = {
 	isPostLoginPolling: false,//是否发起轮询请求
@@ -90,7 +42,7 @@ var LoginPolling = {
 		this.initInterval = setInterval(this.postShareid,3000);
 	},
 	postShareid: function(){
-		if(isPageHidden || pageshareid == "" || kopshareid == ""){
+		if(WSpolling.isPageHidden || pageshareid == "" || kopshareid == ""){
 			return;
 		}
 		$.ajax({
@@ -116,7 +68,7 @@ var LoginPolling = {
 			if(window.WebSocket == undefined) {
 				LoginPolling.isPostLoginPolling = true;
 			}
-			if(isPageHidden || !LoginPolling.isPostLoginPolling){
+			if(WSpolling.isPageHidden || !LoginPolling.isPostLoginPolling){
 				return;
 			}
 			$.ajax({
@@ -140,7 +92,7 @@ var LoginPolling = {
 		this.initInterval = null;
 	}
 }
-var webSocketHeartCheck = new WebSocketHeartCheck("login");
+var webSocketHeartCheck = new WebSocketHeartCheck(LoginPolling);
 //创建websocket连接
 var createWebSocket = function(flag){
 	try{

+ 1 - 0
src/web/templates/common/pnc.html

@@ -15,6 +15,7 @@
 {{Html `<!--[if lt IE 9]><script src="/js/jquery.js?v={{Msg "seo" "version"}}"><![endif]-->`}}
 <script src="/js/jquery.cookie.js"></script>
 <script src="/js/bootstrap.min.js"></script>
+<script src="/js/jyWebScoket.js?v={{Msg "seo" "version"}}"></script>
 <script src="/js/jy.js?v={{Msg "seo" "version"}}"></script>
 <script src="/js/login.js?v={{Msg "seo" "version"}}"></script>
 <script src="/js/common.js?v={{Msg "seo" "version"}}"></script>

+ 1 - 0
src/web/templates/pc/biddetail.html

@@ -482,6 +482,7 @@ $(function(){
 	}
 	haslogin({{.T.logid}},{{.T.obj.projectname}},"D");
 	JYLogin({{.T.logid}})
+	{{if .T.isForceShare}}new JyWebScoket.qrToShareTimeline();{{end}}
     if (_loop){
         console.log("-",_loop)
         return;

+ 0 - 1
src/web/templates/pc/biddingsearch_enterprise.html

@@ -14,7 +14,6 @@
 		<script src="/js/jquery.cookie.js"></script>
 		<script src="/js/biddingSearch.js?v={{Msg "seo" "version"}}"></script>
 		<script language="javascript" type="text/javascript" src="/My97DatePicker/WdatePicker.js"></script>
-		<script src="/js/jyWebScoket.js?v={{Msg "seo" "version"}}"></script>
 		<link rel="stylesheet" type="text/css" href="/pccss/public-nav-1200.css?v={{Msg "seo" "version"}}" />
 		<script type="text/javascript" src="/js/public-nav.js?v={{Msg "seo" "version"}}"></script>
 

+ 0 - 1
src/web/templates/pc/classifylist.html

@@ -12,7 +12,6 @@
 <link href="/css/dev2/superSearch.css?v={{Msg "seo" "version"}}" rel="stylesheet">
 <script src="/js/pagination.min.js"></script>
 <script language="javascript" type="text/javascript" src="/My97DatePicker/WdatePicker.js"></script>
-<script src="/js/jyWebScoket.js?v={{Msg "seo" "version"}}"></script>
 <link rel="stylesheet" type="text/css" href="/pccss/public-nav-1200.css?v={{Msg "seo" "version"}}" />
 <script type="text/javascript" src="/js/public-nav.js?v={{Msg "seo" "version"}}"></script>
 <style type="text/css">

+ 0 - 1
src/web/templates/pc/proproject.html

@@ -13,7 +13,6 @@
 <link href="/css/dev2/superSearch.css?v={{Msg "seo" "version"}}" rel="stylesheet">
 <script src="/js/jquery.cookie.js"></script>
 <script language="javascript" type="text/javascript" src="/My97DatePicker/WdatePicker.js"></script>
-<script src="/js/jyWebScoket.js?v={{Msg "seo" "version"}}"></script>
 <link rel="stylesheet" type="text/css" href="/pccss/public-nav-1200.css?v={{Msg "seo" "version"}}" />
 <script type="text/javascript" src="/js/public-nav.js?v={{Msg "seo" "version"}}"></script>
 <style type="text/css">

+ 0 - 1
src/web/templates/pc/supsearch.html

@@ -15,7 +15,6 @@
 <script type="text/javascript" src="/js/public-nav.js?v={{Msg "seo" "version"}}"></script>
 <script src="/js/jquery.cookie.js"></script>
 <script language="javascript" type="text/javascript" src="/My97DatePicker/WdatePicker.js"></script>
-<script src="/js/jyWebScoket.js?v={{Msg "seo" "version"}}"></script>
 <style type="text/css">
 /*j-wx-code Start*/
 .j-wx-code{