using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using XYY.Core.Standard.Mvc;
using XYY.Model.Standard.Order;
using XYY.Service.Standard.ChannelApi;
using static XYY.Api.Order.Controllers.CustomerMaintenanceController;
using static XYY.Service.Standard.ChannelApi.HangLe.Api;

namespace XYY.Api.Order.Controllers
{
    [AllowAnonymous]
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class XYYTestController : ApiControllerBase
    {
        private IEnumerable<IUItidelApi> _packLabelApis;
        public XYYTestController(IEnumerable<IUItidelApi> packLabelApis)
        {
            _packLabelApis = packLabelApis;
        }
        /// <summary>
        /// 测试 获取打包标签接口
        /// 查看标签下载标签pdf查看
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpPost]
        public async Task<IActionResult> GetIBBagLabels_Test()
        {
            ChannelBagLabelParam param = new ChannelBagLabelParam()
            {
                Box = new XYY.Model.Standard.Channel.Logistics_Box() { BoxNumber = "B230306006402" },
                Channel = new XYY.Model.Standard.Channel.Logistics_Channel() { ServiceTrackingUrl = "https://clients.postnl.a02.cldsvc.net", ApiKey = "WSNTMxGyMMrklKbFChO82K0rNsXGhi2f6EVCTOj2d6PpQCqwLLhmyIevKgFCIqA0HdqndszcJ5EtjhTPP6RSeFPAer2Sj4JC9zi8MAAqVfm7uQjn0FTHUtMSqQTykA9NfDhYeTfHSIu64scmmYrvN2uL0dubQn7szo4pUV6s9PvXRAB4qw1ohzKKfsTUkrKwgiCkNPlVqHodmPAU3HVKQpDaCMepLJAhQiuBSGXPVudyvRoRyLa9A2heTaHybX6NPwMvgOKPcXdneeS669LuUt5gKkGxJk8Ksi519AAKcm8A", },
            };
            var baseApi = _packLabelApis.Where(x => x.ServiceName == "NLPost").FirstOrDefault();
            var resultData = await baseApi.GetChannelBagLabel(param);
            MemoryStream ms = new MemoryStream(Convert.FromBase64String(resultData.Label));
            return new FileStreamResult(ms, "application/pdf");
        }
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> TestIOSSM()
        {
            string code = "IM2760000999";
            string publicKeyBase64 = @"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDc0KbDAE/y4EtmCZCpqqzWreAX0b+1BWP+cFN7XbD55cv0xPF0zIlJ4qTVfdurYEHARTOfVNZOrg2jl2W0ViJ6n7F4";
            string privateKeyBase64 = @"MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBANzQpsMAT/LgS2YJkKmqrNat4BfRv7UFY/5wU3tdsPnly/TE8XTMiUnipNV926tgQcBFM59U1k6uDaOXZbRWInqfsXgz9E1XcIHED15IWuXfePewA7By7HnFr9BkjW+WXpmijuDq3Nm7vqDcV6zmzYvmzTQmsGB62a1NaL1FQeilAg";
            string value = @"IR4E//Nym9n8heEN0A43pijxKBu1BUHKrCMWTAVp6vLFSSfyrQVhtvKq6os4E1kxtvbNUNQoQnHOX7QewGIFUPIqS2eGXilQdTs3Tf0UIysmGpft9P/rkpkiffZ1eK6o/f8EClGAIy4KVDevaNvRSZ5uOOvQm5oBctjQodercts=";
            XYY.Common.Standard.RSA rsa = new Common.Standard.RSA();
            string v = rsa.DecryptByPrivateKey(value, privateKeyBase64);
            return Ok((v));
        }
    }
}