Example #1
0
        /// <summary>
        /// 通过模式2提交到监听者
        /// 通过HTTP协议Post消息到ListenerWebUrl的web接口,提交的对象类型为SMessagePostData
        /// 其中Signature为Id+Type+Data+CurrentTime的字符串格式(yyyy-MM-dd hh:mm:ss)通过ListenerWebSignature签名后的字符串
        /// 接收方需要对此进行校验
        /// </summary>
        /// <param name="listener"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        private async Task <ValidateResult> PostToListenerByMode2(SMessageTypeListener listener, SMessage message)
        {
            ValidateResult result = new ValidateResult()
            {
                Result = true
            };
            var expireTime        = DateTime.UtcNow.AddSeconds(300);
            var strContent        = $"{message.ID.ToString()}{message.Type}{message.Data}{expireTime.ToString("yyyy-MM-dd hh:mm:ss")}";
            var strSignature      = _securityService.SignByKey(strContent, listener.ListenerWebSignature);
            SMessagePostData data = new SMessagePostData()
            {
                ID         = message.ID,
                ExpireTime = expireTime,
                Type       = message.Type,
                Data       = message.Data,
                Signature  = strSignature
            };

            try
            {
                await HttpClinetHelper.PostAsync(data, listener.ListenerWebUrl);
            }
            catch (Exception ex)
            {
                result.Result      = false;
                result.Description = ex.Message;
            }

            return(result);
        }
Example #2
0
        public static async Task RetryPost(int maxRetry, JObject request, string url, Dictionary <string, string> headers, Func <JObject, HttpResponseMessage, Task> action)
        {
            int retryNumber = 0;

            while (true)
            {
                HttpResult <JObject> resultObj = null;
                try
                {
                    resultObj = await HttpClinetHelper.PostWithResponseAsync <JObject, JObject>(request, url, headers, CrmHelper.WebApiErrorHandler);
                }
                catch (UtilityException ex) when(ex.Code == (int)Errors.CrmWebApiLimitError)
                {
                    if (retryNumber >= maxRetry)
                    {
                        throw;
                    }
                    await Task.Delay((TimeSpan)ex.Data[CrmWebApiResponseKeyNames.RetryAfter]);

                    //System.Threading.Thread.Sleep(((TimeSpan)ex.Data[CrmWebApiResponseKeyNames.RetryAfter]));
                    retryNumber++;
                    continue;
                }
                await action(resultObj.Value, resultObj.Response);

                break;
            }
        }
Example #3
0
        public async Task Add(CommonLogModel model)
        {
            //获取服务描述
            var description = await _remoteServiceDescriptionRepositoryHelper.QueryByName(RemoteServiceNames.AddCommonLog);

            if (description == null)
            {
                var fragment = new TextFragment()
                {
                    Code = TextCodes.NotFoundRemoteServiceDescriptionByName,
                    DefaultFormatting = "找不到名称为{0}的远程服务描述",
                    ReplaceParameters = new List <object>()
                    {
                        RemoteServiceNames.AddCommonLog
                    }
                };

                throw new UtilityException((int)Errors.NotFoundRemoteServiceDescriptionByName, fragment);
            }
            //获取认证信息
            var authInfos = await description.GenerateAuthInfo();

            //调用服务
            await HttpClinetHelper.PostAsync(model, description.Address, authInfos);
        }
Example #4
0
        /// <summary>
        ///  通过模式2提交到web接口
        /// 通过HTTP协议Post消息到ScheduleActionServiceWebUrl的web接口,提交的对象类型为SMessagePostData
        /// 其中Signature为CurrentTime的字符串格式(yyyy-MM-dd hh:mm:ss)通过WebSignature签名后的字符串
        /// 接收方需要对此进行校验
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        private async Task <IScheduleActionResult> ExecuteByMode2(ScheduleAction action)
        {
            ScheduleActionResultDefault result = new ScheduleActionResultDefault();
            var currentTime  = DateTime.UtcNow;
            var strContent   = $"{currentTime.ToString("yyyy-MM-dd hh:mm:ss")}";
            var strSignature = _securityService.SignByKey(strContent, action.WebSignature);
            await HttpClinetHelper.PostAsync(strSignature, action.ScheduleActionServiceWebUrl);

            return(result);
        }
Example #5
0
        public async Task <RemoteServiceDescriptionInfo> GetServiceInfo(string name)
        {
            //获取配置服务基地址
            var serviceAddressConfig = _systemConigurationRepository.QueryByName(SystemConfigurationNames.ConfigurationServiceBaseAddress);
            var serviceAddress       = serviceAddressConfig.GetConfigurationValue <string>();
            var logInfos             = await _commonLogInfoGeneratorService.Generate();

            //调用配置服务中获取服务信息的方法
            var serviceInfo = await HttpClinetHelper.GetAsync <RemoteServiceDescriptionInfo>($"{serviceAddress}/api/serviceinfo/getbyname?name={name.ToUrlEncode()}", logInfos);

            return(serviceInfo);
        }
