Commit 1a955160 authored by 黄奎's avatar 黄奎
parents d2d941ce b26e508a
......@@ -46,11 +46,10 @@ 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, string IPAddress)
public static string GetMinUnifiedOrder(string sOrderNo, string sProductName, decimal dPrice, string CustomerId, string openid,string notify_url, RB_MiniProgram_Extend model, IHttpContextAccessor _accessor, string IPAddress)
{
var req = new Common.Pay.WeChatPat.RequestHandler();
req.SetKey(model.WeChatApiSecret);
//
req.SetParameter("appid", model.MiniAppId);//微信开放平台审核通过的应用APPID
req.SetParameter("mch_id", model.WeChatPayMerchants);//微信支付分配的商户号
req.SetParameter("nonce_str", GetNoncestr());//随机字符串,不长于32位
......@@ -61,7 +60,7 @@ namespace Mall.WebApi.App_Code
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("notify_url", notify_url );
req.SetParameter("trade_type", "JSAPI");
req.SetParameter("openid", openid);
req.SetParameter("sign", req.CreateMd5Sign(_accessor, model.WeChatApiSecret));
......@@ -494,6 +493,75 @@ namespace Mall.WebApi.App_Code
/// <summary>
/// 当面支付
/// </summary>
/// <param name="sOrderNo"></param>
/// <param name="dPrice"></param>
/// <param name="CustomerId"></param>
/// <param name="model"></param>
/// <param name="_accessor"></param>
/// <returns></returns>
public static BaseResult GetNativeOrder(string sOrderNo, decimal dPrice, string ProductName, string CustomerId, RB_MiniProgram_Extend model, string IPAddress, IHttpContextAccessor _accessor)
{
var req = new Common.Pay.WeChatPat.RequestHandler();
req.SetKey(model.WeChatApiSecret);
req.SetParameter("appid", model.MiniAppId);//微信开放平台审核通过的应用APPID
req.SetParameter("mch_id", model.WeChatPayMerchants);//微信支付分配的商户号
req.SetParameter("nonce_str", GetNoncestr());//随机字符串,不长于32位
req.SetParameter("out_trade_no", sOrderNo);//商户订单号,需保持唯一性(只能是字母或者数字,不能包含有其它字符)
req.SetParameter("body", ProductName);
req.SetParameter("total_fee", (dPrice * 100).ToString("f0"));
req.SetParameter("spbill_create_ip", IPAddress);
req.SetParameter("notify_url", Config.sTenpayNotify);//回调地址20200604 后面用的时候修改,现在只是把支付调通
req.SetParameter("trade_type", "NATIVE");//
req.SetParameter("sign", req.CreateMd5Sign(_accessor, model.WeChatApiSecret));
var reqXml = req.ParseXml();
var result = Common.Pay.WeChatPat.HttpHelper.Post(new HttpParam()
{
Url = Mall.Common.Pay.WeChatPat.Model.ApiList.UnifiedOrderUrl,
PostParam = reqXml,
Encoding = Common.Pay.WeChatPat.HttpHelper.GetRequestEncoding(_accessor.HttpContext.Request),
});
var xe = XElement.Parse(result, LoadOptions.SetLineInfo);
var returnCode = xe.GetElement("return_code") == null ? "" : xe.GetElement("return_code").Value;
var returnMsg = xe.GetElement("return_msg") == null ? "" : xe.GetElement("return_msg").Value;
if (returnCode.Equals("SUCCESS") && returnCode.Equals("SUCCESS"))
{
var code_url = xe.GetElement("code_url") == null ? "" : xe.GetElement("code_url").Value;
//在外面回写订单
return new BaseResult()
{
IsSuccess = true,
Data = new Dictionary<string, string>
{
{ "code_url", code_url}
}
};
}
//在外面回写订单
return new BaseResult()
{
IsSuccess = false,
Message = returnMsg + returnCode,
Data = new Dictionary<string, string>
{
{ "code_url", ""}
}
};
}
/// <summary>
/// 获取随机字符串
/// </summary>
......
......@@ -128,7 +128,7 @@ namespace Mall.WebApi.Controllers.AppletWeChat
int version = Convert.ToInt32(query.Version.Replace(".", ""));
version += 1;
query.Version = version.ToString().Substring(0, version.ToString().Length - 2) +"."+ version.ToString().Substring(version.ToString().Length - 2, 1) + "." + version.ToString().Substring(version.ToString().Length - 1, 1);
query.Version = version.ToString().Substring(0, version.ToString().Length - 2) + "." + version.ToString().Substring(version.ToString().Length - 2, 1) + "." + version.ToString().Substring(version.ToString().Length - 1, 1);
string URL = $"http://127.0.0.1:{developerKitsPort}/v2/upload?project={Mall.Common.Plugin.StringHelper.UrlEncode(projectUrl)}&version=V{query.Version}&desc=微信开发者工具HTTP上传&appid={model.MiniAppId}";
string result = Mall.Common.Plugin.HttpHelper.HttpGet(URL, Encoding.UTF8, "");
......@@ -176,6 +176,29 @@ namespace Mall.WebApi.Controllers.AppletWeChat
/// <summary>
/// 当面付页面调转
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost]
public virtual ApiResult GetNativeOrder()
{
var parms = RequestParm;
var query = new RB_MiniProgram_Extend
{
TenantId = UserInfo.TenantId,
MallBaseId = parms.MallBaseId
};
var appletWeChatModel = appletWeChatModule.GetTenantListModule(query).FirstOrDefault();
string imgBase64 = appletWeChatModule.GetWeiXinShare(appletWeChatModel, "");//页面暂时还未确定,确定后填入20200604 Add By:W
return ApiResult.Success("", imgBase64);
}
/// <summary>
/// 订阅消息推送
/// </summary>
......
......@@ -53,7 +53,7 @@ namespace Mall.WebApi.Controllers.AppletWeChat
{
var request = RequestParm;
var userInfo = AppletUserInfo; // new AppletUserInfo();
if (userInfo==null)
if (userInfo == null)
{
return ApiResult.Failed("请登录");
}
......@@ -96,7 +96,7 @@ namespace Mall.WebApi.Controllers.AppletWeChat
switch ((int)demodel.OrderPayType)
{
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());
sPayInfo = App_Code.PayUtil.GetMinUnifiedOrder(sOrderNo, demodel.GoodsName, model.Income.Value, model.UserId.ToString(), demodel.OpenId, Config.sTenpayNotify, miniProgram, _accessor, System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList.FirstOrDefault(address => address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)?.ToString());
break;
default:
break;
......@@ -130,8 +130,19 @@ namespace Mall.WebApi.Controllers.AppletWeChat
RB_MiniProgram_Extend miniProgram = new RB_MiniProgram_Extend(); //2020年5月26号新增
miniProgram = new RB_MiniProgram_Extend { MiniAppId = "wxacd9f8cc3480d29e", WeChatApiSecret = "936110e2c2214340b9829a3608bde6b0", WeChatPayMerchants = "1562277941" }; // programModule.GetMiniProgramModule(new RB_MiniProgram_Extend { MallBaseId = 1, TenantId =1 });
string RefundOrderNo = "20200529160443264111";
var Robj = App_Code.PayUtil.GetTransfersOrder(RefundOrderNo, Convert.ToDecimal("0.01"), "21233", "ow_7I5XC1-RGwwk8QANBmWKYKmOc", miniProgram, _accessor); ;
var Robj = App_Code.PayUtil.GetTransfersOrder(RefundOrderNo, Convert.ToDecimal("0.01"), "21233", "ow_7I5XC1-RGwwk8QANBmWKYKmOc", miniProgram, _accessor); ;
return ApiResult.Success("", Robj);
}
public ApiResult TestNativeOrder()
{
RB_MiniProgram_Extend miniProgram = new RB_MiniProgram_Extend(); //2020年5月26号新增
miniProgram = new RB_MiniProgram_Extend { MiniAppId = "wxacd9f8cc3480d29e", WeChatApiSecret = "936110e2c2214340b9829a3608bde6b0", WeChatPayMerchants = "1562277941" }; // programModule.GetMiniProgramModule(new RB_MiniProgram_Extend { MallBaseId = 1, TenantId =1 });
string RefundOrderNo = System.DateTime.Now.ToString("yyyyMMddHHmmssfff");
var Robj = App_Code.PayUtil.GetNativeOrder(RefundOrderNo, Convert.ToDecimal("0.01"), "测试商品", "21233", miniProgram, System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList.FirstOrDefault(address => address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)?.ToString(), _accessor); ;
return ApiResult.Success("", Robj);
}
}
......
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