调整开发票api请求密钥获取方式

dev
douhandong 3 weeks ago
parent 7e26400fbe
commit c0b0a8b080

@ -5,12 +5,17 @@ using DS.WMS.Core.Application.Method;
using DS.WMS.Core.Code.Entity;
using DS.WMS.Core.Invoice.Dtos;
using DS.WMS.Core.Invoice.Interface;
using DS.WMS.Core.QuarztJobs.Dtos;
using DS.WMS.Core.QuarztJobs.Other;
using DS.WMS.Core.Sys.Entity;
using Masuit.Tools;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Org.BouncyCastle.Ocsp;
using SqlSugar;
using static AnyDiff.DifferenceLines;
namespace DS.WMS.Core.Invoice.Method
{
@ -19,7 +24,13 @@ namespace DS.WMS.Core.Invoice.Method
/// </summary>
public sealed class InvoiceIssuanceService : ApplicationServiceBase, IInvoiceIssuanceService
{
readonly InvoiceApiFox api;
//readonly InvoiceApiFox api;
static readonly ApiFox api;
static InvoiceIssuanceService()
{
api = new ApiFox();
}
/// <summary>
/// 初始化并加载配置
@ -28,7 +39,7 @@ namespace DS.WMS.Core.Invoice.Method
public InvoiceIssuanceService(IServiceProvider provider) : base(provider)
{
var config = provider.GetRequiredService<IConfiguration>();
api = new InvoiceApiFox(config);
}
/// <summary>
@ -101,7 +112,22 @@ namespace DS.WMS.Core.Invoice.Method
if (request.order.Count == 0 || request.order.Any(x => x.invoiceDetail.Count == 0))
return DataResult.FailedWithDesc(MultiLanguageConst.InvoiceIncomplete);
var result = await api.PostAsync<InvoiceResult<string>>("/api/Invoice/services", request);
//var result = await api.PostAsync<InvoiceResult<string>>("/api/Invoice/services", request);
var order = await TenantDb.Queryable<Entity.Invoice>().Where(x => ids.Contains(x.Id)).FirstAsync();
var orgauthinfo = Db.Queryable<SysOrg>().LeftJoin<SysOrgAuth>((t, a) => t.Id == a.OrgId)
.Where((t, a) => t.Id == order.SaleDeptId)
.Select((t, a) => new
{
a.Key,
a.Secret
}).First();
api.DefaultHeaders.Add("USER_KEY", orgauthinfo.Key);
api.DefaultHeaders.Add("USER_SECRET", orgauthinfo.Secret);
var result = await api.PostAsync<InvoiceResult<string>>(AppSetting.app(new string[] { "InvoiceApi", "BaseUrl" }) + "/api/Invoice/services", request);
if (!result.Succeeded)
return DataResult.Failed(result.Message, result.MultiCode);
@ -132,8 +158,20 @@ namespace DS.WMS.Core.Invoice.Method
/// <returns></returns>
public async Task<DataResult> UpdateInvoiceNumberAsync(string sn)
{
//var result = await api.PostAsync<InvoiceResult<InvoiceQuery>>("/api/Invoice/GetInvoiceState", new { guid = sn });
//调用查询API获取发票号
var result = await api.PostAsync<InvoiceResult<InvoiceQuery>>("/api/Invoice/GetInvoiceState", new { guid = sn });
var order = await TenantDb.Queryable<Entity.Invoice>().Where(x => x.SN == sn).FirstAsync();
var orgauthinfo = Db.Queryable<SysOrg>().LeftJoin<SysOrgAuth>((t, a) => t.Id == a.OrgId)
.Where((t, a) => t.Id == order.SaleDeptId)
.Select((t, a) => new
{
a.Key,
a.Secret
}).First();
api.DefaultHeaders.Add("USER_KEY", orgauthinfo.Key);
api.DefaultHeaders.Add("USER_SECRET", orgauthinfo.Secret);
var result = await api.PostAsync<InvoiceResult<InvoiceQuery>>(AppSetting.app(new string[] { "InvoiceApi", "BaseUrl" }) + "/api/Invoice/GetInvoiceState", new { guid = sn });
if (!result.Succeeded)
return DataResult.Failed(result.Message, result.MultiCode);
@ -202,7 +240,13 @@ namespace DS.WMS.Core.Invoice.Method
return DataResult.FailedWithDesc(MultiLanguageConst.EmptyData);
var req = new InvoiceReversalRequest { orderNo = invoice.BillNO };
var result = await api.PostAsync<InvoiceResult<string>>("/api/Invoice/RedInvoicing", req);
// var result = await api.PostAsync<InvoiceResult<string>>("/api/Invoice/RedInvoicing", req);
var orgauthinfo = Db.Queryable<SysOrgAuth>().Where(t => t.Id == invoice.SaleDeptId).First();
api.DefaultHeaders.Add("USER_KEY", orgauthinfo.Key);
api.DefaultHeaders.Add("USER_SECRET", orgauthinfo.Secret);
var result = await api.PostAsync<InvoiceResult<string>>(AppSetting.app(new string[] { "InvoiceApi", "BaseUrl" }) + "/api/Invoice/RedInvoicing", req);
if (!result.Succeeded)
return DataResult.Failed(result.Message, result.MultiCode);

@ -450,7 +450,8 @@ namespace DS.WMS.Core.Invoice.Method
}
//补充销方信息
var org = await Db.Queryable<SysOrg>().Where(x => x.Id == User.OrgId).Select(x => new { x.OrgFullName, x.LicenseCode }).FirstAsync();
//var org = await Db.Queryable<SysOrg>().Where(x => x.Id == User.OrgId).Select(x => new { x.OrgFullName, x.LicenseCode }).FirstAsync();
var org = await Db.Queryable<SysOrg>().LeftJoin<SysOrgAuth>((t, a) => t.Id == a.OrgId).Where((t, a) => t.Id == invoice.SaleDeptId).Select((t, a) => new { t.OrgFullName, t.LicenseCode }).FirstAsync();
if (org != null)
{
invoice.OrgName = org.OrgFullName;

@ -44,7 +44,7 @@ public class SysOrgAuthService: IOrgAuthService
{
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = db.Queryable<SysOrgAuth>()
var data = db.Queryable<SysOrgAuth>()
.Where(whereList)
.Select<OrgAuthRes>().ToQueryPage(request.PageCondition);
return data;

Loading…
Cancel
Save