public JObject LineNotifySend(LineNotifyPostModel PostValue)
        {
            this.Logger.LogInformation(JsonConvert.SerializeObject(PostValue, Formatting.Indented).Replace(" ", ""));
            JObject Result = new JObject();

            try
            {
                JObject result = lineNotifyService.LineNotify_Send(PostValue);
                if (result["status"] != null && result["status"].ToString().Trim() == "200")
                {
                    if (result["status"].ToString().Trim() == "200")
                    {
                        Result.Add("Code", (int)ErrorCodeEnum.Success);
                        Result.Add("Message", "訊息發送成功");
                    }
                    else
                    {
                        Result.Add("Code", result["status"].ToString());
                        Result.Add("Message", result["message"].ToString());
                        this.Logger.LogInformation(JsonConvert.SerializeObject(result, Formatting.Indented));
                    }
                }
                else
                {
                    Result = result;
                }
            }
            catch (Exception ex)
            {
                this.Logger.LogWarning(ex.Message);
                Result.Add("Code", "-99");
                Result.Add("Message", ex.Message);
            }
            return(Result);
        }
Ejemplo n.º 2
0
        public async Task LineNotify_Send(LineNotifyPostModel value)
        {
            string  result     = string.Empty;
            JObject PostResult = new JObject();

            try
            {
                LineNotify LineNotifyService = new LineNotify();//宣告LineNotify服務
                string     CheckResult       = LineNotify_Check(value);
                if (!string.IsNullOrEmpty(CheckResult))
                {
                    PostResult.Add("Code", (int)ErrorCodeEnum.ParameterisNull);
                    PostResult.Add("Message", CheckResult);
                    return;
                }
                Dictionary <string, string> HeadList = SendMessageHeaderCombin();
                string Message = SendMessageParameter_Combin(value);
                //呼叫傳送訊息API
                await _api.Post_async(LineNotifyService.LineNotifySendMessageURL_Get(), ContentTypeEnum.urlencoded, Message, _api.HeaderCombin(HeadList));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 3
0
        private string LineNotify_Check(LineNotifyPostModel value)
        {
            string Message = string.Empty;

            if (string.IsNullOrEmpty(value.Message))
            {
                return(Message = $"你Message為空,沒要發訊息不要來亂好嗎");
            }

            if (value.stickerPackageId != 0)
            {
                if (value.stickerId == 0)
                {
                    return(Message = $"stickerId不可為0");
                }
            }
            if (!string.IsNullOrEmpty(value.imageThumbnail))
            {
                if (string.IsNullOrEmpty(value.imageFullsize))
                {
                    return(Message = $"imageFullsize不可為空");
                }
            }
            return(Message);
        }
Ejemplo n.º 4
0
        public JObject LineNotify_Send(LineNotifyPostModel value)
        {
            string  result     = string.Empty;
            JObject PostResult = new JObject();

            try
            {
                LineNotify LineNotifyService = new LineNotify();//宣告LineNotify服務
                string     CheckResult       = LineNotify_Check(value);
                if (!string.IsNullOrEmpty(CheckResult))
                {
                    PostResult.Add("Code", (int)ErrorCodeEnum.ParameterisNull);
                    PostResult.Add("Message", CheckResult);
                    return(PostResult);
                }
                CheckResult = LineNotifyService.GroupToken_Get(value.TokenID);
                if (!string.IsNullOrEmpty(CheckResult))
                {
                    PostResult.Add("Code", (int)ErrorCodeEnum.ParameterisNull);
                    PostResult.Add("Message", CheckResult);
                    return(PostResult);
                }
                Dictionary <string, string> HeadList = LineNotifyService.SendMessageHeaderCombin(value.GroupKey);
                string Message = LineNotifyService.SendMessageParameter_Combin(value);
                //呼叫傳送訊息API
                PostResult = ApiHelper.Post(LineNotifyService.LineNotifySendMessageURL_Get(), Message, ApiHelper.HeaderCombin(HeadList));
            }
            catch (Exception ex)
            {
                this.Logger.LogWarning(ex.Message);
                throw ex;
            }
            return(PostResult);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 組合參數
        /// </summary>
        /// <param name="PostValue"></param>
        /// <returns></returns>
        public string SendMessageParameter_Combin(LineNotifyPostModel PostValue)
        {
            StringBuilder Parameterstring = new StringBuilder();

            Parameterstring.Append($"Message={PostValue.Message}");
            if (PostValue.stickerPackageId != 0)
            {
                Parameterstring.Append($"&stickerPackageId={PostValue.stickerPackageId}");
                Parameterstring.Append($"&stickerId={PostValue.stickerId}");
            }
            if (!string.IsNullOrEmpty(PostValue.imageThumbnail))
            {
                Parameterstring.Append($"&imageThumbnail={PostValue.imageThumbnail}");
                Parameterstring.Append($"&imageFullsize={PostValue.imageFullsize}");
            }

            return(Parameterstring.ToString());
        }