Răsfoiți Sursa

修改指令

renzheng 9 ani în urmă
părinte
comite
cc2c9fb319
1 a modificat fișierele cu 129 adăugiri și 132 ștergeri
  1. 129 132
      weixin/src/qfw/weixin/wxadmin.go

+ 129 - 132
weixin/src/qfw/weixin/wxadmin.go

@@ -28,147 +28,144 @@ func init() {
 }
 
 func processWxAdmin(openid, content string, w ResponseWriter, r *Request) {
-	/*
-		reg := regexp.MustCompile("^([a-z]+)(\\d.*)$")
-		reg2 := regexp.MustCompile("^(\\d+)([smhd])$")
-		s := reg.FindSubmatch([]byte("aaaaa23s-15s"))
-		s2 := strings.Split(string(s[2]), "-")
-		s2s := reg2.FindSubmatch([]byte(s2[0]))
-	*/
-	if openid != "" {
-		b, cmd, qleng, unit, var1, var2 := checkContent(content)
-		if b {
-			resStr := ""
-			switch cmd {
-			case "f":
-				//查看抽奖模式
-				resStr = getMode()
-			case "c":
-				//切换抽奖模式
-				if var1 >= 0 && var1 <= 3 {
-					br := redis.Put("other", "s_luckydraw_mode", fmt.Sprintf("%d", var1), 0)
-					if br {
-						resStr = "模式已切换:" + getMode()
-					}
-				}
-			case "tjr":
-				//数据库抽奖查看
-				var1, var2 = getTimes(qleng, unit, var1, var2)
-				qu1 := M{"$gte": var1}
-				if qleng == 2 { //取区间
-					qu1 = M{"$gte": var2, "$lte": var1}
-				} else {
-					w.ReplyText("指令异常,请重新输入。")
-					return
-				}
-				util.Try(func() {
-					sess := mongodb.GetMgoConn()
-					defer mongodb.DestoryMongoConn(sess)
-					var res []M
-					sess.DB("qfw").C("winningrecord").Pipe([]M{M{"$match": M{"l_timestamp": qu1}},
-						M{"$group": M{"_id": "$s_prize", "count": M{"$sum": 1}}}}).All(&res)
-					if res != nil && len(res) > 0 {
-						sum := 0
-						for _, v := range res {
-							resStr += "\n" + v["_id"].(string) + ":" + fmt.Sprintf("%x", v["count"])
-							sum += v["count"].(int)
-						}
-						resStr += "\n" + "总数:" + fmt.Sprintf("%d", sum)
-					}
-				}, func(e interface{}) {})
-			case "tju":
-				//新用户查看
-				var1, var2 = getTimes(qleng, unit, var1, var2)
-				qu1 := M{"$gte": var1}
-				if qleng == 2 { //取区间
-					qu1 = M{"$gte": var2, "$lte": var1}
-				} else {
-					w.ReplyText("指令异常,请重新输入。")
-					return
-				}
-				util.Try(func() {
-					sess := mongodb.GetMgoConn()
-					defer mongodb.DestoryMongoConn(sess)
-					var res []M
-					sess.DB("qfw").C("user").Pipe([]M{M{"$match": M{"l_registedate": qu1}},
-						M{"$group": M{"_id": "$black", "count": M{"$sum": 1}}}}).All(&res)
-					if res != nil && len(res) > 0 {
-						sum := 0
-						for _, v := range res {
-							resStr += "\n" + util.If(v["_id"] == nil, "黑名单用户", "正常用户").(string) + ":" + fmt.Sprintf("%x", v["count"])
-							sum += v["count"].(int)
+	util.Try(func() {
+
+		if openid != "" {
+			b, cmd, qleng, unit, var1, var2 := checkContent(content)
+			if b {
+				resStr := ""
+				switch cmd {
+				case "f":
+					//查看抽奖模式
+					resStr = getMode()
+				case "c":
+					//切换抽奖模式
+					if var1 >= 0 && var1 <= 3 {
+						br := redis.Put("other", "s_luckydraw_mode", fmt.Sprintf("%d", var1), 0)
+						if br {
+							resStr = "模式已切换:" + getMode()
 						}
-						resStr += "\n" + "总数:" + fmt.Sprintf("%d", sum)
-					}
-				}, func(e interface{}) {})
-			case "ser":
-				//服务器实时统计情况
-				//各端口,及连接数
-				//总连接数
-				resStr = getServer()
-			case "man":
-				switch var1 {
-				case 1:
-					//重启core
-					cmdstr := getNewCmd(DIR, "core2016")
-					if len(cmdstr) > 0 {
-						execCmd(DIR, "core2016", cmdstr, true)
-					}
-					resStr = "重启主程序完成"
-				case 11:
-					//关闭core
-					cmdstr := getNewCmd(DIR, "core2016")
-					if len(cmdstr) > 0 {
-						execCmd(DIR, "core2016", cmdstr, false)
 					}
-					resStr = "关闭主程序完成"
-				case 2:
-					//重启weixin
-					cmdstr := getNewCmd(DIR+"/weixin", "weixin")
-					if len(cmdstr) > 0 {
-						execCmd(DIR+"/weixin", "weixin", cmdstr, true)
+				case "tjr":
+					//数据库抽奖查看
+					var1, var2 = getTimes(qleng, unit, var1, var2)
+					qu1 := M{"$gte": var1}
+					if qleng == 2 { //取区间
+						qu1 = M{"$gte": var2, "$lte": var1}
+					} else {
+						w.ReplyText("指令异常,请重新输入。")
+						return
 					}
-					resStr = "重启微信程序完成"
-				case 22:
-				//不能关闭微信
-				case 3:
-					//重启积分
-					cmdstr := getNewCmd(DIR+"/credit", "credit")
-					if len(cmdstr) > 0 {
-						execCmd(DIR+"/credit", "credit", cmdstr, true)
-					}
-					resStr = "重启积分程序完成"
-				case 33:
-					cmdstr := getNewCmd(DIR+"/credit", "credit")
-					if len(cmdstr) > 0 {
-						execCmd(DIR+"/credit", "credit", cmdstr, false)
-					}
-					resStr = "关闭积分程序完成"
-				//关闭积分
-				case 4:
-					//重启oauth
-					cmdstr := getNewCmd(DIR+"/proxy", "oauth")
-					if len(cmdstr) > 0 {
-						execCmd(DIR+"/proxy", "oauth", cmdstr, true)
+					util.Try(func() {
+						sess := mongodb.GetMgoConn()
+						defer mongodb.DestoryMongoConn(sess)
+						var res []M
+						sess.DB("qfw").C("winningrecord").Pipe([]M{M{"$match": M{"l_timestamp": qu1}},
+							M{"$group": M{"_id": "$s_prize", "count": M{"$sum": 1}}}}).All(&res)
+						if res != nil && len(res) > 0 {
+							sum := 0
+							for _, v := range res {
+								resStr += "\n" + v["_id"].(string) + ":" + fmt.Sprintf("%x", v["count"])
+								sum += v["count"].(int)
+							}
+							resStr += "\n" + "总数:" + fmt.Sprintf("%d", sum)
+						}
+					}, func(e interface{}) {})
+				case "tju":
+					//新用户查看
+					var1, var2 = getTimes(qleng, unit, var1, var2)
+					qu1 := M{"$gte": var1}
+					if qleng == 2 { //取区间
+						qu1 = M{"$gte": var2, "$lte": var1}
+					} else {
+						w.ReplyText("指令异常,请重新输入。")
+						return
 					}
-					resStr = "重启微信程认证序完成"
-				case 44:
-					//关闭oauth
-					cmdstr := getNewCmd(DIR+"/proxy", "oauth")
-					if len(cmdstr) > 0 {
-						execCmd(DIR+"/proxy", "oauth", cmdstr, false)
+					util.Try(func() {
+						sess := mongodb.GetMgoConn()
+						defer mongodb.DestoryMongoConn(sess)
+						var res []M
+						sess.DB("qfw").C("user").Pipe([]M{M{"$match": M{"l_registedate": qu1}},
+							M{"$group": M{"_id": "$black", "count": M{"$sum": 1}}}}).All(&res)
+						if res != nil && len(res) > 0 {
+							sum := 0
+							for _, v := range res {
+								resStr += "\n" + util.If(v["_id"] == nil, "黑名单用户", "正常用户").(string) + ":" + fmt.Sprintf("%x", v["count"])
+								sum += v["count"].(int)
+							}
+							resStr += "\n" + "总数:" + fmt.Sprintf("%d", sum)
+						}
+					}, func(e interface{}) {})
+				case "ser":
+					//服务器实时统计情况
+					//各端口,及连接数
+					//总连接数
+					resStr = getServer()
+				case "man":
+					switch var1 {
+					case 1:
+						//重启core
+						cmdstr := getNewCmd(DIR, "core2016")
+						if len(cmdstr) > 0 {
+							execCmd(DIR, "core2016", cmdstr, true)
+						}
+						resStr = "重启主程序完成"
+					case 11:
+						//关闭core
+						cmdstr := getNewCmd(DIR, "core2016")
+						if len(cmdstr) > 0 {
+							execCmd(DIR, "core2016", cmdstr, false)
+						}
+						resStr = "关闭主程序完成"
+					case 2:
+						//重启weixin
+						cmdstr := getNewCmd(DIR+"/weixin", "weixin")
+						if len(cmdstr) > 0 {
+							execCmd(DIR+"/weixin", "weixin", cmdstr, true)
+						}
+						resStr = "重启微信程序完成"
+					case 22:
+						//不能关闭微信
+						break
+					case 3:
+						//重启积分
+						cmdstr := getNewCmd(DIR+"/credit", "credit")
+						if len(cmdstr) > 0 {
+							execCmd(DIR+"/credit", "credit", cmdstr, true)
+						}
+						resStr = "重启积分程序完成"
+					case 33:
+						cmdstr := getNewCmd(DIR+"/credit", "credit")
+						if len(cmdstr) > 0 {
+							execCmd(DIR+"/credit", "credit", cmdstr, false)
+						}
+						resStr = "关闭积分程序完成"
+					//关闭积分
+					case 4:
+						//重启oauth
+						cmdstr := getNewCmd(DIR+"/proxy", "oauth")
+						if len(cmdstr) > 0 {
+							execCmd(DIR+"/proxy", "oauth", cmdstr, true)
+						}
+						resStr = "重启微信程认证序完成"
+					case 44:
+						//关闭oauth
+						cmdstr := getNewCmd(DIR+"/proxy", "oauth")
+						if len(cmdstr) > 0 {
+							execCmd(DIR+"/proxy", "oauth", cmdstr, false)
+						}
+						resStr = "关闭微信程认证序完成"
 					}
-					resStr = "关闭微信程认证序完成"
 				}
+				w.ReplyText(resStr)
+			} else {
+				w.ReplyText("指令不存在,请重新输入。")
 			}
-			w.ReplyText(resStr)
 		} else {
-			w.ReplyText("指令不存在,请重新输入。")
+			w.ReplyText("用户信息不存在,请重新进入。")
+			delete(UserSession, openid)
 		}
-	} else {
-		w.ReplyText("用户信息不存在,请重新进入。")
-		delete(UserSession, openid)
-	}
+	}, func(e interface{}) {})
 }
 
 func getNewCmd(dir, substr string) string {