由于工作需要,开了一个C#(Winform)+H5(Html)的微信/支付宝对接接口,需要使用的小伙伴可通过链接进行下载,欢迎各位小伙伴交流探讨。
-
测试链接:http://dumikj.com/pay.html (必须用手机浏览器打开)
-
支付页面
- 后台服务
- 支付相关信息存储表
- 核心代码
[HttpPost]
public PayResponse pay(PayRequest request)
{
PayResponse response = new PayResponse();
response.isSuccess = false;
response.errorMsg = "";
try
{
LogHelper.LogHelper.AddShowLog("Request:" + Serializer<PayRequest>(request));
request = GetPayDefaultParam(request);
decimal realMoney = request.amount;
CreatePayRecord(request.pforder, request.amount, realMoney, request.rolename, request.roleid, request.serverid, request.payType);
checkSing(request);
string returnUrl = request.returnurl;
string notifyUrl = request.notifyurl;
string productInfo = "game";
string orderId = request.pforder;
decimal totalFee = realMoney;
notifyUrl = System.Web.HttpUtility.UrlDecode(notifyUrl);
returnUrl = System.Web.HttpUtility.UrlDecode(returnUrl);
if (request.payType == 1)
{
response.url = WxH5Service.GetRequestUrl(returnUrl,
notifyUrl,
orderId,
totalFee,
productInfo,
request.mch_id,
request.appid,
request.appsecret);
}
else if (request.payType == 2)
{
response.url = AliWAPService.GetRequestUrl(returnUrl,
notifyUrl,
orderId,
totalFee,
productInfo,
request.appid,
request.signkey,
request.appsecret);
}
else
{
response.errorMsg = "不支持的支付方式" + request.payType;
}
if (data.ContainsKey(request.appid))
{
decimal amount = data[request.appid];
amount += request.amount;
data[request.appid] = amount;
}
else
{
data.Add(request.appid, request.amount);
}
string json = Serializer(data);
File.WriteAllText(filePath, json);
response.isSuccess = true;
LogHelper.LogHelper.AddShowLog("Response:" + Serializer<PayResponse>(response));
}
catch (Exception ex)
{
response.errorMsg = ex.Message;
}
response.sign = GetResponseSign(response);
return response;
}
-
源码文件清单
-
源码下载链接
https://download.csdn.net/download/qq_27352959/15639776