示例#1
0
文件: sign.go 项目: yearnfar/gocms
func CheckSign(form url.Values, jsonStream map[string]interface{}, excludeFields []string) bool {
	params := map[string]string{}
	if len(form) > 0 {
		if len(excludeFields) == 0 {
			for k, v := range form {
				params[k] = v[0]
			}
		} else {
			for k, v := range form {
				if !utils.InSlice(k, excludeFields) {
					params[k] = v[0]
				}
			}
		}
	} else {
		if len(excludeFields) == 0 {
			for k, v := range jsonStream {
				params[k] = fmt.Sprintf("%v", v)
			}
		} else {
			for k, v := range jsonStream {
				if !utils.InSlice(k, excludeFields) {
					params[k] = fmt.Sprintf("%v", v)
				}
			}
		}
	}

	inputSign := ""
	if v, ok := params["sign"]; ok {
		inputSign = v
		delete(params, "sign")
	}

	if "" == inputSign {
		return false
	}

	sign := BuildSign(params)

	beego.Debug("input sign:", inputSign)
	beego.Debug("new   sign:", sign)

	if inputSign == sign {
		return true
	}

	return false
}
示例#2
0
文件: ip.go 项目: yearnfar/gocms
func ParseQQWryAreaInfo(area string) (province, city, district string) {
	areaArr := []rune(area)
	l := len(areaArr)
	if l == 0 {
		return
	}

	pos := 2

	pro := string(areaArr[0:pos])
	if utils.InSlice(pro, provinces) {
		province = pro
		if string(areaArr[pos:getPos(pos+1, l)]) == "省" {
			pos += 1
		}

	} else if pro == "内蒙" {
		province = pro + "古"
		pos += 1

	} else if pro == "黑龙" {
		province = pro + "江"
		pos += 1
		if string(areaArr[pos:getPos(pos+1, l)]) == "省" {
			pos += 1
		}
	}
	if province == "" {
		return
	}

	if province == "北京" || province == "天津" || province == "上海" || province == "重庆" {
		city = province
		if string(areaArr[pos:getPos(pos+1, l)]) == "市" {
			pos += 1
		}

	} else {

		suffix := "自治州"
		step := 3
		cityPos := utils.StringIndex(area, suffix)

		if cityPos == -1 {
			suffix = "盟"
			cityPos = utils.StringIndex(area, suffix)
			step = 1
		}

		if cityPos == -1 {
			suffix = ""
			cityPos = utils.StringIndex(area, "市")
			step = 1
		}

		if cityPos > pos {
			city = string(areaArr[pos:getPos(cityPos, l)]) + suffix
			pos = cityPos + step
		}
	}

	if city == "" {
		city = string(areaArr[pos:l])
	} else {
		district = string(areaArr[pos:l])
	}

	return
}