Esempio n. 1
0
// 解析数组
func (this *YuqingAnalyse) BaseFormStrings(contro *beego.Controller) (bool, interface{}) {
	types := contro.GetStrings("t")

	if len(types) > 0 {
		typeInts := make([]int, len(types))

		for k, _ := range types {
			typeInts[k], _ = strconv.Atoi(types[k])
		}

		this.Type = typeInts
	}

	ignoreTypes := contro.GetStrings("i")

	if len(ignoreTypes) > 0 {
		typeInts := make([]int, len(ignoreTypes))

		for k, _ := range ignoreTypes {
			typeInts[k], _ = strconv.Atoi(ignoreTypes[k])
		}

		this.IgnoreType = typeInts
	}

	return true, nil
}
Esempio n. 2
0
//远程抓图
func CatchImage(this *beego.Controller) {
	//fmt.Println(this.Ctx.Request.Body)
	urls := this.GetStrings("source[]")
	//fmt.Println(urls)
	callbackjson := "{\"state\": \"SUCCESS\",\"list\": ["
	if len(urls) > 0 {
		for _, v := range urls {
			//去掉最后的!后面部分
			l := v
			//判断扩展名是否合法
			ext := l[strings.LastIndex(l, ".")+1:]

			if strings.Contains(allowImageType, ext) {
				//获取文件名
				filename := l[strings.LastIndex(l, "/")+1:]
				newname := strconv.FormatInt(time.Now().Unix(), 10) + "_" + filename
				res, err := http.Get(l)
				defer res.Body.Close()
				if err != nil {
					callbackjson += "{\"url\": \"\",\"source\": \"" + l + "\",\"state\": \"ERROR\"},"
					fmt.Println("Error:远程抓取失败;", err)
				} else {
					dst, err := os.Create(uploadimage + newname)
					if err != nil {
						callbackjson += "{\"url\": \"\",\"source\": \"" + l + "\",\"state\": \"ERROR\"},"
						fmt.Println("Error:保存失败;", err)
					} else {
						callbackjson += "{\"url\": \"" + uploadimage + newname + "\",\"source\": \"" + l + "\",\"state\": \"SUCCESS\"},"
						io.Copy(dst, res.Body)
					}
				}

			} else {
				callbackjson += "{\"url\": \"\",\"source\": \"" + l + "\",\"state\": \"ERROR\"},"
			}
			//fmt.Println(l)
		}
	}
	callbackjson += "]}"
	this.Ctx.WriteString(callbackjson)
	this.StopRun()
	return
}
Esempio n. 3
0
// 解析数组
func (this *Member) BaseFormStrings(contro *beego.Controller) (bool, interface{}) {
	this.Power = contro.GetStrings("po")

	return true, nil
}
Esempio n. 4
0
//获取广告内容
func GetAdsDetail(c *beego.Controller) string {
	str := ""
	tip := &models.TipJSON{}
	tip.Status = models.TipError
	tid, _ := strconv.ParseInt(c.GetString("Tid"), 10, 64)
	switch tid {
	case 0: //代码
		script := &models.ScriptAds{}
		script.Content = c.GetString("txtScript")
		if script.Content == "" {
			tip.Message = "代码不能为空!"
			EchoTip(c, tip)
		}
		arrstr, _ := json.Marshal(script)
		str = string(arrstr)
	case 1: //文字
		text := &models.TextAds{}
		text.Txt = c.GetString("txt_Txt")
		text.Link = c.GetString("txt_Txt")
		text.Style = c.GetString("txt_Style")
		if text.Txt == "" {
			tip.Message = "文字内容不能为空!"
			EchoTip(c, tip)
		}
		if text.Link == "" {
			tip.Message = "文字链接不能为空!"
			EchoTip(c, tip)
		}
		arrstr, _ := json.Marshal(text)
		str = string(arrstr)
	case 2: //图片类
		img := &models.ImgAds{}
		img.Img = c.GetString("img_Img")
		img.Alt = c.GetString("img_Alt")
		img.Link = c.GetString("img_Link")
		img.Height, _ = strconv.ParseInt(c.GetString("img_Height"), 10, 64)
		img.Width, _ = strconv.ParseInt(c.GetString("img_Width"), 10, 64)
		if img.Img == "" {
			tip.Message = "图片地址不能为空!"
			EchoTip(c, tip)
		}
		if img.Link == "" {
			tip.Message = "图片链接不能为空!"
			EchoTip(c, tip)
		}
		arrstr, _ := json.Marshal(img)
		str = string(arrstr)
	case 3: //Flash
		flash := &models.FlashAds{}
		flash.Swf = c.GetString("flash_Swf")
		flash.Height, _ = strconv.ParseInt(c.GetString("flash_Height"), 10, 64)
		flash.Width, _ = strconv.ParseInt(c.GetString("flash_Width"), 10, 64)
		if flash.Swf == "" {
			tip.Message = "Flash 地址不能为空!"
			EchoTip(c, tip)
		}
		arrstr, _ := json.Marshal(flash)
		str = string(arrstr)
	case 4: //幻灯片
		sw, _ := strconv.ParseInt(c.GetString("slide_Width"), 10, 64)
		sh, _ := strconv.ParseInt(c.GetString("slide_Height"), 10, 64)
		SImg := c.GetStrings("slide_Img")
		SLink := c.GetStrings("slide_Link")
		SAlt := c.GetStrings("slide_Alt")
		if len(SImg) <= 0 {
			tip.Message = "幻灯片图片不能为空!"
			EchoTip(c, tip)
		}
		if len(SLink) <= 0 {
			tip.Message = "幻灯片图片链接不能为空!"
			EchoTip(c, tip)
		}
		length := len(SImg)
		listImg := []*models.ImgAds{}
		for i := 0; i < length; i++ {
			tmp := models.ImgAds{}
			if SImg[i] != "" && SLink[i] != "" {
				tmp.Img = SImg[i]
				tmp.Link = SLink[i]
				tmp.Alt = SAlt[i]
				tmp.Height = sh
				tmp.Width = sw
				listImg = append(listImg, &tmp)
			}
		}
		if listImg == nil || len(listImg) <= 0 {
			tip.Message = "幻灯片请最少设置一个图片!"
			EchoTip(c, tip)
		}
		arrstr, _ := json.Marshal(listImg)
		str = string(arrstr)
	}
	return str
}