public async Task <T> ExecuteAsync <T>(IJDPayNPP10Request <T> request, JDPayOptions options) where T : JDPayResponse { var sortedTxtParams = new JDPayDictionary(request.GetParameters()) { { JDPayContants.CUSTOMER_NO, options.CustomerNo }, { JDPayContants.SIGN_TYPE, options.SignType } }; var isEncrypt = false; if (request is JDPayDefrayPayRequest) { isEncrypt = true; } var encryptDic = JDPaySecurity.EncryptData(options.PrivateCret, options.Password, options.PublicCert, sortedTxtParams, options.SingKey, options.EncryptType, isEncrypt); var content = JDPayUtility.BuildQuery(encryptDic); using (var client = _httpClientFactory.CreateClient(nameof(JDPayClient))) { var body = await client.DoPostAsync(request.GetRequestUrl(), content, "application/x-www-form-urlencoded"); // 验签 var dictionary = JsonConvert.DeserializeObject <JDPayDictionary>(body); if (!JDPaySecurity.VerifySign(dictionary, options.SingKey)) { throw new JDPayException("sign check fail: check Sign and Data Fail!"); } var rsp = JsonConvert.DeserializeObject <T>(body); rsp.Body = body; return(rsp); } }
private void CheckNotifyDefrayPaySign(JDPayDictionary parameters) { if (parameters.Count == 0) { throw new Exception("sign check fail: parameters is Empty!"); } if (!parameters.TryGetValue(JDPayContants.SIGN_DATA, out var sign_data)) { throw new Exception("sign check fail: sign is Empty!"); } if (!JDPaySecurity.VerifySign(parameters, Options.SingKey)) { throw new Exception("sign check fail: check Sign and Data Fail!"); } }
private void CheckNotifyDefrayPaySign(JDPayDictionary dictionary, JDPayOptions options) { if (dictionary.Count == 0) { throw new JDPayException("sign check fail: dictionary is Empty!"); } if (!dictionary.TryGetValue(JDPayContants.SIGN_DATA, out var sign_data)) { throw new JDPayException("sign check fail: sign is Empty!"); } if (!JDPaySecurity.VerifySign(dictionary, options.SingKey)) { throw new JDPayException("sign check fail: check Sign and Data Fail!"); } }
public async Task <T> ExecuteAsync <T>(IJDPayNPP10Request <T> request) where T : JDPayResponse { var sortedTxtParams = new JDPayDictionary(request.GetParameters()) { { Contants.CUSTOMER_NO, Options.CustomerNo }, { Contants.SIGN_TYPE, Options.SignType } }; var isEncrypt = false; if (request is JDPayDefrayPayRequest) { isEncrypt = true; } var encryptDic = JDPaySecurity.EncryptData(Options.PrivateCret, Options.Password, Options.PublicCert, sortedTxtParams, Options.SingKey, Options.EncryptType, isEncrypt); var content = HttpClientEx.BuildQuery(encryptDic); Logger?.LogTrace(0, "Request:{content}", content); var body = await Client.DoPostAsync(request.GetRequestUrl(), content, "application/x-www-form-urlencoded"); Logger?.LogTrace(1, "Response:{content}", body); var rsp = JsonConvert.DeserializeObject <T>(body); // 验签 var dic = JsonConvert.DeserializeObject <JDPayDictionary>(body); if (!JDPaySecurity.VerifySign(dic, Options.SingKey)) { throw new Exception("sign check fail: check Sign and Data Fail!"); } rsp.Body = body; return(rsp); }