123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- using System.Text;
- using System.Net.Cache;
- using System.Security.Cryptography.X509Certificates;
- using System;
- using Aop.Api;
- using WingServerCommon.Config;
- using WingServerCommon.Config.Parameters;
- using Aop.Api.Request;
- using Newtonsoft.Json;
- using Aop.Api.Domain;
- using System.Collections.Generic;
- using WingServerCommon.Log;
- using WingServerCommon.Utilities;
- using Aop.Api.Response;
- using System.Net;
- using System.Web;
- namespace WingPaymentService.Common
- {
-
-
-
- public class AlipayCommon
- {
- private string _gatewayHost => EnvironmentConfigManager.GetParammeter<StringParameter>("Alipay", "GatewayHost").Value;
- private string _signType => EnvironmentConfigManager.GetParammeter<StringParameter>("Alipay", "SignType").Value;
- private string _appId => EnvironmentConfigManager.GetParammeter<StringParameter>("Alipay", "AppId").Value;
- private string _merchantPrivateKey => EnvironmentConfigManager.GetParammeter<StringParameter>("Alipay", "MerchantPrivateKey").Value;
- private string _alipayPublicKey => EnvironmentConfigManager.GetParammeter<StringParameter>("Alipay", "AlipayPublicKey").Value;
- private string _merchantCertPath => EnvironmentConfigManager.GetParammeter<StringParameter>("Alipay", "MerchantCertPath").Value;
- private string _certPath => EnvironmentConfigManager.GetParammeter<StringParameter>("Alipay", "AlipayCertPath").Value;
- private string _rootCertPath => EnvironmentConfigManager.GetParammeter<StringParameter>("Alipay", "AlipayRootCertPath").Value;
- private string _notifyUrl => EnvironmentConfigManager.GetParammeter<StringParameter>("Alipay", "NotifyUrl").Value;
-
-
-
-
-
-
-
-
- public (string, string) AlipayPagePay(string subject, double totalAmount, string recordCode, string payReturnUrl)
- {
- try
- {
- var serverUrl = $"{_gatewayHost}/gateway.do";
-
- AlipayTradePagePayModel model = new AlipayTradePagePayModel
- {
- Subject = subject,
- TotalAmount = totalAmount.ToString("0.00"),
- OutTradeNo = recordCode,
- ProductCode = "FAST_INSTANT_TRADE_PAY"
- };
-
- IAopClient client = new DefaultAopClient
- (
- serverUrl,
- _appId,
- _merchantPrivateKey,
- "json",
- "1.0",
- _signType,
- _alipayPublicKey,
- "utf-8"
- );
- Aop.Api.Request.AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
-
- request.SetNotifyUrl(_notifyUrl);
- request.SetProdCode("FAST_INSTANT_TRADE_PAY");
- request.SetBizModel(model);
- request.SetReturnUrl(payReturnUrl);
-
- Aop.Api.Response.AlipayTradePagePayResponse response = client.SdkExecute(request);
- if (!response.IsError)
- {
- var url = $"{serverUrl}?{response.Body}";
- Logger.WriteLineInfo($"AlipayWapPay success pay url:{url}");
- return (url, response.Body);
-
-
-
-
-
-
-
-
-
- }
- else
- {
- Logger.WriteLineError($"AlipayPagePay error:{response.Msg},{response.SubMsg}");
- return (string.Empty, response.Body);
- }
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"AlipayPagePay error:{ex}");
- return (string.Empty, $"AlipayPagePay error:{ex}");
- }
- }
-
-
-
-
-
-
-
- public (string, string) AlipayWapPay(string subject, double totalAmount, string recordCode, string payReturnUrl)
- {
- try
- {
- var serverUrl = $"{_gatewayHost}/gateway.do";
-
- AlipayTradeWapPayModel model = new AlipayTradeWapPayModel
- {
- Subject = subject,
- TotalAmount = totalAmount.ToString("0.00"),
- OutTradeNo = recordCode,
- ProductCode = "QUICK_WAP_WAY"
- };
-
- IAopClient client = new DefaultAopClient
- (
- _gatewayHost,
- _appId,
- _merchantPrivateKey,
- "json",
- "1.0",
- _signType,
- _alipayPublicKey,
- "utf-8"
- );
- Aop.Api.Request.AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
-
- request.SetNotifyUrl(_notifyUrl);
- request.SetProdCode("QUICK_WAP_WAY");
- request.SetBizModel(model);
- request.SetReturnUrl(payReturnUrl);
-
- Aop.Api.Response.AlipayTradeWapPayResponse response = client.SdkExecute(request);
- if (!response.IsError)
- {
- var url = $"{serverUrl}?{response.Body}";
- Logger.WriteLineInfo($"AlipayWapPay success pay url:{url}");
- return (url, response.Body);
-
-
-
-
-
-
-
-
-
-
- }
- else
- {
- Logger.WriteLineError($"AlipayWapPay error:{response.Msg},{response.SubMsg}");
- return (string.Empty, response.Body);
- }
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"AlipayWapPay error:{ex}");
- return (string.Empty, $"AlipayWapPay error:{ex}");
- }
- }
- }
- }
|