.NET C# 支付宝支付功能

//注意引用AopSdk NuGet程序包
#region 字段
 /// 
/// 沙箱地址
/// 
//serverUrl = "http://openapi.alipaydev.com/gateway.do";

 /// 
/// 线上地址
/// 
//public string serverUrl = "https://openapi.alipay.com/gateway.do";
/// 
/// 应用ID
/// 
public string appId = "";
/// 
/// 合作身份者ID
/// 
public string partner = "";
///  
/// 商户的私钥
/// 
public string private_key = @"";
///  
///支付宝的公钥,无需修改该值
/// 
public string public_key = @"";

/// 
/// 字符编码格式 目前支持 gbk 或 utf-8
/// 
public string input_charset = "utf-8";

/// 
/// 签名方式,选择项:RSA、DSA、MD5、RSA2、
/// 切记一定要注意选择的加密方式是RSA,还是RSA2。因为这两种方式生成的支付宝公匙是不一样的。RSA2对应的是2048位支付宝公匙。在配置类Config中,要根据加密方式配置支付宝公匙
/// 
public string sign_type = "RSA2";

/// 
/// 支付宝消息验证地址
/// 
private string Https_veryfy_url = "https://mapi.alipay.com/gateway.do?service=notify_verify&";
#endregion

/// 
/// 支付宝支付
/// 
/// 商品订单号
/// 金额
/// 返回结果
public AlipayTradeAppPayResponse AlipayPay(string order_no, int money)
{
  bool isUrl = false;
  //正式购买地址 沙盒购买地址
  string url_buy = "https://openapi.alipay.com/gateway.do";
  string url_sandbox = "http://openapi.alipaydev.com/gateway.do";
  string url = isUrl == false ? url_sandbox : url_buy;
  IAopClient client = new DefaultAopClient(url, appId, private_key, "json", "1.0", sign_type, public_key, input_charset, false);
  //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称如:alipay.trade.app.pay
  AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
  //SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
  var MainPath = System.Web.Configuration.WebConfigurationManager.AppSettings["MainPath"].ToString();
  AlipayTradeAppPayModel PayModel = new AlipayTradeAppPayModel();
  PayModel.Body = "我是测试数据";
  PayModel.Subject = "App支付测试DoNet";
  PayModel.TotalAmount = money + "0.00";
  PayModel.ProductCode = "QUICK_MSECURITY_PAY";
  PayModel.OutTradeNo = order_no;
  PayModel.TimeoutExpress = "30m";
  request.SetBizModel(PayModel);
  request.SetNotifyUrl(MainPath + "app/AliSecurity/notify_Url.aspx");//设置AOP的异步请求地址
  // request.SetReturnUrl("www.baidu.com");
  //这里和普通的接口调用不同,使用的是sdkExecute
  return client.SdkExecute(request);
}

你可能感兴趣的:(c#)