Beispiel #1
0
func (self *BaseHandler) checkSign(form url.Values, appid, appsecret string) bool {
	for _, key := range []string{"appid", "sign_method", "sign", "timestamp"} {
		//如果不存在以上的key,则验证失败
		if ok, err := goutils.Contains(key, form); !ok && err == nil {
			return false
		}
	}
	dict := map[string]string{}
	for k, v := range form {
		if len(v) != 1 {
			return false
		}
		if k == "appid" {
			if v[0] != appid {
				return false
			}
		}
		if k != "sign" {
			dict[k] = v[0]
		}
	}
	checkstr := appsecret + goutils.MapDictSortToStr(dict) + appsecret
	//生成sign 验证是否与发过来的sign是否一致
	sign := form["sign"][0]
	var mysign string
	switch dict["sign_method"] {
	case "md5":
		mysign = goutils.Md5(checkstr)
	}
	if sign != mysign {
		return false
	}
	return true
}
Beispiel #2
0
//检测settings文件
func CheckSettings(settings map[string]string) (string, bool) {
	for _, key := range []string{"DEBUG", "DBINFO", "HOST", "PORT", "DICT", "STOP", "INDEXSTORENUM", "APPID", "APPSECRET", "STATIC", "NOVELPIC"} {
		if ok, _ := goutils.Contains(key, settings); !ok {
			return key, false
		}
	}
	return "", true
}