public static void CheckResponseSign <T>(IAopRequest <T> request, string responseBody, bool isError, IAopParser <T> parser, string alipayPublicKey, string charset, string signType, bool keyFromFile) where T : AopResponse { if (string.IsNullOrEmpty(alipayPublicKey) || string.IsNullOrEmpty(charset)) { return; } SignItem signItem = parser.GetSignItem(request, responseBody); if (signItem == null) { throw new AopException("sign check fail: Body is Empty!"); } if ((!isError || (isError && !string.IsNullOrEmpty(signItem.Sign))) && !AlipaySignature.RSACheckContent(signItem.SignSourceDate, signItem.Sign, alipayPublicKey, charset, signType, keyFromFile)) { if (string.IsNullOrEmpty(signItem.SignSourceDate) || !signItem.SignSourceDate.Contains("\\/")) { throw new AopException("sign check fail: check Sign and Data Fail!"); } string signContent = signItem.SignSourceDate.Replace("\\/", "/"); if (!AlipaySignature.RSACheckContent(signContent, signItem.Sign, alipayPublicKey, charset, signType, keyFromFile)) { throw new AopException("sign check fail: check Sign and Data Fail JSON also"); } } }
public static void CheckResponseSign <T>(IAopRequest <T> request, string responseBody, bool isError, IAopParser <T> parser, string alipayPublicKey, string charset, string signType) where T : AopResponse { if (string.IsNullOrEmpty(alipayPublicKey) || string.IsNullOrEmpty(charset)) { return; } var signItem = parser.GetSignItem(request, responseBody); if (signItem == null) { throw new AopException("sign check fail: Body is Empty!"); } if (!isError || isError && !string.IsNullOrEmpty(signItem.Sign)) { var rsaCheckContent = AlipaySignature.RSACheckContent(signItem.SignSourceDate, signItem.Sign, alipayPublicKey, charset, signType); if (!rsaCheckContent) { if (!string.IsNullOrEmpty(signItem.SignSourceDate) && signItem.SignSourceDate.Contains("\\/")) { var srouceData = signItem.SignSourceDate.Replace("\\/", "/"); var jsonCheck = AlipaySignature.RSACheckContent(srouceData, signItem.Sign, alipayPublicKey, charset, signType); if (!jsonCheck) { throw new AopException( "sign check fail: check Sign and Data Fail JSON also"); } } else { throw new AopException( "sign check fail: check Sign and Data Fail!"); } } } }