public async Task <object> PayAsync(OrderPayRequestDto input) { var order = await Repository.Include(x => x.OrderItems).FirstOrDefaultAsync(x => x.Id == input.OrderId); var appName = _httpContextAccessor?.HttpContext.Request.Headers["AppName"].FirstOrDefault(); var app = await _appProvider.GetOrNullAsync(appName); var appid = app["appid"] ?? throw new AbpException($"App:{appName} appid未设置"); var mchId = await _setting.GetOrNullAsync(MallManagementSetting.PayMchId); var mchKey = await _setting.GetOrNullAsync(MallManagementSetting.PayKey); var notifyUrl = await _setting.GetOrNullAsync(MallManagementSetting.PayNotify); var result = await _payApi.UnifiedOrderAsync( appid, mchId, mchKey, body : order.OrderItems.First().SpuName, outTradeNo : $"{mchId}{DateTime.Now:yyyyMMddHHmmss}{StringExt.BuildRandomStr(6)}", totalFee : Convert.ToInt32(order.PriceOriginal * 100), notifyUrl : notifyUrl, tradeType : Consts.TradeType.JsApi, openId : input.openid, billCreateIp : _httpContext.HttpContext.Connection.RemoteIpAddress.ToString() ); return(result); }
public virtual async Task <QrDetail> Handle(GetQrQuery request, CancellationToken cancellationToken) { var dbEntity = await _repository.FirstOrDefaultAsync(x => x.AppName == request.Input.AppName && x.EventName == request.EventName && x.EventKey == request.Input.SpuId.ToString()); if (dbEntity != null) { return(dbEntity); } var detail = new QrDetail(request.Input.AppName, request.EventName, request.Input.SpuId?.ToString(), _currentTenant.Id); detail.Params.Add("spuId", request.Input.SpuId.ToString()); detail.Params.Add("keywords", request.Input.Keywords); var app = await _appProvider.GetOrNullAsync(request.Input.AppName); if (app == null) { throw new UserFriendlyException("没有定义的APP"); } var entity = await _repository.InsertAsync(detail, autoSave : true, cancellationToken : cancellationToken); var qr = await _weixinManager.Getwxacodeunlimit(app["appid"], app["appsec"], entity.Id.ToShortString(), detail.Path); entity.SetQrUrl(qr); return(await Task.FromResult(entity)); }
public async Task <object> MiniAuth(WeChatMiniProgramAuthenticateModel loginModel) { var appName = _httpContextAccessor?.HttpContext.Request.Headers["AppName"].FirstOrDefault(); var app = await _appProvider.GetOrNullAsync(appName); var appid = app["appid"] ?? throw new AbpException($"App:{appName} appid未设置"); var appSec = app["appsec"] ?? throw new AbpException($"App:{appName} appsec未设置"); return(await _weixinAppService.MiniAuth(loginModel, appid, appSec)); }
public async Task <object> PayAsync(OrderPayRequestDto input) { var productOrder = await Repository.Include(x => x.OrderItems).FirstOrDefaultAsync(x => x.Id == input.OrderId); if (productOrder == null) { throw new UserFriendlyException("NotFind"); } var appName = _httpContextAccessor?.GetAppName(); var app = await _appProvider.GetOrNullAsync(appName); var appid = app["appid"] ?? throw new AbpException($"App:{appName} appid未设置"); var mchId = await _setting.GetOrNullAsync(MallManagementSetting.PayMchId); var mchKey = await _setting.GetOrNullAsync(MallManagementSetting.PayKey); var notifyUrl = await _setting.GetOrNullAsync(MallManagementSetting.PayNotify); var payorder = new PayOrder(); payorder.CreatWxPayFromProductOrder(id: GuidGenerator.Create(), productOrder: productOrder, mchId: mchId, openid: input.openid, appName: appName, shareFromUserId: null, partnerId: null ); var insertPayOrder = await _payOrderRepository.InsertAsync(payorder, autoSave : true); productOrder.SetBillNo(insertPayOrder.Id, insertPayOrder.BillNo); var unifiedResult = await _payApi.UnifiedOrderAsync( appid, mchId, mchKey, body : productOrder.OrderItems.First().SpuName, outTradeNo : insertPayOrder.BillNo, totalFee : Convert.ToInt32(productOrder.PriceOriginal * 100), notifyUrl : notifyUrl.EnsureEndsWith('/') + appName, tradeType : Consts.TradeType.JsApi, openId : input.openid, billCreateIp : _httpContext.HttpContext.Connection.RemoteIpAddress.ToString() ); _rabbit.PushDelyMessage(new PayOrderLisenerData { Type = "PayOrder", Data = insertPayOrder }, MallConsts.PayAutoCancelTime, "SoMall_DelayQueue"); // 半小时内未支付删除 return(unifiedResult); }
public virtual async Task <object> PayNotifyUrl(string appName, [FromBody] TenPayNotifyXml input) { Log.Warning(JsonConvert.SerializeObject(input)); var return_msg = input.return_msg; var return_code = input.return_code; var app = await _appProvider.GetOrNullAsync(appName); var appsec = app["appsec"] ?? throw new AbpException($"App:{appName} appsec未设置"); var verifySign = _signatureGenerator.Generate(GetPayParameters(input), MD5.Create(), appsec); Log.Warning($"verifySign:{verifySign},InputSign:{input.sign}"); var tenPayNotify = new TenPayNotify { appid = input.appid, bank_type = input.bank_type, cash_fee = input.cash_fee, fee_type = input.fee_type, is_subscribe = input.is_subscribe, mch_id = input.mch_id, nonce_str = input.nonce_str, openid = input.openid, out_trade_no = input.out_trade_no, result_code = input.result_code, return_code = input.return_code, sign = input.sign, time_end = input.time_end, total_fee = input.total_fee, trade_type = input.trade_type, transaction_id = input.transaction_id }; var notify = await _tenpayRepository.FirstOrDefaultAsync(z => z.out_trade_no == tenPayNotify.out_trade_no); if (notify == null) { notify = tenPayNotify; var insertEntity = await _tenpayRepository.InsertAsync(notify, autoSave : true); await _capBus.PublishAsync("mall.tenpay.notify", insertEntity); } var xml = $@"<xml> <return_code><![CDATA[{return_code}]]></return_code> <return_msg><![CDATA[{return_msg}]]></return_msg> </xml>"; return(xml); }
public async Task <object> PayAsync(OrderPayRequestDto input) { var productOrder = await Repository.Include(x => x.OrderItems).FirstOrDefaultAsync(x => x.Id == input.OrderId); var appName = _httpContextAccessor?.HttpContext.Request.Headers["AppName"].FirstOrDefault(); var app = await _appProvider.GetOrNullAsync(appName); var appid = app["appid"] ?? throw new AbpException($"App:{appName} appid未设置"); var mchId = await _setting.GetOrNullAsync(MallManagementSetting.PayMchId); var mchKey = await _setting.GetOrNullAsync(MallManagementSetting.PayKey); var notifyUrl = await _setting.GetOrNullAsync(MallManagementSetting.PayNotify); var payorder = new PayOrder(); payorder.CreatWxPayFromProductOrder(id: GuidGenerator.Create(), productOrder: productOrder, mchId: mchId, openid: input.openid, appName: appName, shareFromUserId: null, partnerId: null ); var insertAsync = await _payOrderRepository.InsertAsync(payorder, autoSave : true); productOrder.SetBillNo(insertAsync.Id, insertAsync.BillNo); var result = await _payApi.UnifiedOrderAsync( appid, mchId, mchKey, body : productOrder.OrderItems.First().SpuName, outTradeNo : insertAsync.BillNo, totalFee : Convert.ToInt32(productOrder.PriceOriginal * 100), notifyUrl : notifyUrl, tradeType : Consts.TradeType.JsApi, openId : input.openid, billCreateIp : _httpContext.HttpContext.Connection.RemoteIpAddress.ToString() ); return(result); }
public async Task <object> MiniAuth(WeChatMiniProgramAuthenticateModel loginModel, string appName) { var app = await _appProvider.GetOrNullAsync(appName); var appid = app["appid"] ?? throw new AbpException($"App:{appName} appid未设置"); var appSec = app["appsec"] ?? throw new AbpException($"App:{appName} appsec未设置"); var session = await _weixinManager.Mini_Code2Session(loginModel.code, appid, appSec); // 解密用户信息 var miniUserInfo = await _weixinManager.Mini_GetUserInfo(appid, loginModel.encryptedData, session.session_key, loginModel.iv); miniUserInfo.AppName = appName; // 更新数据库 await _capBus.PublishAsync("weixin.services.mini.getuserinfo", miniUserInfo); var token = ""; var user = await _identityUserStore.FindByLoginAsync($"unionid", miniUserInfo.unionid); if (user == null) { var userId = _guidGenerator.Create(); user = new IdentityUser(userId, miniUserInfo.unionid, $"{miniUserInfo.unionid}@somall.top", _currentTenant.Id) { Name = miniUserInfo.nickName }; using (var uow = _unitOfWorkManager.Begin(requiresNew: true)) { var passHash = _passwordHasher.HashPassword(user, "1q2w3E*"); await _identityUserStore.CreateAsync(user); await _identityUserStore.SetPasswordHashAsync(user, passHash); await _identityUserStore.AddLoginAsync(user, new UserLoginInfo($"unionid", miniUserInfo.unionid, "unionid")); await _identityUserStore.AddLoginAsync(user, new UserLoginInfo($"{appid}_openid", miniUserInfo.openid, "openid")); await _unitOfWorkManager.Current.SaveChangesAsync(); await uow.CompleteAsync(); } } var serverClient = _httpClientFactory.CreateClient(); var disco = await serverClient.GetDiscoveryDocumentAsync(_configuration["AuthServer:Authority"]); var result = await serverClient.RequestTokenAsync( new TokenRequest { Address = disco.TokenEndpoint, GrantType = "UserWithTenant", ClientId = _configuration["AuthServer:ClientId"], ClientSecret = _configuration["AuthServer:ClientSecret"], Parameters = { { "user_id", $"{user.Id}" }, { "tenantid", $"{user.TenantId}" }, { "scope", "SoMall" } } }); token = result.AccessToken; return(await Task.FromResult(new { AccessToken = token, ExternalUser = miniUserInfo, SessionKey = session.session_key })); }