支付接口逻辑调整

develop
old易 2023-09-19 16:43:16 +08:00
parent 57f651cc30
commit 4b82560e6d
17 changed files with 185 additions and 45 deletions

View File

@ -10,11 +10,13 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using New_College.Common;
using New_College.Common.Helper;
using New_College.IRepository;
using New_College.IServices;
using New_College.Model;
using New_College.Model.Models;
using New_College.Model.ViewModels;
using Newtonsoft.Json;
namespace New_College.Api.Controllers.Front
{
@ -52,12 +54,13 @@ namespace New_College.Api.Controllers.Front
var resp = new WeixinPayResult();
try
{
DingHookHelper.DingTalkHookMessage("UnifiedOrder=>发起支付", JsonConvert.SerializeObject(query));
Random rd = new Random();
//HttpContext.GetClientUserIp();
//外部商户订单号
var payNum = DateTime.Now.ToString("yyyyMMddHHmmss") + rd.Next(0, 1000).ToString().PadLeft(3, '0');
var data = new WxPayData();
data.SetValue("body", "壹志愿好帮手VIP购买");
data.SetValue("body", "六纬志愿VIP购买");
data.SetValue("out_trade_no", payNum);
data.SetValue("detail", "志愿好帮手VIP卡购买");
data.SetValue("total_fee", Convert.ToInt32(query.total_fee * 100));
@ -66,9 +69,9 @@ namespace New_College.Api.Controllers.Front
data.SetValue("notify_url", WeixinConfig.NotifyUrl);
//data.SetValue("goods_tag", "test");
data.SetValue("trade_type", "JSAPI");
data.SetValue("openid", query.Phone);
data.SetValue("openid", query.OpenId);
//可以将用户Id和订单Id同时封装在attach中
data.SetValue("attach", string.Format("{0}|{1}", query.Phone, payNum));
data.SetValue("attach", string.Format("{0}|{1}", query.OpenId, payNum));
WxPayData result = UnifiedOrder(data);
if (!result.IsSet("appid") || !result.IsSet("prepay_id") || result.GetValue("prepay_id").ToString() == "")
{
@ -98,7 +101,7 @@ namespace New_College.Api.Controllers.Front
resp.timeStamp = timeStamp;
//NLogHelper.WriteInfo("Signurl" + Newtonsoft.Json.JsonConvert.SerializeObject(resp), DevAuthorNameEnum.Michael, false);
// WebHookHelper.WebHookmarkdownSend("Signurl" + Newtonsoft.Json.JsonConvert.SerializeObject(resp));
var customer = await v_CustomerInfoRepository.Query(x => x.OpenId == query.Phone && x.IsDelete == false);
var customer = await v_CustomerInfoRepository.Query(x => x.OpenId == query.OpenId && x.IsDelete == false);
if (customer.Count <= 0)
return new WeixinPayResult() { err_code_des = "用户出现错误" };
//添加一张卡
@ -116,16 +119,18 @@ namespace New_College.Api.Controllers.Front
Day = cardtype.Day,
EndTime = DateTime.Now.AddDays(cardtype.Day)
});
string OrderNo = OrderGenerateHelper.GenerateOrderNo("ZY");
var baseResult = await v_OrderInfoRepository.Add(new V_OrderInfo
{
out_trade_no = payNum,
// PayType = 2,
PayType = 0,
CardTypeId = query.CardTypeId,
// Status = 1,
OrderId = OrderNo,
Status = EnumOrderType.payment,
CustomerId = customer.FirstOrDefault().Id,
Price = query.total_fee,
PayPrice = query.total_fee,
Name = "壹志愿好帮手VIP购买",
Name = "六纬志愿VIP购买",
CardNo = code,
CardId = addcard
});
@ -152,10 +157,11 @@ namespace New_College.Api.Controllers.Front
/// </summary>
/// <returns></returns>
[HttpPost]
[AllowAnonymous]
public async Task<IActionResult> PayNotify()
{
logger.LogInformation("开始回调PayNotify");
DingHookHelper.DingTalkHookMessage("开始回调PayNotify", "开始回调PayNotify");
WxPayData res = new WxPayData();
//接收从微信后台POST过来的数据
@ -163,6 +169,7 @@ namespace New_College.Api.Controllers.Front
WxPayData data = new WxPayData();
using (var reader = new StreamReader(Request.Body))
{
var builder = reader.ReadToEnd();
//WebHookHelper.WebHookmarkdownSend(builder.ToString());
try
@ -172,7 +179,7 @@ namespace New_College.Api.Controllers.Front
catch (Exception ex)
{
//若签名错误,则立即返回结果给微信支付后台
DingHookHelper.DingTalkHookMessage("回调PayNotify", ex.Message);
res.SetValue("return_code", "FAIL");
res.SetValue("return_msg", ex.Message);
// NLogHelper.WriteError("Sign check error : " + res.ToXml(), DevAuthorNameEnum.Michael, false);
@ -185,6 +192,7 @@ namespace New_College.Api.Controllers.Front
//检查支付结果中transaction_id是否存在
if (!data.IsSet("transaction_id"))
{
DingHookHelper.DingTalkHookMessage("回调PayNotify", "支付结果中微信订单号不存在");
//若transaction_id不存在则立即返回结果给微信支付后台
res.SetValue("return_code", "FAIL");
res.SetValue("return_msg", "支付结果中微信订单号不存在");
@ -194,11 +202,13 @@ namespace New_College.Api.Controllers.Front
// 执行订单状态操作
string out_trade_no = data.GetValue("out_trade_no").ToString();
logger.LogInformation("开始回调PayNotify" + out_trade_no);
DingHookHelper.DingTalkHookMessage("回调PayNotify", "开始回调PayNotify" + out_trade_no);
var info = await v_OrderInfoRepository.Query(x => x.out_trade_no == out_trade_no);
if (info.Count <= 0)
{
res.SetValue("return_code", "FAIL");
res.SetValue("return_msg", "在自有平台未找到该订单号");
DingHookHelper.DingTalkHookMessage("回调PayNotify", "在自有平台未找到该订单号" + out_trade_no);
//WebHookHelper.WebHookmarkdownSend("支付结果中微信订单号不存在");
return Content(res.ToXml(), "text/xml");
}
@ -207,6 +217,7 @@ namespace New_College.Api.Controllers.Front
var rep = await v_OrderInfoRepository.Update(oneinfo);
if (rep)
{
DingHookHelper.DingTalkHookMessage("支付回调成功", oneinfo.out_trade_no + ":修改为VIP");
//修改用户信息 修改为VIp
var customerinfo = await v_CustomerInfoRepository.QueryById(oneinfo.CustomerId);
customerinfo.IsVIP = true;
@ -220,6 +231,7 @@ namespace New_College.Api.Controllers.Front
{
// string attach = data.GetValue("attach").ToString();
// WebHookHelper.WebHookmarkdownSend(attach);
DingHookHelper.DingTalkHookMessage("回调PayNotify", "在自有平台未找到该订单号" + out_trade_no);
res.SetValue("return_code", "FAIL");
res.SetValue("return_msg", "在自有平台未找到该订单号");
}

View File

@ -505,6 +505,21 @@
分类等级
</summary>
</member>
<member name="T:New_College.Model.Models.D_TagMapPerson">
<summary>
标签代表人物
</summary>
</member>
<member name="P:New_College.Model.Models.D_TagMapPerson.NickName">
<summary>
人物昵称
</summary>
</member>
<member name="P:New_College.Model.Models.D_TagMapPerson.AvatarUrl">
<summary>
人物头像
</summary>
</member>
<member name="P:New_College.Model.Models.D_University.Area_Id">
<summary>
省id

View File

@ -7,7 +7,7 @@
//MCHKey
"KEY": "brapuk6fon0wachiMlth2t3lb4a0h7ji",
//NotifyUrl
"NotifyUrl": "http://*:8082/api/WeixinPay/PayNotify"
"NotifyUrl": "https://zytb.ycymedu.com/api/front/WeixinPay/PayNotify"
},
"Logging": {
"IncludeScopes": false,

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace New_College.Common
{
public class DingHookHelper
{
/// <summary>
/// 钉钉消息推送
/// </summary>
/// <param name="controllername"></param>
/// <param name="title"></param>
/// <param name="message"></param>
public static void DingTalkHookMessage(string controllername, string message)
{
string title = "weipay";
DingtalkChatbotSdk.DingDingClient.SendMessageAsync("https://oapi.dingtalk.com/robot/send?access_token=879f3d3511b90d2e13080f0f729d9c65c3e6737de76c6074da3b98f8e432cef0", string.Format("title:{0};message:{1}", title, message));
}
}
}

View File

@ -11,6 +11,7 @@
<ItemGroup>
<PackageReference Include="Aliyun.OSS.SDK.NetCore" Version="2.10.0" />
<PackageReference Include="DingtalkChatbotSdk" Version="1.0.1" />
<PackageReference Include="Essensoft.AspNetCore.Payment.Alipay" Version="3.1.8" />
<PackageReference Include="Essensoft.AspNetCore.Payment.Security" Version="3.1.8" />
<PackageReference Include="Essensoft.AspNetCore.Payment.WeChatPay" Version="3.1.5" />

View File

@ -0,0 +1,12 @@
using New_College.IServices.BASE;
using New_College.Model.Models;
namespace New_College.IServices
{
/// <summary>
/// ID_TagMapPersonServices
/// </summary>
public interface ID_TagMapPersonServices :IBaseServices<D_TagMapPerson>
{
}
}

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace New_College.Model.Models
{
/// <summary>
/// 标签代表人物
/// </summary>
public class D_TagMapPerson:EntityModel
{
public string Tag { get; set; }
/// <summary>
/// 人物昵称
/// </summary>
public string NickName { get; set; }
public string Description { get; set; }
/// <summary>
/// 人物头像
/// </summary>
public string AvatarUrl { get; set; }
}
}

View File

@ -11,7 +11,7 @@ namespace New_College.Model.ViewModels
{
public string OutTradeNo { get; set; } = "";
public string Body { get; set; } = "志愿VIP";
public string Body { get; set; } = "六纬志愿VIP";
public decimal TotalAmount { get; set; } = 0;

View File

@ -10,6 +10,6 @@ namespace New_College.Model.ViewModels
public decimal total_fee { get; set; }
public string Phone { get; set; }
public string OpenId { get; set; }
}
}

View File

@ -63,7 +63,7 @@ namespace New_College.Model.ViewModels
/// <summary>
/// 项目编号
/// </summary>
public string Body { get; set; } = "志愿VIP";
public string Body { get; set; } = "六纬志愿VIP";
}

View File

@ -0,0 +1,17 @@
using New_College.IRepository;
using New_College.IRepository.UnitOfWork;
using New_College.Model.Models;
using New_College.Repository.Base;
namespace New_College.Repository
{
/// <summary>
/// D_TagMapPersonRepository
/// </summary>
public class D_TagMapPersonRepository : BaseRepository<D_TagMapPerson>, ID_TagMapPersonRepository
{
public D_TagMapPersonRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
{
}
}
}

View File

@ -0,0 +1,12 @@
using New_College.IRepository.Base;
using New_College.Model.Models;
namespace New_College.IRepository
{
/// <summary>
/// ID_TagMapPersonRepository
/// </summary>
public interface ID_TagMapPersonRepository : IBaseRepository<D_TagMapPerson>
{
}
}

View File

@ -0,0 +1,18 @@

using New_College.IServices;
using New_College.Model.Models;
using New_College.Services.BASE;
using New_College.IRepository.Base;
namespace New_College.Services
{
public class D_TagMapPersonServices : BaseServices<D_TagMapPerson>, ID_TagMapPersonServices
{
private readonly IBaseRepository<D_TagMapPerson> _dal;
public D_TagMapPersonServices(IBaseRepository<D_TagMapPerson> dal)
{
this._dal = dal;
base.BaseDal = dal;
}
}
}

View File

@ -35,35 +35,38 @@ namespace New_College.Services
if (info == null)
return new List<appQuestionResult>() { };
List<appQuestionResult> list = new List<appQuestionResult>() { };
if (query.CategoryId == 20)
{
List<string> subject = new List<string>() { "物理", "化学", "生物", "政治", "历史", "地理" };
int sort = 1;
foreach (var x in subject)
{
//if (query.CategoryId == 20)
//{
// List<string> subject = new List<string>() { "物理", "化学", "生物", "政治", "历史", "地理" };
// int sort = 1;
// foreach (var x in subject)
// {
// foreach (var item in info)
// {
// list.Add(new appQuestionResult()
// {
// Id = item.Id,
// IsAddScore = item.IsAddScore,
// QuestionSort = sort++,// item.OrderSort,
// QuestionTag = x,
// QuestionTitle = "对于" + x + "," + item.QuestionTitle,
// QuestionType = item.QuestionType,
// QuestionTypeId = item.QuestionTypeId
// });
// }
// }
// return list;
//}
int k = 0;
foreach (var item in info)
{
k++;
list.Add(new appQuestionResult()
{
Id = item.Id,
IsAddScore = item.IsAddScore,
QuestionSort = sort++,// item.OrderSort,
QuestionTag = x,
QuestionTitle = "对于" + x + "," + item.QuestionTitle,
QuestionType = item.QuestionType,
QuestionTypeId = item.QuestionTypeId
});
}
}
return list;
}
foreach (var item in info)
{
list.Add(new appQuestionResult()
{
Id = item.Id,
IsAddScore = item.IsAddScore,
QuestionSort = item.OrderSort,
QuestionSort = k,
QuestionTag = item.QuestionTag,
QuestionTitle = item.QuestionTitle,
QuestionType = item.QuestionType,

View File

@ -288,7 +288,7 @@ namespace New_College.Services
viewModel.SpBillCreateIp = PayInfoQuery.CreateIp;
viewModel.OutTradeNo = out_trade_no;
viewModel.TotalFee = Convert.ToInt32(query.Money*100);
viewModel.Body = "志愿VIP";
viewModel.Body = "六纬志愿VIP";
viewModel.TradeType = "MWEB";
var response = await WeChatPay.GetMwebUrl(_client, _optionsAccessor, viewModel);
@ -306,7 +306,7 @@ namespace New_College.Services
CustomerId = query.CustomerId,
Price = query.Money,
PayPrice = query.Money,
Name = "壹志愿好帮手VIP开通",
Name = "六纬志愿VIP开通",
CardNo = "0",
CardId = 0
});
@ -592,8 +592,8 @@ namespace New_College.Services
//或者失败
var model = new AlipayTradeWapPayModel
{
Body = "志愿VIP",
Subject = "志愿VIP",
Body = "六纬志愿VIP",
Subject = "六纬志愿VIP",
TotalAmount = query.Money.ToString(),
OutTradeNo = out_trade_no,
ProductCode = "QUICK_WAP_WAY",
@ -620,7 +620,7 @@ namespace New_College.Services
CustomerId = query.CustomerId,
Price = query.Money,
PayPrice = query.Money,
Name = "壹志愿好帮手VIP开通",
Name = "六纬志愿VIP开通",
CardNo = "0",
CardId = 0
});

View File

@ -62,7 +62,7 @@ namespace New_College.Services
CustomerId = query.CustomerId,
Price = cardinfo.Money,
PayPrice = cardinfo.Money,
Name = "壹志愿好帮手VIP绑定",
Name = "六纬志愿VIP绑定",
CardNo = query.CardCode,
CardId = cardinfo.Id
});