public void PrimaryHandler(WeChatPayOptions options, WeChatPaySignType signType, WeChatPayDictionary sortedTxtParams) { sortedTxtParams.Add(WeChatPayConsts.nonce_str, WeChatPayUtility.GenerateNonceStr()); sortedTxtParams.Add(WeChatPayConsts.appid, options.AppId); sortedTxtParams.Add(WeChatPayConsts.mch_id, options.MchId); sortedTxtParams.Add(WeChatPayConsts.sign, WeChatPaySignature.SignWithKey(sortedTxtParams, options.Key, signType)); }
public void PrimaryHandler(WeChatPayOptions options, WeChatPaySignType signType, WeChatPayDictionary sortedTxtParams) { sortedTxtParams.Add(WeChatPayConsts.nonce_str, WeChatPayUtility.GenerateNonceStr()); sortedTxtParams.Add(WeChatPayConsts.mch_id, options.MchId); if (signType == WeChatPaySignType.HMAC_SHA256) { sortedTxtParams.Add(WeChatPayConsts.sign_type, WeChatPayConsts.HMAC_SHA256); } }
public void PrimaryHandler(WeChatPayOptions options, WeChatPaySignType signType, WeChatPayDictionary sortedTxtParams) { sortedTxtParams.Add(WeChatPayConsts.nonce_str, WeChatPayUtility.GenerateNonceStr()); sortedTxtParams.Add(WeChatPayConsts.appid, options.AppId); sortedTxtParams.Add(WeChatPayConsts.sub_appid, options.SubAppId); sortedTxtParams.Add(WeChatPayConsts.mch_id, options.MchId); sortedTxtParams.Add(WeChatPayConsts.sub_mch_id, options.SubMchId); if (signType == WeChatPaySignType.HMAC_SHA256) { sortedTxtParams.Add(WeChatPayConsts.sign_type, WeChatPayConsts.HMAC_SHA256); } sortedTxtParams.Add(WeChatPayConsts.sign, WeChatPaySignature.SignWithKey(sortedTxtParams, options.APIKey, signType)); }
public void PrimaryHandler(WeChatPayOptions options, WeChatPaySignType signType, WeChatPayDictionary sortedTxtParams) { if (string.IsNullOrEmpty(options.RsaPublicKey)) { throw new WeChatPayException($"{nameof(WeChatPayPayBankRequest)}.{nameof(PrimaryHandler)}: {nameof(options.RsaPublicKey)} is null or empty!"); } sortedTxtParams.Add(WeChatPayConsts.nonce_str, WeChatPayUtility.GenerateNonceStr()); sortedTxtParams.Add(WeChatPayConsts.mch_id, options.MchId); sortedTxtParams.Add(WeChatPayConsts.enc_bank_no, OaepSHA1WithRSA.Encrypt(BankNo, options.RsaPublicKey)); sortedTxtParams.Add(WeChatPayConsts.enc_true_name, OaepSHA1WithRSA.Encrypt(TrueName, options.RsaPublicKey)); sortedTxtParams.Add(WeChatPayConsts.sign, WeChatPaySignature.SignWithKey(sortedTxtParams, options.Key, signType)); }
public static string SignWithKey(WeChatPayDictionary dictionary, string key, WeChatPaySignType signType) { var sb = new StringBuilder(); foreach (var iter in dictionary) { if (!string.IsNullOrEmpty(iter.Value) && iter.Key != WeChatPayConsts.sign) { sb.Append(iter.Key).Append('=').Append(iter.Value).Append("&"); } } var signContent = sb.Append("key=").Append(key).ToString(); return(signType switch { WeChatPaySignType.MD5 => MD5.Compute(signContent).ToUpperInvariant(), WeChatPaySignType.HMAC_SHA256 => HMAC_SHA256.Compute(signContent, key).ToUpperInvariant(), _ => throw new WeChatPayException("Unknown sign type!"), });
public void PrimaryHandler(WeChatPayOptions options, WeChatPaySignType signType, WeChatPayDictionary sortedTxtParams) { sortedTxtParams.Add(WeChatPayConsts.nonce_str, WeChatPayUtility.GenerateNonceStr()); sortedTxtParams.Add(WeChatPayConsts.wxappid, options.AppId); sortedTxtParams.Add(WeChatPayConsts.mch_id, options.MchId); var signList = new List <string> { "act_name", "mch_billno", "mch_id", "nonce_str", "re_openid", "total_amount", "wxappid", }; sortedTxtParams.Add(WeChatPayConsts.workwx_sign, WeChatPaySignature.SignWithSecret(sortedTxtParams, options.AppSecret, signList)); sortedTxtParams.Add(WeChatPayConsts.sign, WeChatPaySignature.SignWithKey(sortedTxtParams, options.Key, signType)); }
public void PrimaryHandler(WeChatPayOptions options, WeChatPaySignType signType, WeChatPayDictionary sortedTxtParams) { if (string.IsNullOrEmpty(options.RsaPublicKey)) { throw new WeChatPayException("WeChatPayPayBankRequest: RsaPublicKey is null!"); } sortedTxtParams.Add(WeChatPayConsts.nonce_str, WeChatPayUtility.GenerateNonceStr()); sortedTxtParams.Add(WeChatPayConsts.mch_id, options.MchId); var no = OaepSHA1WithRSA.Encrypt(sortedTxtParams.GetValue(WeChatPayConsts.enc_bank_no), options.RsaPublicKey); sortedTxtParams.SetValue(WeChatPayConsts.enc_bank_no, no); var name = OaepSHA1WithRSA.Encrypt(sortedTxtParams.GetValue(WeChatPayConsts.enc_true_name), options.RsaPublicKey); sortedTxtParams.SetValue(WeChatPayConsts.enc_true_name, name); sortedTxtParams.Add(WeChatPayConsts.sign, WeChatPaySignature.SignWithKey(sortedTxtParams, options.Key, signType)); }
public void PrimaryHandler(WeChatPayOptions options, WeChatPaySignType signType, WeChatPayDictionary sortedTxtParams) { sortedTxtParams.Add(WeChatPayConsts.nonce_str, WeChatPayUtility.GenerateNonceStr()); sortedTxtParams.Add(WeChatPayConsts.appid, options.AppId); sortedTxtParams.Add(WeChatPayConsts.mch_id, options.MchId); var signList = new List<string> { "amount", "appid", "desc", "mch_id", "nonce_str", "openid", "partner_trade_no", "ww_msg_type", }; sortedTxtParams.Add(WeChatPayConsts.workwx_sign, WeChatPaySignature.SignWithSecret(sortedTxtParams, options.Secret, signList)); sortedTxtParams.Add(WeChatPayConsts.sign, WeChatPaySignature.SignWithKey(sortedTxtParams, options.Key, signType)); }
public void SetSignType(WeChatPaySignType signType) { this.signType = signType; }
private static 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.APIKey, signType); 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.ResponseBody)) { throw new WeChatPayException("sign check fail: Body is Empty!"); } if (response.ResponseParameters.Count == 0) { throw new WeChatPayException("sign check fail: Parameters is Empty!"); } if (response.ResponseParameters["return_code"] == "SUCCESS") { if (!response.ResponseParameters.TryGetValue("sign", out var sign)) { throw new WeChatPayException("sign check fail: sign is Empty!"); } var cal_sign = WeChatPaySignature.SignWithKey(response.ResponseParameters, options.Key, signType); if (cal_sign != sign) { throw new WeChatPayException("sign check fail: check Sign and Data Fail!"); } } }