/// <summary> /// 验证安全信息是否合法 /// </summary> /// <param name="securityInfo">安全信息实体</param> /// <param name="registerInfo">注册信息实体</param> public void Validate(SecurityRequestInfo securityInfo, RegisterInfo registerInfo) { if (securityInfo == null) { throw new ArgumentNullException(nameof(securityInfo), "安全信息实体不可为空!"); } if (registerInfo == null) { throw new ArgumentNullException(nameof(registerInfo), "注册信息实体不可为空!"); } ValidateSecurityInfo(securityInfo); var sign = CreatSingData(securityInfo, registerInfo); if (sign != securityInfo.Signature) { throw new ArgumentException("签名验证错误!"); } }
/// <summary> /// 根据请求内容及注册信息,生成签名数据 /// </summary> /// <param name="securityInfo">安全信息实体</param> /// <param name="registerInfo">注册信息实体</param> /// <returns></returns> private static string CreatSingData(SecurityRequestInfo securityInfo, RegisterInfo registerInfo) { var content = $"{securityInfo.AppId}{securityInfo.TimeStamp}{securityInfo.RequestContent}{registerInfo.AppSecret}"; return(GetMD5(content)); }