Commit 76f7c688 authored by 吴春's avatar 吴春

提交支付

parent 2341cf77
......@@ -92,31 +92,31 @@ namespace Mall.Common.Pay.WeChatPat
}
}
/// <summary>
/// 获取package带参数的签名包
/// </summary>
/// <returns></returns>
public string GetRequestURL()
{
this.CreateMd5Sign();
var sb = new StringBuilder();
var akeys = new ArrayList(Parameters.Keys);
akeys.Sort();
foreach (string k in akeys)
{
var v = (string)Parameters[k];
if (null != v && String.Compare("key", k, StringComparison.Ordinal) != 0)
{
sb.Append(k + "=" + UrlEncode(v, GetCharset()) + "&");
}
}
//去掉最后一个&
if (sb.Length > 0)
{
sb.Remove(sb.Length - 1, 1);
}
return sb.ToString();
}
///// <summary>
///// 获取package带参数的签名包
///// </summary>
///// <returns></returns>
//public string GetRequestURL()
//{
// this.CreateMd5Sign();
// var sb = new StringBuilder();
// var akeys = new ArrayList(Parameters.Keys);
// akeys.Sort();
// foreach (string k in akeys)
// {
// var v = (string)Parameters[k];
// if (null != v && String.Compare("key", k, StringComparison.Ordinal) != 0)
// {
// sb.Append(k + "=" + UrlEncode(v, GetCharset()) + "&");
// }
// }
// //去掉最后一个&
// if (sb.Length > 0)
// {
// sb.Remove(sb.Length - 1, 1);
// }
// return sb.ToString();
//}
......@@ -172,7 +172,7 @@ namespace Mall.Common.Pay.WeChatPat
/// 创建package签名,按参数名称a-z排序,遇到空值的参数不参加签名。
/// </summary>
/// <returns></returns>
public string CreateMd5Sign(IHttpContextAccessor accessor)
public string CreateMd5Sign(IHttpContextAccessor accessor, string WeChatApiSecret)
{
var sb = new StringBuilder();
var akeys = new ArrayList(Parameters.Keys);
......@@ -186,7 +186,8 @@ namespace Mall.Common.Pay.WeChatPat
sb.Append(k + "=" + v + "&");
}
}
sb.Append("key=" + GetKey());
// sb.Append("key=" + GetKey());
sb.Append("key=" + WeChatApiSecret);
var sign = Plugin.SecurityHelper.MD5EncryptWeChat(sb.ToString(), GetCharset(accessor)).ToUpper();
return sign;
}
......
......@@ -16,6 +16,7 @@ using Mall.Model.Entity.User;
using Mall.Common;
using Mall.Model.Extend.User;
using NPOI.SS.Formula.Functions;
using Org.BouncyCastle.Utilities.Net;
namespace Mall.WebApi.App_Code
{
......@@ -44,7 +45,7 @@ namespace Mall.WebApi.App_Code
/// <param name="CustomerId"></param>
/// <param name="openid"></param>
/// <returns></returns>
public static string GetMinUnifiedOrder(string sOrderNo, string sProductName, decimal dPrice, string CustomerId, string openid, RB_MiniProgram_Extend model, IHttpContextAccessor _accessor)
public static string GetMinUnifiedOrder(string sOrderNo, string sProductName, decimal dPrice, string CustomerId, string openid, RB_MiniProgram_Extend model, IHttpContextAccessor _accessor,string IPAddress)
{
var req = new Common.Pay.WeChatPat.RequestHandler();
req.SetKey(model.WeChatApiSecret);
......@@ -56,13 +57,13 @@ namespace Mall.WebApi.App_Code
req.SetParameter("attach", CustomerId);
req.SetParameter("out_trade_no", sOrderNo);
req.SetParameter("total_fee", (dPrice * 100).ToString("f0"));
req.SetParameter("spbill_create_ip", _accessor.HttpContext.Connection.RemoteIpAddress.ToString());
req.SetParameter("spbill_create_ip",IPAddress);
req.SetParameter("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));
req.SetParameter("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss"));
req.SetParameter("notify_url", Config.sTenpayNotify);
req.SetParameter("trade_type", "JSAPI");
req.SetParameter("openid", openid);
req.SetParameter("sign", req.CreateMd5Sign(_accessor));
req.SetParameter("sign", req.CreateMd5Sign(_accessor, model.WeChatApiSecret));
var reqXml = req.ParseXml();
var result = Common.Pay.WeChatPat.HttpHelper.Post(new HttpParam()
......@@ -77,12 +78,16 @@ namespace Mall.WebApi.App_Code
try
{
var prepayId = xe.GetElement("return_code").Value;
var prepayId = xe.GetElement("prepay_id").Value;
var payReq = new RequestHandler();
payReq.SetKey(model.WeChatApiSecret);
payReq.SetParameter("appId", model.MiniAppId);
payReq.SetParameter("timeStamp", GetTimestamp());
payReq.SetParameter("nonceStr", GetNoncestr());
payReq.SetParameter("package", "prepay_id=" + prepayId);
payReq.SetParameter("signType", "MD5");
//创建签名
payReq.SetParameter("sign", payReq.CreateMd5Sign(_accessor));
payReq.SetParameter("sign", payReq.CreateMd5Sign(_accessor, model.WeChatApiSecret));
var payReqXml = payReq.ParseXml();
var payReqJson = payReq.ParseJson();
return payReqJson;
......@@ -217,7 +222,7 @@ namespace Mall.WebApi.App_Code
packageReq.SetParameter("out_refund_no", param.RefundNumber);
packageReq.SetParameter("total_fee", (param.TotalFee.Value).ToString(System.Globalization.CultureInfo.InvariantCulture));
packageReq.SetParameter("refund_fee", param.RefundFee.Value.ToString(System.Globalization.CultureInfo.InvariantCulture));
packageReq.SetParameter("sign", packageReq.CreateMd5Sign(_accessor));
packageReq.SetParameter("sign", packageReq.CreateMd5Sign(_accessor, model.WeChatApiSecret));
var reqXml = packageReq.ParseXml();
var result = Common.Pay.WeChatPat.HttpHelper.Post(new HttpParam()
......@@ -277,7 +282,7 @@ namespace Mall.WebApi.App_Code
packageReq.SetParameter("appid", model.MiniAppId);
packageReq.SetParameter("mch_id", model.WeChatPayMerchants);
packageReq.SetParameter("nonce_str", GetNoncestr());
packageReq.SetParameter("sign", packageReq.CreateMd5Sign(_accessor));
packageReq.SetParameter("sign", packageReq.CreateMd5Sign(_accessor, model.WeChatApiSecret));
packageReq.SetParameter("out_refund_no", param.RefundNumber);//商户系统内部的退款单号
var reqXml = packageReq.ParseXml();
......@@ -362,7 +367,7 @@ namespace Mall.WebApi.App_Code
req.SetParameter("mch_appid", model.MiniAppId);//微信开放平台审核通过的应用APPID
req.SetParameter("mchid", model.WeChatPayMerchants);//微信支付分配的商户号
req.SetParameter("nonce_str", GetNoncestr());//随机字符串,不长于32位
req.SetParameter("sign", req.CreateMd5Sign(_accessor));
req.SetParameter("sign", req.CreateMd5Sign(_accessor, model.WeChatApiSecret));
req.SetParameter("partner_trade_no", sOrderNo);//商户订单号,需保持唯一性(只能是字母或者数字,不能包含有其它字符)
req.SetParameter("openid", openid);
req.SetParameter("check_name", "NO_CHECK");
......
......@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using Google.Protobuf.WellKnownTypes;
using Mall.Common.API;
using Mall.Common.Pay.WeChatPat;
using Mall.Common.Plugin;
......@@ -14,12 +15,17 @@ using Newtonsoft.Json.Linq;
namespace Mall.WebApi.Controllers.AppletWeChat
{
[Route("api/[controller]/[action]")]
[ApiExceptionFilter]
[ApiController]
[EnableCors("AllowCors")]
public class WeChatNotifyController : Controller
{
private static object _lock = new object();
UserCommonModule userCommonModule = new UserCommonModule();
/// <summary>
/// 订单支付回调
/// </summary>
......@@ -52,9 +58,12 @@ namespace Mall.WebApi.Controllers.AppletWeChat
userCommonModule.InsertOrderPayInfo(UserId, OrderId, sOrderNo, TransactionId, Common.Enum.Goods.OrderPayTypeEnum.WeChatPay, PayType, dPaid, PayDate, 0);
#endregion
}
var reqXml = req.ParseXml();
//告诉微信我们已经处理成功,不需要再调用我们的接口了
req.SetParameter("return_code", "SUCCESS");
req.SetParameter("return_msg", "OK");
var reqXml = req.ParseXml();
return reqXml;
// return ApiResult.Success("", reqXml);
}
else
{
......@@ -63,6 +72,7 @@ namespace Mall.WebApi.Controllers.AppletWeChat
var reqXmlFAIL = req.ParseXml();
LogHelper.Write(null, "Notify返回信息:" + reqXmlFAIL);
return reqXmlFAIL;
// return ApiResult.Failed("", reqXmlFAIL);
}
}
}
......
......@@ -92,8 +92,8 @@ namespace Mall.WebApi.Controllers.AppletWeChat
App_Code.PayUtil payUtil = new App_Code.PayUtil();
switch ((int)demodel.OrderPayType)
{
case 1://微信支付
sPayInfo = App_Code.PayUtil.GetMinUnifiedOrder(sOrderNo, demodel.GoodsName, model.Income.Value, model.UserId.ToString(), demodel.OpenId, miniProgram, _accessor);
case 1://微信支付 _accessor.HttpContext.Connection.RemoteIpAddress.ToString()
sPayInfo = App_Code.PayUtil.GetMinUnifiedOrder(sOrderNo, demodel.GoodsName, model.Income.Value, model.UserId.ToString(), demodel.OpenId, miniProgram, _accessor, System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList.FirstOrDefault(address => address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)?.ToString());
break;
default:
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment