Ejemplo n.º 1
0
        private void MockIoc()
        {
            IServiceCollection services = new ServiceCollection();

            //注册服务
            //内存缓存支持
            services.AddMemoryCache();
            services.AddHttpContextAccessor();
            //依赖注入验证服务
            services.AddTransient <IAuthenticationService, AuthenticationService>();


            #region 平台设置依赖注册组件


            //支付宝配置加载---注册:
            var alipayConfig = ConfigHelper.GetConfigSection <AlipayConfigSection>(AlipayConfigSection.SectionName);
            if (null != alipayConfig)
            {
                services.AddAlipay(options =>
                {
                    options.AlipayPublicKey = alipayConfig.AppPublicKey;     // "支付宝公钥";
                    options.AppId           = alipayConfig.AppId.ToString(); // "应用ID";
                    options.CharSet         = alipayConfig.CharSet;          // "密钥编码";
                    options.Gatewayurl      = alipayConfig.Gatewayurl;       // "支付网关";
                    options.PrivateKey      = alipayConfig.PrivateKey;       // "商家私钥";
                    options.SignType        = alipayConfig.SignType;         // "签名方式 RSA/RSA2";
                    options.Uid             = alipayConfig.Uid.ToString();   // "商户ID";
                });
            }



            // 批多多服务依赖注册---IPddService
            AppSecretConfigSection configSection = ConfigHelper.GetConfigSection <AppSecretConfigSection>(AppSecretConfigSection.SectionName);
            services.AddPdd(options =>
            {
                //注册 id  secret
                options.ClientId     = configSection.Pdd.client_id;
                options.ClientSecret = configSection.Pdd.client_secret;
                options.CallbackUrl  = configSection.Pdd.redirect_uri;
            });

            #endregion



            IServiceProvider serviceProvider = services.BuildServiceProvider();
            ServiceLocator.ServiceProvider = serviceProvider;
        }
Ejemplo n.º 2
0
        public void GetTemplate()
        {
            //加载配置
            AppSecretConfigSection configSection = ConfigHelper.GetConfigSection <AppSecretConfigSection>(AppSecretConfigSection.SectionName);

            string appkey    = configSection.CaiNiao.AppKey;
            string appSecret = configSection.CaiNiao.AppSecret;
            string url       = configSection.CaiNiao.PacUrl;
            string token     = "";

            //测试
            //  token = "TmpFU1ZOUGoyRnoybDZmT3lyaW9hWGR4VFNad0xNYTBUek9QZk9kamt2Z1hJMytsVkVHK0FjVW55T25wcUR1Qw==";
            //正式
            token = "WkFhU2ZYdnA2dkFPd2MvVlR2OTF6K2FuQ1NKejdrV0V1ZDE3VS8zTW9uQjhLOGx5VHBuUkgyMzgrc3Q1RnRZNw==";
            //List<TemplateCompanyModel> lst = new TemplateCompanyService().GetTemplateCompanyElementsByCondition(d => d.ExCode != "OTHER");

            //foreach (TemplateCompanyModel m in lst)
            // {
            //    var client = new PacClient(appkey, appSecret, url);
            //    string jsonParas = "{\"cpCode\":\""+m.ExCode+"\"}";
            //    TmsWaybillSubscriptionQueryRequest parasModel = jsonParas.FromJsonToObject<TmsWaybillSubscriptionQueryRequest>();
            //    parasModel.SoapFormat = PacSupportFormat.XML;

            //    var resp = client.Send(parasModel, token);
            //    if (resp.Success && resp.WaybillApplySubscriptionCols[0].BranchAccountCols.Count > 0)
            //    {
            //        Assert.IsNotNull(resp);
            //    }
            // }

            var    client    = new PacClient(appkey, appSecret, url);
            string jsonParas = "{\"cpCode\":\"ZTO\"}";
            CloudprintStandardTemplatesRequest parasModel = jsonParas.FromJsonToObject <CloudprintStandardTemplatesRequest>();

            parasModel.SoapFormat = PacSupportFormat.JSON;

            var resp = client.Send(parasModel, token);

            if (resp.Success)
            {
                Assert.IsNotNull(resp);
            }
        }
Ejemplo n.º 3
0
        public void GetDianZiDanHaoTest()
        {
            //加载配置
            AppSecretConfigSection configSection = ConfigHelper.GetConfigSection <AppSecretConfigSection>(AppSecretConfigSection.SectionName);

            string appkey    = configSection.CaiNiao.AppKey;
            string appSecret = configSection.CaiNiao.AppSecret;
            string url       = configSection.CaiNiao.PacUrl;
            string token     = "TmpFU1ZOUGoyRnoybDZmT3lyaW9hWGR4VFNad0xNYTBUek9QZk9kamt2Z1hJMytsVkVHK0FjVW55T25wcUR1Qw==";

            //正式     WkFhU2ZYdnA2dkFPd2MvVlR2OTF6K2FuQ1NKejdrV0V1ZDE3VS8zTW9uQjhLOGx5VHBuUkgyMzgrc3Q1RnRZNw==
            token = "WkFhU2ZYdnA2dkFPd2MvVlR2OTF6K2FuQ1NKejdrV0V1ZDE3VS8zTW9uQjhLOGx5VHBuUkgyMzgrc3Q1RnRZNw==";
            var    client    = new PacClient(appkey, appSecret, url);
            string jsonParas = "{\"cpCode\":\"ZTO\"}";
            TmsWaybillSubscriptionQueryRequest parasModel = jsonParas.FromJsonToObject <TmsWaybillSubscriptionQueryRequest>();

            parasModel.SoapFormat = PacSupportFormat.JSON;

            var resp = client.Send(parasModel, token);

            Assert.IsNotNull(resp);
        }
Ejemplo n.º 4
0
        //https://developer.telerik.com/featured/understanding-asp-net-core-initialization/

        /*https://docs.microsoft.com/en-us/aspnet/core/fundamentals/startup?view=aspnetcore-2.1#the-configureservices-method
         * The ConfigureServices method
         * The ConfigureServices method is:
         * Optional
         * Called by the web host before the Configure method to configure the app's services.
         * Where configuration options are set by convention
         * note: IServiceCollection services 变量并不是 application级的全局引用,而是一个 .临时变量
         */
        #endregion

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            #region CORS 支持


            //支持跨域请求CORS
            var urls = ConfigHelper.AppSettingsConfiguration.GetConfig("CORS-Domin").Split(',');
            services.AddCors(options => options.AddPolicy(
                                 "AllowAllDomain",
                                 builder => builder.WithOrigins(urls)
                                 .AllowAnyHeader()
                                 .AllowAnyMethod()
                                 .AllowCredentials()
                                 )
                             );
            services.AddSession(options =>
            {
                options.Cookie.SameSite = Microsoft.AspNetCore.Http.SameSiteMode.None;
            });


            // configure the application cookie
            services.ConfigureApplicationCookie(options =>
            {
                options.Cookie.SameSite = Microsoft.AspNetCore.Http.SameSiteMode.None;
            });

            #endregion

            //内存缓存支持
            services.AddMemoryCache();
            //返回json  大小写控制
            services.AddMvc().AddJsonOptions(op => op.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver());;

            //将http 上下文中间件 添加的依赖注册容器
            // HttpContext在整个中间件贯穿。基于构造函数依赖:public UserRepository(IHttpContextAccessor httpContextAccessor)            2.1 之前手工写法services.AddSingleton<Microsoft.AspNetCore.Http.IHttpContextAccessor, Microsoft.AspNetCore.Http.HttpContextAccessor>();
            //https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-context?view=aspnetcore-2.1
            //https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-2.1
            services.AddHttpContextAccessor();
            //依赖注入验证服务
            services.AddTransient <IAuthenticationService, AuthenticationService>();


            #region 平台设置依赖注册组件


            //支付宝配置加载---注册:
            var alipayConfig = ConfigHelper.GetConfigSection <AlipayConfigSection>(AlipayConfigSection.SectionName);
            if (null != alipayConfig)
            {
                services.AddAlipay(options =>
                {
                    options.AlipayPublicKey = alipayConfig.AppPublicKey;     // "支付宝开放平台的应用公钥";
                    options.AppId           = alipayConfig.AppId.ToString(); // "应用ID";
                    options.CharSet         = alipayConfig.CharSet;          // "密钥编码";
                    options.Gatewayurl      = alipayConfig.Gatewayurl;       // "支付网关";
                    options.PrivateKey      = alipayConfig.PrivateKey;       // "商家私钥";
                    options.SignType        = alipayConfig.SignType;         // "签名方式 RSA/RSA2";
                    options.Uid             = alipayConfig.Uid.ToString();   // "商户ID";
                });
            }



            // 批多多服务依赖注册---IPddService
            AppSecretConfigSection configSection = ConfigHelper.GetConfigSection <AppSecretConfigSection>(AppSecretConfigSection.SectionName);
            services.AddPdd(options =>
            {
                //注册 id  secret
                options.ClientId     = configSection.Pdd.client_id;
                options.ClientSecret = configSection.Pdd.client_secret;
                options.CallbackUrl  = configSection.Pdd.redirect_uri;
            });


            //菜鸟打印ISV依赖注册----ICaiNiaoPacService
            services.AddCaiNiaoPac(options =>
            {
                //注册 id  secret
                options.AppKey    = configSection.CaiNiao.AppKey;
                options.AppSecret = configSection.CaiNiao.AppSecret;
                options.PacUrl    = configSection.CaiNiao.PacUrl;
            });

            #endregion
        }