private void CheckNotifySign(WeChatPayNotify notify, WeChatPayOptions options) { if (string.IsNullOrEmpty(notify.Body)) { throw new WeChatPayException("sign check fail: Body is Empty!"); } if (notify.Parameters.Count == 0) { throw new WeChatPayException("sign check fail: Parameters is Empty!"); } if (!notify.Parameters.TryGetValue("sign", out var sign)) { throw new WeChatPayException("sign check fail: sign is Empty!"); } var cal_sign = WeChatPaySignature.SignWithKey(notify.Parameters, options.Key, WeChatPaySignType.MD5); if (cal_sign != sign) { throw new WeChatPayException("sign check fail: check Sign and Data Fail!"); } }
private void CheckResponseSign(WeChatPayResponse response, WeChatPayOptions options, WeChatPaySignType signType) { if (string.IsNullOrEmpty(response.Body)) { throw new WeChatPayException("sign check fail: Body is Empty!"); } if (response.Parameters.TryGetValue(WeChatPayConsts.return_code, out var return_code)) { if (return_code == WeChatPayCode.Success) { if (!response.Parameters.TryGetValue(WeChatPayConsts.sign, out var sign)) { throw new WeChatPayException("sign check fail: sign is Empty!"); } var cal_sign = WeChatPaySignature.SignWithKey(response.Parameters, options.Key, signType); if (cal_sign != sign) { throw new WeChatPayException("sign check fail: check Sign and Data Fail!"); } } } }