wangshan 9 vuotta sitten
vanhempi
commit
b5182e8472

+ 2 - 2
common/src/qfw/util/encrypt_test.go

@@ -22,8 +22,8 @@ func Test_sim(t *testing.T) {
 	//s2 := "GyUlIhEDDjcfWCAyIl4xBkgsERYiLAwZLCg9VkkbLj4zMRYDPRs5ATVZOxccPAkzFxw7CCpEFj41QlRAQFdFXlRMQVZcHRIbBgsWBxYcFQwEBwoa"
 
 	//s3 := "RFYoal5bCFdXWQoQB0JuWwlXAQFZCUVfFj4JMFtT"
-	s4 := "oJULtwzXo6EFV1Ah-XeyRBimXGM8,uid,123456,wxpushlist"
-	se := SimpleEncrypt{Key: "topnet"}
+	s4 := "oJULtwzXo6EFV1Ah-XeyRBimXGM8"
+	se := SimpleEncrypt{Key: "topnet2015topnet2015"}
 	log.Println("=====", se.EncodeString(s4))
 	log.Println("=====", se.EncodeString(",1349385977,ASD"))
 	log.Println("---", se.DecodeString("GyUlIhEDDjcfWCAyIl4xBkgsERYiLAwZLCg9VkkBHQtcX1FBR1hJWldCREMHFhUBBwccBxYA"))

+ 180 - 0
core/src/qfw/active/activemanage.go

@@ -4,9 +4,11 @@
 package active
 
 import (
+	"container/list"
 	"fmt"
 	"github.com/go-xweb/xweb"
 	"gopkg.in/mgo.v2/bson"
+	"log"
 	"math/rand"
 	. "qfw/coreconfig"
 	"qfw/coreutil"
@@ -18,9 +20,183 @@ import (
 	qrpc "qfw/util/rpc"
 	"strconv"
 	"strings"
+	"sync"
 	"time"
 )
 
+//限制与解除数组
+var limitrule, unlimitrule [][]int
+
+//时间间隔
+var unlimitduration int
+
+//提示语
+var limitmsg, unlimitmsg string
+
+//锁
+var limitLock = new(sync.Mutex)
+
+//限制状态
+var limitStatus = false
+
+//流量池
+var tList = list.New()
+
+//全局抽奖次数
+var times int64
+
+//通知openid
+var notifyIds []string
+
+//对池的管理
+func listFun() {
+	tList.Remove(tList.Front())
+	tList.PushBack(times)
+	time.AfterFunc(1*time.Second, listFun)
+}
+
+//取值
+func CheckLimit() bool {
+	times++
+	return limitStatus
+}
+
+func getValFromList(n int) (val int, flag bool) {
+	Try(func() {
+		B := tList.Back()
+		Bn := B.Value.(int64)
+		ti := 1
+		n = n - 1
+		A := B.Prev()
+		flag = true
+		for ti < n {
+			if A != nil {
+				ti++
+				A = A.Prev()
+			} else {
+				flag = false
+				break
+			}
+		}
+		val = int(Bn - A.Value.(int64))
+	}, func(e interface{}) {
+		log.Println("ERROR", e)
+	})
+	return
+}
+
+//限制的监测
+func limitFun() {
+	limitLock.Lock()
+	//非限制状态
+	if !limitStatus {
+		for _, v := range limitrule {
+			//取的秒的区间
+			if val, flag := getValFromList(v[0]); flag && val >= v[1] {
+				//限制状态
+				limitStatus = true
+				//发送模板消息
+				str := fmt.Sprintf(limitmsg, v[0], val, v[1])
+				go func() {
+					log.Println("发送限制抽奖通知", str)
+					Try(func() {
+						for _, id := range notifyIds {
+							coreutil.SendManagerNotifyMsg(&qrpc.NotifyMsg{
+								Openid: id,
+								Title:  "抽奖进入限制状态通知",
+								Detail: "系统",
+								Result: str,
+								Remark: "",
+							})
+						}
+					}, func(e interface{}) {})
+				}()
+				break
+			}
+		}
+	}
+	limitLock.Unlock()
+	time.AfterFunc(5*time.Second, limitFun)
+}
+
+//解除限制的监测
+func unlimitFun() {
+	limitLock.Lock()
+	//非限制状态
+	if limitStatus {
+		allb := true
+		str := ""
+		for _, v := range unlimitrule {
+			//取的秒的区间
+			val, flag := getValFromList(v[0])
+			if !flag || val >= v[1] {
+				allb = false
+				break
+			} else {
+				str += " [间隔:" + strconv.Itoa(v[0]) + "," + "实际次数:" + strconv.Itoa(val) + ",限制:" + strconv.Itoa(v[1]) + "]"
+			}
+		}
+		if allb {
+			limitStatus = false
+			//发送解除通知
+			go func() {
+				log.Println("发送解除抽奖限制通知", str)
+				Try(func() {
+					for _, id := range notifyIds {
+						coreutil.SendManagerNotifyMsg(&qrpc.NotifyMsg{
+							Openid: id,
+							Title:  "抽奖进入限制状态通知",
+							Detail: "系统",
+							Result: fmt.Sprintf(unlimitmsg, str),
+							Remark: "",
+						})
+					}
+				}, func(e interface{}) {})
+			}()
+		}
+
+	}
+	limitLock.Unlock()
+	time.AfterFunc(time.Duration(unlimitduration)*time.Second, unlimitFun)
+}
+
+//初始化内容
+func init() {
+	tmpLimtRules := RedPackage.Limit["limitrules"].([]interface{})
+	limitrule = make([][]int, len(tmpLimtRules))
+	for i, k := range tmpLimtRules {
+		minR := k.([]interface{})
+		tmpInts := make([]int, len(minR))
+		limitrule[i] = tmpInts
+		for j, v := range minR {
+			tmpInts[j] = int(v.(float64))
+		}
+	}
+	tmpUnLimtRules := RedPackage.Limit["unlimitrules"].([]interface{})
+	unlimitrule = make([][]int, len(tmpUnLimtRules))
+	for i, k := range tmpUnLimtRules {
+		minR := k.([]interface{})
+		tmpInts := make([]int, len(minR))
+		unlimitrule[i] = tmpInts
+		for j, v := range minR {
+			tmpInts[j] = int(v.(float64))
+		}
+	}
+	unlimitduration = int(RedPackage.Limit["unlimitduration"].(float64))
+	limitmsg = RedPackage.Limit["limitmsg"].(string)
+	unlimitmsg = RedPackage.Limit["unlimitmsg"].(string)
+
+	notifyIds = ObjArrToStringArr(RedPackage.Limit["notifyIds"].([]interface{}))
+
+	for tList.Len() < 3600 {
+		tList.PushBack(int64(0))
+	}
+
+	go listFun()
+	go limitFun()
+	go unlimitFun()
+}
+
 type Activemanage struct {
 	*xweb.Action
 	luckdraw    xweb.Mapper `xweb:"/activity/(\\w+)/([^.]*)"`
@@ -94,6 +270,7 @@ func (a *Activemanage) Luckdraw(activecode, id string) error {
 
 //
 func (a *Activemanage) Getluckdraw() error {
+	CheckLimit()
 	flog := "F"
 	//提示语
 	msg := ""
@@ -211,6 +388,9 @@ func getLuckDraw() int {
 	th := time.Now().Hour()
 	thflog := (th < 23 || th > 7)
 	array := []map[string]interface{}{}
+	if !CheckLimit() {
+		flog = true
+	}
 	if flog == false || thflog == false {
 		array = LuckDraw.GetAmounttwo
 	} else {

+ 47 - 0
core/src/qfw/coreconfig/MessageConfig_test.go

@@ -1,7 +1,9 @@
 package coreconfig
 
 import (
+	"container/list"
 	"log"
+	"time"
 	//"qfw/coreconfig"
 	"qfw/util"
 	"testing"
@@ -12,3 +14,48 @@ func TestGetMessage(t *testing.T) {
 	ret := util.GetPropertie("indentify.success.result", MessageConfig)
 	log.Println(ret)
 }
+
+var tList *list.List
+var times int
+
+func listFun() {
+	times++
+	tList.Remove(tList.Front())
+	tList.PushBack(times)
+	time.AfterFunc(1*time.Second, listFun)
+}
+
+func TestList(t *testing.T) {
+	tList = list.New()
+	for tList.Len() < 3000 {
+		tList.PushBack(0)
+	}
+	go listFun()
+
+	/**
+	i := 0
+	for i < 10 {
+		i++
+		h.Remove(h.Front())
+		h.PushBack(i)
+
+		for e := h.Front(); e != nil; e = e.Next() {
+			log.Print(e.Value, "  ")
+		}
+	}
+	**/
+
+	go func() {
+		for {
+			log.Print("\n----------")
+			for e := tList.Front(); e != nil; e = e.Next() {
+				log.Print(e.Value, "  ")
+			}
+			log.Print("\n----------")
+			time.Sleep(5 * time.Second)
+		}
+	}()
+
+	b := make(chan bool, 1)
+	<-b
+}

+ 1 - 0
core/src/qfw/coreconfig/RedPackage.go

@@ -15,6 +15,7 @@ type redPackage struct {
 	Weixin        map[string]interface{}   `json:"weixin"`
 	Msg           map[string]interface{}   `json:"msg"`
 	IsReissue     bool                     `json:"isReissue"`
+	Limit         map[string]interface{}   `json:"limit"`
 }
 
 var RedPackage redPackage

+ 105 - 59
core/src/redpackage.json

@@ -1,61 +1,107 @@
 {
-	"startDate":1450022400,
-	"endDate":1452700800,
-	"getAmount":[{
-		"min":3,
-		"max":6,
-		"proportion":97.1
-	},{
-		"min":6,
-		"max":11,
-		"proportion":2
-	},{
-		"min":11,
-		"max":51,
-		"proportion":0.75
-	},{
-		"min":51,
-		"max":151,
-		"proportion":0.1
-	},{
-		"min":151,
-		"max":201,
-		"proportion":0.05
-	}],
-	"showAmount":[{
-		"min":3,
-		"max":10,
-		"count":2
-	},{
-		"min":10,
-		"max":50,
-		"count":4
-	},{
-		"min":50,
-		"max":100,
-		"count":6
-	},{
-		"min":100,
-		"max":150,
-		"count":4
-	},{
-		"min":150,
-		"max":200,
-		"count":4
-	}],
-	"promotioncode":"2001001501",
-	"weixin":{
-		"sendname":"企明星",
-		"wishing":"企明星扫码送红包活动",
-		"actname":"企明星扫码送红包活动",
-		"remark":"拆红包愉快!",
-		"successtitle":"友情提示",
-		"successremark":"因参加活动的用户较多,如果您在十分钟内未收到企明星发放的红包,请及时联系客服QQ。"
-	},
-	"msg":{
-		"title":"红包到账啦!",
-		"content":"您的企明星红包到账啦,快打开微信猛戳红包!"
-	},
-	"reissueTime":"8:10",
-	"isReissue":false
+    "startDate": 1450022400,
+    "endDate": 1452700800,
+    "getAmount": [
+        {
+            "min": 3,
+            "max": 6,
+            "proportion": 97.1
+        },
+        {
+            "min": 6,
+            "max": 11,
+            "proportion": 2
+        },
+        {
+            "min": 11,
+            "max": 51,
+            "proportion": 0.75
+        },
+        {
+            "min": 51,
+            "max": 151,
+            "proportion": 0.1
+        },
+        {
+            "min": 151,
+            "max": 201,
+            "proportion": 0.05
+        }
+    ],
+    "showAmount": [
+        {
+            "min": 3,
+            "max": 10,
+            "count": 2
+        },
+        {
+            "min": 10,
+            "max": 50,
+            "count": 4
+        },
+        {
+            "min": 50,
+            "max": 100,
+            "count": 6
+        },
+        {
+            "min": 100,
+            "max": 150,
+            "count": 4
+        },
+        {
+            "min": 150,
+            "max": 200,
+            "count": 4
+        }
+    ],
+    "promotioncode": "2001001501",
+    "weixin": {
+        "sendname": "企明星",
+        "wishing": "企明星扫码送红包活动",
+        "actname": "企明星扫码送红包活动",
+        "remark": "拆红包愉快!",
+        "successtitle": "友情提示",
+        "successremark": "因参加活动的用户较多,如果您在十分钟内未收到企明星发放的红包,请及时联系客服QQ。"
+    },
+    "msg": {
+        "title": "红包到账啦!",
+        "content": "您的企明星红包到账啦,快打开微信猛戳红包!"
+    },
+    "limit": {
+        "limitrules": [
+			[
+                10,
+                50
+            ],
+            [
+                30,
+                130
+            ],
+            [
+                60,
+                300
+            ]
+        ],
+        "limitmsg": "抽奖进入限止状态,原因:%d秒内抽奖次数为%d超过%d次。",
+        "unlimitduration": 1200,
+		"notifyIds":["oJULtwzXo6EFV1Ah-XeyRBimXGM8"],
+        "unlimitrules": [
+            [
+                3600,
+                1000
+            ],
+            [
+                2500,
+                500
+            ],
+            [
+                1200,
+                200
+            ]
+        ],
+        "unlimitmsg": "解除抽奖限止,%s。"
+    },
+    "reissueTime": "8:10",
+    "isReissue": false
 }

+ 1 - 1
core/src/timetask.json

@@ -1 +1 @@
-{"comment":{"c_rate":720,"commentrate":900},"market":{"demand":{"attr":["i_hits","i_bids","i_status"],"timepoint":"2016-01-29 15:54:12"},"service":{"attr":["i_hits","i_sales","i_comments","i_score","i_appcounts"],"timepoint":"2016-01-29 15:54:12"}},"marketisstart":true,"marketrate":300}
+{"comment":{"c_rate":720,"commentrate":900},"market":{"demand":{"attr":["i_hits","i_bids","i_status"],"timepoint":"2016-01-29 15:54:12"},"service":{"attr":["i_hits","i_sales","i_comments","i_score","i_appcounts"],"timepoint":"2016-01-29 15:54:12"}},"marketisstart":true,"marketrate":300}

+ 5 - 0
core/src/web/staticres/css/qfw.css

@@ -484,6 +484,11 @@ a.new_red:hover, a.new_red:active {
 	color: #FF5A5F;
 	box-shadow: none;
 }
+.btn.disabled, .btn.disabled.active, .btn.disabled.focus, .btn.disabled:active, .btn.disabled:focus, .btn.disabled:hover, .btn[disabled], .btn[disabled].active, .btn[disabled].focus, .btn[disabled]:active, .btn[disabled]:focus, .btn[disabled]:hover, fieldset[disabled] .btn, fieldset[disabled] .btn.active, fieldset[disabled] .btn.focus, fieldset[disabled] .btn:active, fieldset[disabled] .btn:focus, fieldset[disabled] .btn:hover{
+	color: #FFFFFF;
+	background-color: #aea79f;
+	border-color: #aea79f;
+}
 .btn-sm, .btn-group-sm > .btn{
 	padding-top: 3px;
 	padding-bottom: 3px;

+ 1 - 1
core/src/web/templates/swordfish/wxshare.html

@@ -1,6 +1,6 @@
 <html>
 <head>
-<title>企明星-剑鱼-演示</title>
+<title>企明星-剑鱼</title>
 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
 <link href="/wxswordfish/style.css" rel="stylesheet">
 <link href="/swiper/swiper.min.css" rel="stylesheet">

+ 1 - 1
core/src/web/templates/swordfish/wxshareguide.html

@@ -1,6 +1,6 @@
 <html>
 <head>
-<title>企明星-剑鱼-演示</title>
+<title>企明星-剑鱼-分享</title>
 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
 <link href="/wxswordfish/style.css" rel="stylesheet">
 <link href="/swiper/swiper.min.css" rel="stylesheet">

+ 3 - 1
weixin/src/config.json

@@ -34,6 +34,8 @@
 		"title":"企明星新年抽奖活动进行中",
 		"picurl":"http://www.qimingxing.info/images/choujiang2.png"
 	},"weixinautorpl":"小主的吩咐我们已经收到了,请留下您的联系方式(手机号或qq号),企明星客服会在下一个工作日9:00-17:00给小主回复哦!",
-	"creditRpc":"127.0.0.1:8765"
+	"creditRpc":"127.0.0.1:8765",
+	"subscribemonitorcyc":3,
+	"subscribemonitortimes":12
 
 }

+ 3 - 3
weixin/src/qfw/weixin/clickhandler.go

@@ -36,7 +36,7 @@ func ClickHandler(w ResponseWriter, r *Request) {
 					w.ReplyText("您已经提交认证信息,正在审核中,请耐心等待")
 				} else if state == 1 {
 					//w.ReplyText("恭喜您,身份认证已通过,请点击<a href='http://" + wf.SysConfig.Domain + "/ent/wsite/edit/" + r.FromUserName + "'>进入微官网</a>")
-					urlstr := "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + wf.SysConfig.Appid + "&redirect_uri=http://" + wf.SysConfig.Domain + "/weixinoauth?action=msiteaction&response_type=code&scope=snsapi_base&state=1#wechat_redirect"
+					urlstr := "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + wf.SysConfig.Appid + "&redirect_uri=http://" + wf.SysConfig.Domain + "/weixinoauth/action/msiteaction&response_type=code&scope=snsapi_base&state=1#wechat_redirect"
 					w.ReplyText("恭喜您,身份认证已通过,请点击<a href='" + urlstr + "'>进入微官网</a>")
 				} else {
 					str := "欢迎您进行企业认证"
@@ -56,7 +56,7 @@ func ClickHandler(w ResponseWriter, r *Request) {
 					w.ReplyText("您已经提交认证信息,正在审核中,请耐心等待")
 				} else if state == 1 {
 					//w.ReplyText("恭喜您,身份认证已通过,请点击<a href='http://" + wf.SysConfig.Domain + "/ent/wsite/edit/" + r.FromUserName + "'>进入微官网</a>")
-					urlstr := "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + wf.SysConfig.Appid + "&redirect_uri=http://" + wf.SysConfig.Domain + "/weixinoauth?action=msiteaction&response_type=code&scope=snsapi_base&state=1#wechat_redirect"
+					urlstr := "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + wf.SysConfig.Appid + "&redirect_uri=http://" + wf.SysConfig.Domain + "/weixinoauth/action/msiteaction&response_type=code&scope=snsapi_base&state=1#wechat_redirect"
 					w.ReplyText("恭喜您,身份认证已通过,请点击<a href='" + urlstr + "'>进入微官网</a>")
 				} else {
 					str := "欢迎您进行个人认证"
@@ -76,7 +76,7 @@ func ClickHandler(w ResponseWriter, r *Request) {
 					w.ReplyText("您已经提交认证信息,正在审核中,请耐心等待")
 				} else if state == 1 {
 					//w.ReplyText("恭喜您,身份认证已通过,请点击<a href='http://" + wf.SysConfig.Domain + "/ent/wsite/edit/" + r.FromUserName + "'>进入微官网</a>")
-					urlstr := "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + wf.SysConfig.Appid + "&redirect_uri=http://" + wf.SysConfig.Domain + "/weixinoauth?action=msiteaction&response_type=code&scope=snsapi_base&state=1#wechat_redirect"
+					urlstr := "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + wf.SysConfig.Appid + "&redirect_uri=http://" + wf.SysConfig.Domain + "/weixinoauth/action/msiteaction&response_type=code&scope=snsapi_base&state=1#wechat_redirect"
 					w.ReplyText("恭喜您,身份认证已通过,请点击<a href='" + urlstr + "'>进入微官网</a>")
 				} else {
 					str := "欢迎您进行机构认证"

+ 13 - 4
weixin/src/qfw/weixin/dao/sharedao.go

@@ -14,11 +14,20 @@ import (
 //锁
 var sharelock *sync.Mutex = &sync.Mutex{}
 
-//保存用户邀请关系,走线程池
-func SaveInviteLink(shareid string, myopenid string) {
+//保存用户邀请关系
+func SaveInviteLink(shareid string, myopenid string,isolduser bool) {
 	log.Println("save user invitelink ", myopenid, shareid)
-	//先找邀请人信息
-	sharelock.Lock()
+		sharelock.Lock()
+	//对于老用户的处理
+	if isolduser{//找我自己是不是别人邀请的
+		invite:=FindOne("person_invitelink",`{"s_target_openid":"`+myopenid+`"}`)
+		if *invite!=nil{
+			sharelock.Unlock()
+			return
+		}
+	}
+	//找邀请人信息
+
 	ret := FindOne("person_share", M{"i_shareid": shareid})
 	if *ret == nil {
 		log.Println("wu share info!!!!")

+ 1 - 0
weixin/src/qfw/weixin/msgtxtchandler.go

@@ -65,6 +65,7 @@ func MsgTxtHandler(w ResponseWriter, r *Request) {
 		w.ReplyText("嗨,小星来陪你解闷。有什么开心的,不开心的说说来,大伙乐呵乐呵。\n输入q或Q离开。")
 		return
 	} else if r.Content == "抽奖" { //进入抽奖环节
+		//w.ReplyText("非常抱歉!系统维护中,请稍后再试。")
 		targeturl := fmt.Sprintf("http://%s/activity/%s/%s", wf.SysConfig.Domain, wf.SysConfig.Activity["activitycode"], se.EncodeString(r.FromUserName))
 		w.ReplyNews([]Article{Article{PicUrl: wf.SysConfig.Activity["picurl"], Title: wf.SysConfig.Activity["title"], Url: targeturl}})
 	} else if strings.HasPrefix(r.Content, "内部报名") { //绑定拓普员工姓名

+ 2 - 2
weixin/src/qfw/weixin/paybonusact.go

@@ -85,13 +85,13 @@ type GroupBonusMsg struct {
 var se util.SimpleEncrypt = util.SimpleEncrypt{Key: "topnet2015topnet2015"}
 
 //发红包(传统红包)
-func PayBonusAct1(w http.ResponseWriter, r *http.Request) {
+func PayNormalBonusAct(w http.ResponseWriter, r *http.Request) {
 	if r.Method == "GET" {
 		w.Write([]byte(html))
 	} else {
 		//动作
 		cert := r.FormValue("cert")
-		s_cert := se.EncodeString(time.Now().Format("2006010215"))
+		s_cert := se.EncodeString(time.Now().Format("200601021504"))
 		if s_cert != cert {
 			w.Write([]byte("error cert"))
 			return

+ 6 - 9
weixin/src/qfw/weixin/subscribehandler.go

@@ -8,25 +8,19 @@ import (
 	"net/http"
 	"os"
 	"qfw/util"
+	wxutil "qfw/weixin/util"
 	"qfw/util/redis"
 	"qfw/weixin/dao"
 	"qfw/weixinconfig"
-	"regexp"
 	"strings"
 	"time"
 )
 
-var WELCOME_MSG string
-var OWELCOME_MSG string
 
-var digitreg *regexp.Regexp = regexp.MustCompile("^\\d+$")
 
 //关注事件处理
 func SubscribeHandler(w ResponseWriter, r *Request) {
-	if WELCOME_MSG == "" || OWELCOME_MSG == "" {
-		WELCOME_MSG = weixinconfig.SysConfig.WelcomeTip
-		OWELCOME_MSG = weixinconfig.SysConfig.OWelcomeTip
-	}
+	wxutil.SubscribeInc()
 	openid := r.FromUserName
 	ret, err := w.GetUserBaseInfo(openid)
 	var unionid, bindweixin, userphoto string
@@ -57,11 +51,14 @@ func SubscribeHandler(w ResponseWriter, r *Request) {
 			redis.Put("sso", "new_"+source, openid, 900)
 			//TODO 处理分享(邀请)类的二维码,记录邀请关系
 			if strings.HasPrefix(source, "32") {
-				go dao.SaveInviteLink(source, r.FromUserName)
+				go dao.SaveInviteLink(source, r.FromUserName, false)
 				//go dao.UpdateInviteUserCoupon(source)
 			}
 		} else {
 			w.ReplyText(OWELCOME_MSG) // 有旧人关注,返回欢迎消息
+			if strings.HasPrefix(source, "32") {
+				go dao.SaveInviteLink(source, r.FromUserName, true)
+			}
 		}
 		DoLogin(source, openid)
 	} else {

+ 42 - 0
weixin/src/qfw/weixin/util/subscribefilter.go

@@ -0,0 +1,42 @@
+package util
+
+//实时统计状态
+import (
+	"log"
+	"fmt"
+	"qfw/util/mongodb"
+	"sync/atomic"
+	"time"
+)
+
+var tmp int32 = 0
+var starttime, endtime int64
+var dutrat time.Duration //时间间隔
+var times int32
+
+//累加
+func SubscribeInc() {
+	atomic.AddInt32(&tmp, 1)
+}
+
+func subscribeStats() {
+	endtime = time.Now().Unix()
+	total := atomic.SwapInt32(&tmp, 0)
+	//
+	if total > times {
+		log.Printf("flash black user [%d - %d] \n ",starttime,endtime)
+		//刷数据
+		mongodb.Update("user", fmt.Sprintf(`{"l_registedate":{"$gte":%d,"$lte":%d}}`, starttime, endtime), `{"$set":{"black":1}}`, false, true)
+	}
+	starttime = time.Now().Unix()
+	endtime = starttime
+	time.AfterFunc(dutrat, subscribeStats)
+}
+
+//启动过滤,3分钟,超过20次,认为是非法操作
+func StartSubscribeFilter(cyc, ts int) {
+	times = int32(ts)
+	dutrat = time.Duration(cyc) * time.Minute
+	starttime = time.Now().Unix()
+	go time.AfterFunc(dutrat, subscribeStats)
+}

+ 1 - 0
weixin/src/qfw/weixin/util/util.go

@@ -0,0 +1 @@
+package util

+ 9 - 1
weixin/src/qfw/weixin/weixin.go

@@ -2,6 +2,7 @@ package weixin
 
 import (
 	"net/http"
+	"qfw/weixin/util"
 	wf "qfw/weixinconfig"
 	"regexp"
 )
@@ -10,12 +11,17 @@ var Mux *Weixin
 
 //语音用到的正则
 var clear_voice_reg, keyword_voice_reg, notify_xiaoxing, chat_bye *regexp.Regexp
+var WELCOME_MSG string
+var OWELCOME_MSG string
+var digitreg *regexp.Regexp = regexp.MustCompile("^\\d+$")
 
 func InitWeixinSdk() {
 	keyword_voice_reg, _ = regexp.Compile("查询|搜索|检索|看|找|查|搜")
 	clear_voice_reg, _ = regexp.Compile("!|!|\\s+")
 	notify_xiaoxing, _ = regexp.Compile("小星|阿星|助手|助理")
 	chat_bye, _ = regexp.Compile("再见|拜拜|不说了|不聊了")
+	WELCOME_MSG = wf.SysConfig.WelcomeTip
+	OWELCOME_MSG = wf.SysConfig.OWelcomeTip
 
 	// my-token 验证微信公众平台的Token
 	// app-id, app-secret用于高级API调用。
@@ -42,9 +48,10 @@ func InitWeixinSdk() {
 	//单点登录请求
 	http.HandleFunc("/"+wf.SysConfig.Appcontext+"/sso/", SsoHandle)
 	//支付
-	http.HandleFunc("/"+wf.SysConfig.Appcontext+"/paybonus", PayBonusAct)
+	http.HandleFunc("/"+wf.SysConfig.Appcontext+"/paybonus", PayNormalBonusAct)
 	http.HandleFunc("/"+wf.SysConfig.Appcontext+"/recharge", RechargeAct)
 	http.HandleFunc("/"+wf.SysConfig.Appcontext+"/paycallback", PayCallback)
+	//监控
 
 	//生成推广二维码
 	http.HandleFunc("/"+wf.SysConfig.Appcontext+"/adv/", AdvHandle)
@@ -52,4 +59,5 @@ func InitWeixinSdk() {
 	//执行其他一些初始化的动作
 	InitRobotHttpClient()
 	InitSSLClient()
+	util.StartSubscribeFilter(wf.SysConfig.SubscribeMonitorCyc, wf.SysConfig.SubscribeMonitorTimes)
 }

+ 12 - 0
weixin/src/qfw/weixin/weixinsdkssl.go

@@ -1,6 +1,7 @@
 package weixin
 
 import (
+	"encoding/json"
 	"bytes"
 	"crypto/tls"
 	"crypto/x509"
@@ -76,6 +77,17 @@ func (wx *Weixin) PostXmlCustom(url string, obj interface{}) ([]byte, error) {
 	return bs, err
 }
 
+//Post Json Data
+func (wx *Weixin) PostJsonCustom(url string, obj interface{}) ([]byte,error){
+	var bs []byte
+	data, err := json.Marshal(obj)
+	if err != nil {
+		return bs, err
+	}
+	bs, err = postSSLRequest(url, wx.tokenChan, data)
+	return bs,err
+}
+
 //发送安全请求
 func postSSLRequest(reqURL string, c chan accessToken, data []byte) ([]byte, error) {
 	for i := 0; i < retryMaxN; i++ {

+ 2 - 0
weixin/src/qfw/weixinconfig/weixinconfig.go

@@ -30,6 +30,8 @@ type wxconfig struct {
 	FreezeTip       string            `json:"freezeTip"`
 	Activity        map[string]string `json:"activity"` //活动配置
 	WeixinAutoRpl   string            `json:"weixinautorpl"`
+	SubscribeMonitorCyc int `json:"subscribemonitorcyc"`
+	SubscribeMonitorTimes int `json:"subscribemonitortimes"`
 }
 
 //系统配置

BIN
weixin/src/weixin