调用支付宝支付(C#)

2021-06-21 16:04

阅读:535

标签:pid   soft   api   mount   subject   蚂蚁金服   应用   vat   文档   

//支付宝支付
public string AliPay(string OrderID, string Total) //OrderID订单号,Total订单总金额
{

// 支付宝网关
string Url = "https://openapi.alipay.com/gateway.do";
string APPID = "2016080180820878";

//开发者应用私钥,由支付宝密钥生成工具生成 商户应用私钥 蚂蚁金服后台商户应用公钥与支付宝密钥生成工具商户应用公钥匹配一致
string APP_PRIVATE_KEY = "开发者应用私钥";

//参数返回格式,只支持json
string FORMAT = "json";

//请求和签名使用的字符编码格式,支持GBK和UTF-8
string CHARSET = "UTF-8";

//支付宝公钥,由支付宝生成到蚂蚁金服复制
string zhifubao_public_key = "支付宝公钥";

DefaultAopClient client = new DefaultAopClient(Url, APPID, APP_PRIVATE_KEY, FORMAT, "1.0", "RSA2", zhifubao_public_key, CHARSET, false);


// 外部订单号,商户网站订单系统中唯一的订单号
string out_trade_no = OrderID.Trim();

// 订单名称
string subject = "订单" + OrderID + "支付";

// 付款金额
string total_amout = Total.Trim().ToString();

// 商品描述
string body = "订单" + OrderID + "支付";

// 支付中途退出返回商户网站地址
string quit_url = "url";

#region -----API日志----
Maticsoft.BLL.Shop_Apilog Bll_Api = new Maticsoft.BLL.Shop_Apilog();
Maticsoft.Model.Shop_Apilog Api = new Maticsoft.Model.Shop_Apilog();
Api.ApiName = "https://openapi.alipay.com/gateway.do";
Api.ReTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff");
Api.Method = "支付宝支付"+OrderID;
#endregion

// 组装业务参数model
AlipayTradeWapPayModel model = new AlipayTradeWapPayModel();
model.Body = body;
model.Subject = subject;
model.TotalAmount = total_amout;
model.OutTradeNo = out_trade_no;
model.ProductCode = "QUICK_WAP_WAY";
model.QuitUrl = quit_url;

AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
// 设置支付完成同步回调地址
request.SetReturnUrl("回调地址");
// 设置支付完成异步通知接收地址
request.SetNotifyUrl("异步通知接收地址");
// 将业务model载入到request
request.SetBizModel(model);

AlipayTradeWapPayResponse response = null;
try
{
response = client.pageExecute(request, null, "post");
Api.ApiInfo = response.Body;
Bll_Api.Add(Api);

return response.Body;
}
catch (Exception exp)
{
throw exp;
}
}

具体请看支付宝开发文档:https://openhome.alipay.com/developmentDocument.htm

调用支付宝支付(C#)

标签:pid   soft   api   mount   subject   蚂蚁金服   应用   vat   文档   

原文地址:https://www.cnblogs.com/Lance88/p/10234875.html


评论


亲,登录后才可以留言!