Example #6
0
 public string GetAccessToken(string username, string password, string apiUrl, out string errMsg)
 {
     errMsg = "";
     try
     {
         return(HttpClinetHelper.PostResponse(apiUrl, string.Format("username={0}&password={1}&grant_type=password", username, password)));
     }
     catch (Exception ex)
     {
         errMsg = ex.Message;
         return("");
     }
 }
Example #7
0
        //private ICommonLogInfoGeneratorService _commonLogInfoGeneratorService;
        //private ISystemConfigurationRepository _systemConigurationRepository;
        //public ChangePasswordService(ICommonLogInfoGeneratorService commonLogInfoGeneratorService)
        //{
        //    _commonLogInfoGeneratorService = commonLogInfoGeneratorService;
        //    _systemConigurationRepository = systemConigurationRepository;
        //}


        public async Task <ResultResponse> UpdatePwd(ChangePasswordModel model)
        {
            //获取配置服务基地址
            //var serviceAddressConfig = _systemConigurationRepository.QueryByName(SystemConfigurationNames.ConfigurationServiceBaseAddress);
            //var serviceAddress = serviceAddressConfig.GetConfigurationValue<string>();

            var serviceAddress = "https://subcrmuatceo.sokon.com/uc.inapitocrm/swagger/ui/index#!/User/User_UserResetPassWord?UserName="******"&PassWord="******"&OldPassWord="******"Authorization", "bearer " + accesstoken);
            //调用配置服务中获取服务信息的方法
            var serviceInfo = await HttpClinetHelper.GetAsync <ResultResponse>($"{serviceAddress}");

            return(serviceInfo);
        }
Example #8
0
 /// <summary>
 /// 模拟微信/支付宝退款接口
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 public async Task <SimulatedRefundResponse> SimulatedRefund(SimulatedRefundRequest request)
 {
     return(await Task.Run(() =>
     {
         var refund_id = GenerateOrderNo("420000");
         if (!string.IsNullOrEmpty(request.notify_url))
         {
             var callBackResponse = new RefundCallBackResponse()
             {
                 return_code = "SUCCESS",
                 appid = request.appid,
                 mch_id = request.mch_id,
                 nonce_str = request.nonce_str,
                 transaction_id = GenerateOrderNo("420000"),
                 out_trade_no = request.out_trade_no,
                 out_refund_no = request.out_refund_no,
                 refund_id = refund_id,
                 total_fee = request.total_fee,
                 refund_fee = request.refund_fee,
                 settlement_refund_fee = request.refund_fee,
                 refund_status = "SUCCESS",
                 success_time = DateTime.Now.ToString()
             };
             var results = HttpClinetHelper.PostAsync <RefundCallBackResponse, BaseRefundResponse>(callBackResponse, request.notify_url);
             //记录回调是否成功
             if (results != null)
             {
             }
         }
         return new SimulatedRefundResponse()
         {
             return_code = "SUCCESS",
             return_msg = "",
             appid = request.appid,
             mch_id = request.mch_id,
             nonce_str = request.nonce_str,
             sign = request.sign,
             out_trade_no = request.out_trade_no,
             out_refund_no = request.out_refund_no,
             refund_id = refund_id,
             total_fee = request.total_fee,
             refund_fee = request.refund_fee
         };
     }));
 }
Example #9
0
        /// <summary>
        /// 积分接口
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public async Task <ValidateResult> IntegralPost(IntegralRequest req)
        {
            ValidateResult res = new ValidateResult();

            try
            {
                string url = await GetConfig(IntegralUrl_Key);

                var ret = HttpClinetHelper.Post <IntegralRequest, string>(req, $"{url}/api/member/integralcreate");
                if (ret == "1")
                {
                    res.Result = true;
                }
            }
            catch (Exception e)
            {
                res.Result      = false;
                res.Description = e.Message;
            }
            return(res);
        }
Example #10
0
        //public MemberRightsService(ICommonLogInfoGeneratorService commonLogInfoGeneratorService, ISystemConfigurationRepository systemConigurationRepository)
        //{
        //    _commonLogInfoGeneratorService = commonLogInfoGeneratorService;
        //    _systemConigurationRepository = systemConigurationRepository;
        //}

        /// <summary>
        /// 获取整车订单权益项
        /// </summary>
        /// <returns></returns>
        public async Task <MemberRightsResponse> GetMemberRights()
        {
            //var userInfo = ContextContainer.GetValue<UserInfo>(ContextExtensionTypes.CurrentUserInfo);
            //var ProxyUserId = userInfo != null ? userInfo.systemuserid : null;


            //获取配置服务基地址
            //var serviceAddressConfig = _systemConigurationRepository.QueryByName(SystemConfigurationNames.ConfigurationServiceBaseAddress);
            //var serviceAddress = serviceAddressConfig.GetConfigurationValue<string>();

            var primaryActiveCode = "SERES-SF5";
            var userId            = "1000004";

            var serviceAddress = "http://mtkprd.seres.cn/mktcloud/order/v1/queryOrderRight?primaryActiveCode=" + primaryActiveCode + "&userId=" + userId + "&orderNo=";
            //var headDic = await _commonLogInfoGeneratorService.Generate();
            //var headDic = new Dictionary<string, string>();

            //调用配置服务中获取服务信息的方法
            var serviceInfo = await HttpClinetHelper.GetAsync <MemberRightsResponse>($"{serviceAddress}");

            return(serviceInfo);
        }
