public async Task Test3() { var config = new AlipayConfig { NotifyUrl = "", AppId = "", PrivateKey = "", AliPublicKey = "", QuitUrl = "" }; var request = new AlipayTradeQueryModel { OutTradeNo = "202007297777" }; var response = await AlipayClient.OrderQueryAsync(request, config); if (string.IsNullOrEmpty(response.Body)) { Assert.Fail(); } else { Assert.Pass(); } }
public void Test1() { var config = new AlipayConfig { NotifyUrl = "", AppId = "", PrivateKey = "", AliPublicKey = "" }; var request = new AlipayTradeAppPayModel { Body = "产品", Subject = "产品", OutTradeNo = "202007297777", TimeoutExpress = "15m", TotalAmount = $"{10:0.##}", ProductCode = AlipayConstants.QUICK_MSECURITY_PAY }; var response = AlipayClient.CreateOrder(request, config); if (string.IsNullOrEmpty(response.Body)) { Assert.Fail(); } else { Assert.Pass(); } }
public async Task Test2() { var config = new AlipayConfig { NotifyUrl = "", AppId = "", PrivateKey = "", AliPublicKey = "", QuitUrl = "" }; var request = new AlipayTradeWapPayModel { Body = "产品", Subject = "产品", OutTradeNo = "202007297777", TimeoutExpress = "15m", TotalAmount = $"{10:0.##}", QuitUrl = config.QuitUrl, ProductCode = AlipayConstants.QUICK_WAP_WAY }; var response = await AlipayClient.CreateOrderAsync(request, config); if (string.IsNullOrEmpty(response.Body)) { Assert.Fail(); } else { Assert.Pass(); } }
public void Test4() { var data = "{}";//json请求数据 var request = new AlipayData(); request.FromJson(data); var config = new AlipayConfig { NotifyUrl = "", AppId = "", PrivateKey = "", AliPublicKey = "", QuitUrl = "" }; var response = AlipayClient.Notify(request, config); if (string.IsNullOrEmpty(response.OutTradeNo)) { Assert.Fail(); } else { Assert.Pass(); } }
public async Task Test5() { var config = new AlipayConfig { NotifyUrl = "", AppId = "", PrivateKey = "", AliPublicKey = "", QuitUrl = "" }; var request = new AlipayTradeRefundModel { OutTradeNo = "202007297777", RefundAmount = $"{10:0.##}" }; var response = await AlipayClient.RefundAsync(request, config); if (string.IsNullOrEmpty(response.Body)) { Assert.Fail(); } else { Assert.Pass(); } }
public async Task <IActionResult> Alipay() { var config = new AlipayConfig { NotifyUrl = "http://mobiletest.emoney.cn/mdata/payment/api/alipay/alipaynotity", AppId = "2015072000178264", PrivateKey = "MIIEowIBAAKCAQEA92h++oFzk59dB+Xjcn+QsXMcMFREsMq1CqBXd1G8l+5wjDKetmoCbXNU3beZtWL+6XuetfPa2tmOR42v1zJeKODid5+tvgBe0ecJvgmxmSQ3al7gAu2mMnwzY6jkhl8kMG9CCUUs5PTQXAeDc5oSoXzfX06xgbCf4D4NRlRwPU5Ff3QVqlZ1desEczubyuhE7dl0pf+/Y6FB1NMTvB1MEX6PQ0ygVqe2i32ugCT/Fq2yf1UNwU6VXqOmX14mF/ZKxhWLn5bW3PVtvQkZQqR1Wtr5pNYDJ91XoKLraeSzH8fbLuxMGfwgflskMGwhMrmt69wRa5+Gc/5TdtgdLH648QIDAQABAoIBADWi8eRdLDFU21ZbAHRSM4xE6FeR7VJmn9kt6ch0b+6AQuYiE0Z4tQ4FcuCebTRlwd3cbwwDUe8gOzhH/1coFEHIf1BvzbrjWasn63THpTkOIPVunCIGY4GOa5Wvh9uZxL67YBWiaZk5efJ5roXhYSihacu/w7vaDs8OpNIafDrN0CE7KKxwo21sxR6++CikPV3ecs1lepKuiGmxSfUlZQ0LIK2kf0nt5JxAkcCmofW5wfTEQ3jD1ogdPtnqenGHqLONPU9vJ/onGLle8zu4K6m1FsIDFmpY/G9CAUDFE/Mkue6jmTFnMzSdEfQyA4mLqiSryerppzkF1eLsShUpAAECgYEA/2JrP8OzE0O3N0sMT0/KwMPrMKlz94GnLAd+YPs3Rf6c5UUEJCBgOo7wSrssvbeTg2r9K9xh9ROTsl6sIL6yAsisaIIAAqDhoMjMwoFVNPiln7qxhSi2FviJMD5fFDdNj1T8BjwOSl3iZnpUAGlebjBbH0qIFAOt/sLC9TVESLECgYEA+AEnys8efC1MQpIzf6i60DvhR88is0RoTLeI0AsAEwC3U6MXPkImW4P0WDdE5Ju4UNX2ARU5nJ5PQEUj0PPAWV+cJg7zPG1kLmMWomH4DjAIXrAE6rpDYfMVZcljzlPaWVcZpTNBW2Q25JuAD5G7LremKRJTFY/KS+WhB6a9hEECgYEA9e9JaPaFFSA46D6VdCtbDZeefhYxX0C0RGpTAgHqkLVJUmDMRB4JjVrpfI4T3/9RR1VYyUxJ6UEZEsSo7j+2HYgyv9GxQNa9caDtzsHN1F0+4jtfiORTtntRYewuk8FOJ6GnsjlTabpPtHBJRLwz+9kFZ3TW5q9Ed/oG1SyevYECgYBYloESTt3C2aNt/C9tIGZqz5jvP6xTgNII5V53ghZqs0zJEW7SDGsLMZ1sjYGMb5ttNKCFToGf0mTYvlnG3+sLgb2TUq/MG/83GqoRIxGqb7ntqM540kQTjvNLwp5mK0nJs/UzL5XfAXMiQfGCnjnQvEUcUrFe+Ff4uHPG+eakgQKBgAdQ24pGFdyC2gkwKPLPrvslfiuBxgvpsOqo0Jic+cK+QsORemqcKHM6RgwTPZ3ooaaaupjbERMTc0ykVJJGMCdnTINUwvyb2vR3p2a0PXMFVS/2OrIdRaMlmLX5BGVjupecE5wk+lEMjRWHrti4FrE8/yNMZNsFrBPxQBUGS8wr", AliPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxKydmUKMCWLIShH/t/67Rbn16ZrBNwANAJ6rdUGEB3cWUaLG4poXLZsd6B1roEYioLRGTerHFGfHzjsL0vzG1FSnBTRgBu/F1xqtSzvzh8P5qW9ObISwjiOA4ZfV63XL3WpTytR8lPyWYFUSLmMc2ofzAKUVVC4p5nMafJB306f21AXNS6//ulDnI4IhRl2kvBawOgBGpJ4kHJHm/qtZ0XDu5/+LiLm/Wvd2lBp1z3QsqTHLumR+w/4CeTH1R/YZXd3fUULqg/2lVEk9O8rIcYVtnMJ/oR/BRhQsCU5y3nvC3fPMOwVqlM8AUzrZvN7tjhxxdFPpyj/d0yTS9B8pwQIDAQAB" }; var data = new AlipayTradePrecreateModel { Body = "产品", Subject = "产品", OutTradeNo = $"em_{DateTime.Now.ToString("yyyyMMddHHmmss")}", TimeoutExpress = "15m", TotalAmount = $"{10:0.##}" }; var response = await AlipayClient.CreateOrderAsync(data, config); var ms = Convert.FromBase64String((await GetImage(response.QrCode)).Replace("data:image/jpeg;base64,", "")); return(File(ms, "image/png")); }
protected void Page_Load(object sender, EventArgs e) { string orderId = DateTime.Now.ToString("yyyyMMddHHmmssfff"); decimal paymentAmount = Convert.ToDecimal(0.01); string paymentType = "H5_A"; string productName = "Test Product"; string wap_URL = "http://m.babynaiba.com/alipay/index.aspx?orderId=" + orderId; Log.WriteLog("AliPay", "wap_URL is:" + wap_URL); string pay_URL = AlipayClient.GenerateH5URL(paymentType, orderId, paymentAmount, productName, wap_URL); Log.WriteLog("AliPay", "pay_URL is:" + pay_URL); Response.Write(pay_URL); }
public static async Task <AuthTokenResult> Request(this AlipayClient client, AuthTokenArg arg) { string text = JsonConvert.SerializeObject(arg); var http = new HttpClient(); var response = await http.PostAsync(client.Host, new StringContent(text)); if (response.StatusCode == HttpStatusCode.OK) { var content = await response.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <AuthTokenResult>(content)); } else { return(null); } }
public async Task Precreate() { string orderId = Guid.NewGuid().ToString().Replace("-", string.Empty); var content = new PrecreateContent { OutTradeNo = orderId, Subject = "Preceate Test" + orderId, TotalAmount = 1 }; var arg = new PrecreateArg { AppId = config.AppId, BizContent = content }; var client = new AlipayClient(); client.PrivateKey = @"D:\Programing\Dev Repos\ZeusPay\alipayPrivateKey.txt"; client.AlipayRootCertSN = GetCertSN(@"D:\Programing\Dev Repos\ZeusPay\alipayRootCert.crt"); client.AppCertSN = GetCertSN(@"D:\Programing\Dev Repos\ZeusPay\appCertPublicKey.crt"); client.UseProductEnv(); await PrecreateRequest.Request(client, arg); }
public async Task CreateToken() { var content = new AuthTokenContent { GrantType = AuthTokenRequest.authorization_code }; var arg = new AuthTokenArg { AppId = config.AppId, BizContent = content }; arg.SetRSA2Sign(@"D:\Programing\Dev Repos\ZeusPay\alipayPrivateKey.txt"); var client = new AlipayClient(); var result = await AuthTokenRequest.Request(client, arg); Assert.IsNotNull(result); if (result != null) { Assert.AreEqual(result.AlipayTradePrecreateResponse.Code, 10000); } }
public AlipayController(AlipayClient client, AlipayNotifyClient notifyClient) { _client = client; _notifyClient = notifyClient; }
public static async Task <PrecreateResult> Request(this AlipayClient client, PrecreateArg arg) { string text = JsonConvert.SerializeObject(arg); var jObj = (JObject)JsonConvert.DeserializeObject(text); JToken bizContent; if (!jObj.TryGetValue("bizContent", out bizContent)) { return(null); } jObj.Remove("bizContent"); var query = String.Join("&", jObj.Children().Cast <JProperty>() .OrderBy(c => c.Name) .Select(jp => jp.Name + "=" + jp.Value.ToString())); List <JToken> removeTokens = new List <JToken>(); foreach (var item in bizContent.Children().Cast <JProperty>()) { if (string.IsNullOrWhiteSpace(item.Value.ToString())) { removeTokens.Add(item); } } foreach (var item in removeTokens) { item.Remove(); } query += "&biz_content=" + bizContent.ToString().Replace("\r\n", ""); string pattern = "(?:^|&)[a-zA-Z_]+=(?=&|$)"; if (client.EncryptMode == EncryptMode.RSA2) { query += "&sign_type=RSA2"; } else if (client.EncryptMode == EncryptMode.RSA) { query += "&sign_type=RSA"; } query += $"&app_cert_sn={client.AppCertSN}&alipay_root_cert_sn={client.AlipayRootCertSN}"; Regex rgx = new Regex(pattern); text = rgx.Replace(query, ""); var queryString = HttpUtility.ParseQueryString(text); queryString.Remove("sign"); //queryString.Remove("biz_content"); var orderedKeys = queryString.Cast <string>().Where(k => k != null).OrderBy(k => k); text = string.Join("&", orderedKeys.Select(k => { if (k != "timestamp") { return(string.Format("{0}={1}", k, queryString[k].Replace(" ", ""))); } else { return(string.Format("{0}={1}", k, queryString[k])); } } )); text = text.Replace(" \"", ""); if (client.EncryptMode == EncryptMode.RSA2) { string sign = AlipaySignature.RSASignCharSet(text, client.PrivateKey, "GBK", "RSA2"); //string sign = AlipaySignature.RSASignCharSet(HttpUtility.HtmlEncode(text), client.PrivateKey, "utf-8", "RSA2"); query = text + $"&sign={sign}"; } else if (client.EncryptMode == EncryptMode.RSA) { string sign = AlipaySignature.RSASignCharSet(HttpUtility.HtmlEncode(text), client.PrivateKey, "GBK", "RSA"); query = text + $"&sign={sign}"; } queryString = HttpUtility.ParseQueryString(query); query = string.Join("&", queryString.Cast <string>().Select(k => string.Format("{0}={1}", k, HttpUtility.UrlEncode(queryString[k])))); var parameters = new Dictionary <string, string>(); foreach (var k in queryString.Cast <string>()) { parameters.Add(k, queryString[k]); } var encodedContent = new FormUrlEncodedContent(parameters); //.Select(jp => jp.Name + "=" + HttpUtility.UrlEncode(jp.Value.ToString()))); var http = new HttpClient(); //var response = await http.GetAsync(client.Host + "?" + query); var response = await http.PostAsync(client.Host, encodedContent); if (response.StatusCode == HttpStatusCode.OK) { var content = await response.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <PrecreateResult>(content)); } else { var content = await response.Content.ReadAsStringAsync(); return(null); } }