|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- using BPA.Kitchen.Core;
- using BPA.KitChen.GroupMealOrder.Core.CacheOption;
- using BPA.KitChen.GroupMealOrder.Core.Common;
- using BPA.KitChen.GroupMealOrder.Core.Entity;
- using BPA.KitChen.GroupMealOrder.SqlSugar;
- using BPA.KitChen.WeChat.WechatServer.Dtos;
- using BPA.KitChen.WeChat.WechatServer.Service;
- using Essensoft.Paylink.WeChatPay.V2.Response;
- using Furion.DynamicApiController;
- using Furion.FriendlyException;
- using Furion.JsonSerialization;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Caching.Memory;
-
- namespace Black_B_Project.Application.WechatServer.Service
- {
- /// <summary>
- /// 微信接口汇总
- /// </summary>
- [ApiDescriptionSettings("WECHAT"), AllowAnonymous]
- public class WechatAppService : IDynamicApiController
- {
- private readonly IWechatPayService _IWechatPay;
- private readonly IWechatNotityService _IWechatNotityService;
- private readonly IWechatService _WechatService;
-
- private readonly IWeChatPayProfitService _IProfitService;
- private readonly IMemoryCache _memoryCache;
- public WechatAppService(
- IWechatPayService IWechatPay,
- IWechatService wechatService,
- IWechatNotityService IWechatNotityService,
- IWeChatPayProfitService IProfitService,
- IMemoryCache memoryCache
- )
- {
- _IWechatPay = IWechatPay;
- _WechatService = wechatService;
- _IWechatNotityService = IWechatNotityService;
-
- _IProfitService = IProfitService;
- _memoryCache = memoryCache;
- }
-
- /// <summary>
- /// 用户登录,获取openid
- /// </summary>
- /// <param name="vm"></param>
- /// <returns></returns>
- [HttpPost]
- public WeChatUserInfo wxlogin(DecryptVM vm)
- {
- return _WechatService.WxLogin(vm);
- }
- [HttpPost]
- public WeChatUserInfo Decryptuserinfo(DecryptVM vm)
- {
- if (string.IsNullOrEmpty(vm.session_key))
- {
- throw Oops.Oh("session_key不能为空!");
- }
- if (string.IsNullOrEmpty(vm.aesiv))
- {
- throw Oops.Oh("aesiv不能为空!");
- }
- if (string.IsNullOrEmpty(vm.encryptedData))
- {
- throw Oops.Oh("encryptedData不能为空!");
- }
- WeChatUserInfo userinfo = _WechatService.Decryptuserinfo(vm);
- return userinfo;
- }
- /// <summary>
- /// 获取手机号
- /// </summary>
- /// <param name="code"></param>
- /// <returns></returns>
- [HttpGet("/api/wechat/user/phone")]
- public async Task<string> WxPhone(string code)
- {
- WechatPhoneMsg phonemsg = await _WechatService.WxPhone(code);
- if (phonemsg.errcode==0)
- {
- return phonemsg.phone_info.purePhoneNumber;
- }
- else
- {
- throw Oops.Bah(phonemsg.errmsg);
- }
- }
- /// <summary>
- /// 调用jsapi支付,返回支付信息
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public Task<IActionResult> Wechatpay( string ordernum)
- {
- return _IWechatPay.PayLinkWechatPay(null, ordernum);
- }
-
- /// <summary>
- /// 充值
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [HttpPost]
- public Task<IActionResult> Rechargepay(RechargeInput input)
- {
- return _IWechatPay.RechargePay(input);
- }
-
- /// <summary>
- /// 调用Native支付,返回支付信息url
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public string Nativepay(decimal amount, string orderid)
- {
- return _IWechatPay.NativePay(amount, orderid);
- }
-
- /***
- * @param transaction_id 微信订单号(优先使用)
- * @param out_trade_no 商户订单号
- * @param total_fee 订单总金额
- * @param refund_fee 退款金额
- * @return 退款结果(xml格式)
- */
- /// <summary>
- /// 申请退款完整业务流程逻辑
- /// </summary>
- /// <param name="input">商户</param>
- /// <returns></returns>
- [HttpPost]
- public async Task<IActionResult> Wechatrefund(RefundInput input)
- {
- // BPALog.WriteLog($"Wechatrefund请求参数", param: input);
- if (string.IsNullOrEmpty(input.AppId))
- {
- throw Oops.Oh("AppId不能为空!");
- }
- var config = ApolloApplication.Configs.Find(x => x.Key == input.AppId);
- if (config==null)
- {
- throw Oops.Oh("AppId不存在!");
- }
- config.WechatConfig.OrderAddress = "https://bpa.black-pa.com:21527/order";
- // MyDataResult<OrderAllInfoDto> res = OrderWeApiHepler.GetOrderInfoByNum<OrderAllInfoDto>(config.WechatConfig.OrderAddress,input.OrderNumberId);
-
- var order = await SqlSugarDb.Db.Queryable<BPA_WeighOrder>()
- .FirstAsync(x => x.OrderNumber == input.OrderNumberId);
- if (order!=null)
- {
- int totalFee = Convert.ToInt32(order.TotalAmount * 100);
-
- RefundDto refundDto = await _IWechatPay.Refund(
- new() {
- out_trade_no = input.OrderNumberId,
- refund_fee = totalFee,
- total_fee = totalFee,
- },config
- );//提交退款申请给API,接收返回数据
- return new JsonResult(refundDto);
- }
- else
- {
- throw Oops.Oh("数据接口查询失败:订单不存在");
- }
- }
- /// <summary>
- /// 对账单请求处理
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [NonUnify]
- [Route("wechat/pay/downloadbill")]
- public static string Downloadbill(BillInput input)
- {
- var config = ApolloApplication.Configs.Find(x => x.Key == input.appid);
- string nonceStr = WechatCommon.GenerateNonceStr();
- string appid = config.WechatPayConfig.AppId;
- string mchid = config.WechatPayConfig.MchId;
- string mchkey = config.WechatPayConfig.APIKey;
- string strA = $"appid={appid}&bill_date={input.billdate}&bill_type={input.billtype}&mch_id={mchid}&nonce_str={nonceStr}&key=" + mchkey;
- string sign = WechatCommon.MD5(strA).ToUpper();
- var json = new
- {
- input.appid,
- input.billdate,
- input.billtype,
- mchid,
- nonceStr,
- sign
- };
-
- return JSON.Serialize(json);
- }
- ///<summary>
- /// 微信支付通知
- /// </summary>
- /// <returns></returns>
- [NonUnify]
- [Route("wechat/paynotity")]
- public Task<IActionResult> PayNotity()
- {
- return _IWechatNotityService.PayNotity();
- }
- /// <summary>
- /// 微信支付退款通知
- /// </summary>
- [Route("wechat/refundnotity")]
- [NonUnify]
- public async Task<IActionResult> RefundNotity()
- {
- return await _IWechatNotityService.RefundNotity();
- }
- /// <summary>
- /// 微信支付-付款码
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [Route("wechat/pay/micro")]
- [NonUnify]
- public async Task<IActionResult> MicropayPay(MicropayInput input)
- {
- return await _IWechatPay.MicropayPay(input);
- }
- /// <summary>
- /// 查询
- /// </summary>
- /// <param name="ordernumid"></param>
- /// <param name="appId"></param>
- /// <returns></returns>
- [Route("wechat/queryorder")]
- public async Task<IActionResult> PayOrderQuery(string ordernumid,string appId)
- {
- var config = ApolloApplication.Configs.Find(x => x.Key == appId);
- // MyDataResult<OrderAllInfoDto> info = OrderWeApiHepler.GetOrderInfoByNum<OrderAllInfoDto>(config.WechatConfig.OrderAddress, ordernumid);
-
- var order = await SqlSugarDb.Db.Queryable<BPA_WeighOrder>()
- .FirstAsync(x => x.OrderNumber == ordernumid);
-
-
- if (order==null)
- {
- throw Oops.Oh("查询失败,没有找到订单");
- }
- var data = await _IWechatPay.PayOrderQuery(appId, order.OrderNumber, order.TransactionId);
- return new JsonResult(data);
- }
- /// <summary>
- /// 发送预定提醒
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [Route("wechat/reserve")]
- [HttpPost]
- public void SendReserveMessage(ReserveInput input)
- {
- _WechatService.SendReserveMessage(input);
- }
- /// <summary>
- /// 分账信息
- /// </summary>
- /// <param name="vm"></param>
- /// <returns></returns>
- [Route("wechat/profit/sharing")]
- [HttpPost]
- public Task<WeChatPayProfitSharingResponse> ProfitSharingRequest(ProfitSharingInput vm)
- {
- return _IProfitService.ProfitSharingRequest(vm);
- }
- /// <summary>
- /// 分账余额信息
- /// </summary>
- /// <param name="TransactionId">微信支付订单号</param>
- /// <returns></returns>
- [Route("wechat/profit/amountquery")]
- public Task<WeChatPayProfitSharingOrderAmountQueryResponse> WeChatPayProfitSharingOrderAmountQuery(string TransactionId,string appId)
- {
- return _IProfitService.WeChatPayProfitSharingOrderAmountQuery(TransactionId, appId);
- }
-
- }
- }
|