Example #11
0
 public async Task <List <SkuStockModel> > GetProductListByCode(QueryStockQuantityRequest model)
 {
     //调用服务
     return(await HttpClinetHelper.GetAsync <List <SkuStockModel> >($"{BaseUrl}/api/product/QueryStockQuantity?ProductCode={model.ProductCode}&ProductSkuCode={model.ProductSkuCode}"));
 }
Example #12
0
 public async Task <QueryProductAllResponse> QueryProductAllUpDate2(QueryProductAllRequest request)
 {
     //调用服务
     return(await HttpClinetHelper.PostAsync <QueryProductAllRequest, QueryProductAllResponse>(request, $"{BaseUrl}/api/product/All2"));
 }
Example #13
0
 public async Task <List <CategoryEntity> > GetAllFrontCategory2()
 {
     //调用服务
     return(await HttpClinetHelper.GetAsync <List <CategoryEntity> >($"{BaseUrl}/api/category/AllFrontCategory2"));
 }
Example #14
0
 public async Task <Product> QueryNewProductByCode(string productCode)
 {
     return(await HttpClinetHelper.PostAsync <string, Product>(productCode, $"{BaseUrl}/api/product/"));
 }
Example #15
0
 public async Task <List <CategoryEntity> > GetAllManagerCategory()
 {
     //调用服务
     return(await HttpClinetHelper.GetAsync <List <CategoryEntity> >($"{BaseUrl}/api/category/AllManagerCategory", AuthInfos));
 }
Example #16
0
        protected override void AfterUploadToFtp()
        {
            if (_fileGroups != null && _fileGroups.Any())
            {
                var fileType = "2";
                var type     = "2";
                foreach (var key in _fileGroups.Keys)
                {
                    var filePath = string.Join(";", _fileGroups[key]);
                    var dto      = new UploadZipDto
                    {
                        FilePath = filePath,
                        FileType = fileType,
                        Type     = type
                    };

                    try
                    {
                        var resp = HttpClinetHelper.PostResponseJson(ConfigContext.Current.DefaultConfig["Upload:SLWJRK"], JsonConvert.SerializeObject(dto));
                        _logger.Debug(resp);

                        //TODO:给laycontentId赋值
                        if (!resp.Contains("error"))
                        {
                            var model = JsonConvert.DeserializeObject <InfoEarthFrame.ServerInterfaceApp.ServerInterfaceAppService.UploadResult>(resp);
                            if (model != null)
                            {
                                var layer = Layers.FirstOrDefault(p => p.LayerName.ToLower() == key.ToLower());
                                if (layer != null && model.LayerContentEntity != null)
                                {
                                    layer.LayerContentId = model.LayerContentEntity.Id;
                                }
                                else
                                {
                                    layer.LayerContentId = Guid.NewGuid().ToString() + "_geo-200";

                                    this.ErrorInfo.Add("图层文件入库失败:" + model.Message + ",相关文件:" + string.Join("、", dto.FilePath.Split(';').Select(p => Path.GetFileName(p))) + "");
                                    this.IsGeoServerError = true;
                                }
                            }
                        }
                        else
                        {
                            throw new Exception(resp);
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.Error(ex);

                        var layer = Layers.FirstOrDefault(p => p.LayerName.ToLower() == key.ToLower());
                        if (layer != null)
                        {
                            layer.LayerContentId = Guid.NewGuid().ToString() + "_geo500";
                        }
                        this.ErrorInfo.Add("图层文件入库出错,相关文件:" + string.Join("、", dto.FilePath.Split(';').Select(p => Path.GetFileName(p))) + ",错误信息:" + ex.Message);
                        this.IsGeoServerError = true;
                    }
                }
            }
        }
Example #17
0
 public async Task <CreateOrderManagerResponse> CreateOrder(CreateOrderManagerRequest request)
 {
     return(await HttpClinetHelper.PostAsync <CreateOrderManagerRequest, CreateOrderManagerResponse>(request, $"{BaseUrl}/api/order/CreateOrder"));
 }
Example #18
0
 public async Task <QueryProductByCodeResponse> QueryProductByCode(string productCode)
 {
     //调用服务
     return(await HttpClinetHelper.GetAsync <QueryProductByCodeResponse>($"{BaseUrl}/api/product/Detail?productCode={productCode}"));
 }
Example #19
0
 public async Task <QueryProductAllResponse> QueryProductByCategory(string code)
 {
     //调用服务
     return(await HttpClinetHelper.GetAsync <QueryProductAllResponse>($"{BaseUrl}/api/product/QueryProductByCategory?code={code}"));
 }