Beispiel #1
0
        internal ErrModel GetErrData()
        {
            ErrModel errMsg = new ErrModel();
            DateTime myDate = DateTime.Now;

            try
            {
                #region Request ID
                if (!string.IsNullOrEmpty(_context.Items[SettingHelper.Re_quest_Id].ToString()))
                {
                    errMsg.RequestId = _context.Items[SettingHelper.Re_quest_Id].ToString();
                }
                #endregion Request ID

                #region  錯誤訊息
                if (_message != null)
                {
                    errMsg.ErrMessage     = _message;
                    errMsg.ErrStackTrace  = _stacktrace;
                    errMsg.InnerException = _innerException;
                }

                if (_context.Items["ErrorMessage"] != null)
                {
                    errMsg.ErrMessage    = _context.Items["ErrorMessage"].ToString();
                    errMsg.ErrStackTrace = _context.Items["ErrorStackTrace"].ToString();
                }

                #endregion  錯誤訊息

                #region URL路徑 && 呼叫方法
                if (_context.Request.Path.HasValue)
                {
                    errMsg.ActionData = _context.Request.Path.Value;
                }
                #endregion URL路徑 && 呼叫方法

                return(errMsg);
            }
            catch (Exception ex)
            {
                log.ObjectErrorLog(ex.Message + ex.StackTrace, Directory.GetCurrentDirectory());
            }
            return(errMsg);
        }
Beispiel #2
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        private bool CommSendMessage(string data)
        {
            string accessToken = "accessToken";
            string result      = string.Empty;

            try
            {
                string url = string.Format("https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={0}", accessToken);
                result = HttpRequestHelper.HttpPostWebRequest(url, 100000, data);//post发送数据
                ErrModel err = JsonHelper.JsonDeserialize <ErrModel>(result);
                if (!string.IsNullOrEmpty(err.errcode))
                {
                    Log4NetHelper.WriteExceptionLog("发送消息失败;失败原因" + err.errmsg);//失败日志
                    return(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                Log4NetHelper.WriteExceptionLog("发送消息异常", ex, data, result);//记录异常
                return(false);
            }
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="url"></param>
        /// <param name="encoding"></param>
        /// <returns></returns>
        public static ErrModel HttpGetData(string url, Encoding encoding = null)
        {
            ErrModel model = new ErrModel();

            if (encoding == null)
            {
                encoding = Encoding.UTF8;
            }
            HttpClient httpClient = new HttpClient();
            var        t          = httpClient.GetAsync(url);

            t.Wait();
            var type = t.Result.Content.Headers.ContentType.MediaType;

            if (type.ToLower() == "application/json")
            {
            }
            var stram = t.Result.Content.ReadAsStreamAsync();

            stram.Wait();
            model.Data = StreamToBytes(stram.Result);
            return(model);
        }