Commit 15785911 authored by 吴春's avatar 吴春

提交代码

parent e9b95178
using Mall.Common.Plugin;
using System;
using System.Collections.Generic;
using System.Text;
namespace Mall.Common.Enum.Goods
{
public enum OrderPayTypeEnum
{
/// <summary>
/// 微信
/// </summary>
[EnumField("微信")]
WeChatPay = 1,
/// <summary>
/// 支付宝
/// </summary>
[EnumField("支付宝")]
Alipay = 2
}
}
......@@ -14,13 +14,6 @@ namespace Mall.Common.Pay.WeChatPat
/// </summary>
public class RequestHandler
{
private IHttpContextAccessor _accessor;
public RequestHandler(IHttpContextAccessor accessor)
{
_accessor = accessor;
}
/// <summary>
/// 请求的参数
/// </summary>
......@@ -171,6 +164,35 @@ namespace Mall.Common.Pay.WeChatPat
var sign = Plugin.SecurityHelper.MD5EncryptWeChat(sb.ToString(), GetCharset()).ToUpper();
return sign;
}
/// <summary>
/// 创建package签名,按参数名称a-z排序,遇到空值的参数不参加签名。
/// </summary>
/// <returns></returns>
public string CreateMd5Sign(IHttpContextAccessor accessor)
{
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("", v, StringComparison.Ordinal) != 0
&& String.Compare("sign", k, StringComparison.Ordinal) != 0 && String.Compare("key", k, StringComparison.Ordinal) != 0)
{
sb.Append(k + "=" + v + "&");
}
}
sb.Append("key=" + GetKey());
var sign = Plugin.SecurityHelper.MD5EncryptWeChat(sb.ToString(), GetCharset(accessor)).ToUpper();
return sign;
}
/// <summary>
/// 创建sha1签名
/// </summary>
......@@ -269,18 +291,37 @@ namespace Mall.Common.Pay.WeChatPat
/// 获取编号
/// </summary>
/// <returns></returns>
protected virtual string GetCharset()
protected virtual string GetCharset(IHttpContextAccessor accessor)
{
//return "UTF-8";
try
{
return HttpHelper.GetRequestEncoding(_accessor.HttpContext.Request).BodyName; // HttpContext.Current.Request.ContentEncoding.BodyName;
return HttpHelper.GetRequestEncoding(accessor.HttpContext.Request).BodyName; // HttpContext.Current.Request.ContentEncoding.BodyName;
}
catch (Exception)
{
return "UTF-8";
}
}
/// <summary>
/// 获取编号
/// </summary>
/// <returns></returns>
protected virtual string GetCharset()
{
return "UTF-8";
//try
//{
// return HttpHelper.GetRequestEncoding(accessor.HttpContext.Request).BodyName; // HttpContext.Current.Request.ContentEncoding.BodyName;
//}
//catch (Exception)
//{
// return "UTF-8";
//}
}
}
}
......@@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using System.Text;
using Mall.Model.Entity.Product;
using Mall.Common.Enum.Goods;
namespace Mall.Model.Extend.Product
{
......@@ -107,12 +108,27 @@ namespace Mall.Model.Extend.Product
/// 使用优惠卷id
/// </summary>
public int? User_Coupon_Id { get; set; }
/// <summary>
/// 支付方式
/// </summary>
public OrderPayTypeEnum? OrderPayType { get; set; }
/// <summary>
/// 唯一识别码
/// </summary>
public string OpenId
{
get;
set;
}
}
/// <summary>
/// 订单优惠金额
/// </summary>
public class RB_Goods_CouponModel {
public class RB_Goods_CouponModel
{
/// <summary>
/// 商品id
/// </summary>
......
......@@ -550,6 +550,7 @@ namespace Mall.Module.User
{ nameof(RB_MiniProgram_Extend.WeChatApiSecret),extModel.WeChatApiSecret},
{ nameof(RB_MiniProgram_Extend.WeChatPayCertificate),extModel.WeChatPayCertificate},
{ nameof(RB_MiniProgram_Extend.WeChatPayPrivateKey),extModel.WeChatPayPrivateKey},
{ nameof(RB_MiniProgram_Extend.WeChatPayCertificateUrl),extModel.WeChatPayCertificateUrl},
};
flag = programRepository.Update(fileds, new WhereHelper(nameof(RB_MiniProgram_Extend.MallBaseId), extModel.MallBaseId));
}
......
This diff is collapsed.
......@@ -9,78 +9,16 @@ using Mall.Common.Plugin;
using Mall.WebApi.Filter;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
namespace Mall.WebApi.Controllers.AppletWeChat
{
[Route("api/[controller]/[action]")]
[ApiExceptionFilter]
[ApiController]
[EnableCors("AllowCors")]
public class WeChatNotifyController : BaseController
public class WeChatNotifyController : Controller
{
private static object _lock = new object();
/// <summary>
/// 微信支付方法
/// </summary>
/// <param name="sOrderNo"></param>
/// <param name="sCurOpenID"></param>
/// <returns></returns>
[HttpGet]
[HttpPost]
public ApiResult DoPay(string sOrderNo, string sCurOpenID = "")
{
if (string.IsNullOrWhiteSpace(sCurOpenID))
{
return ApiResult.Failed("OpenId不能为空!");
}
string result = "";
//判断订单信息
//var model = new REBORN.Module.SellModule.CounponOrderModule().GetEntity(Convert.ToInt32(sOrderNo));
//if (model == null)
//{
// return ApiResult.Failed("订单信息不存在!");
//}
//if (model.OrderState == 2)
//{
// return ApiResult.Failed("订单已支付");
//}
//if (model.OrderState == 3)
//{
// return ApiResult.Failed("订单已取消");
//}
var payParam = new Common.Pay.WeChatPat.PayParam()
{
TotalFee = 1,// Convert.ToInt32(model.PreferPrice * 100),//总价,单位:分。2500即25元
OpenId = sCurOpenID,//支付用户的OpenId
OrderNumber = (System.DateTime.Now.ToString("yyyyMMddHHmmssfff")) + sOrderNo,
ProductName = "测试商品名称", //model.ProductName,
IsRecharge = false
};
try
{
LogHelper.Write(null, "DoPay-H5:" + payParam);
App_Code.PayUtil PayUtil = new App_Code.PayUtil();
result = PayUtil.CreateJSAPIPayJson(payParam);
return ApiResult.Success("", result);
}
catch (Exception ex)
{
if (ex.Message.Contains("timed out"))
{
App_Code.PayUtil PayUtil = new App_Code.PayUtil();
var json = PayUtil.CreateJSAPIPayJson(payParam);
return ApiResult.Success("", json);
}
}
return ApiResult.Success();
}
/// <summary>
......@@ -157,5 +95,16 @@ namespace Mall.WebApi.Controllers.AppletWeChat
//告诉微信我们处理失败,请继续调用我们的接口。好像是会重试8次。
}
}
}
\ No newline at end of file
This diff is collapsed.
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