示例#1
0
        public void SendMessage(string msg)
        {
            var form = new LineNotifyEntity();

            form.message = msg;
            LineNotifyApi(form);
        }
示例#2
0
        //註:api 一小時只能呼叫1000次
        private void LineNotifyApi(LineNotifyEntity form, byte[] imageByte = null)
        {
            var linetoken = Setting.GetLineToken();
            var client    = new RestClient(UrlGenerator._LineNotifyUrl);
            var request   = new RestRequest();

            request.Method = Method.POST;
            if (imageByte == null)
            {
                request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
            }
            else
            {
                request.AddHeader("Content-Type", "multipart/form-data");
            }

            request.AddHeader("Authorization", $"Bearer {linetoken}");


            request.AddObject(form);
            if (imageByte != null)
            {
                request.AddFile("imageFile", imageByte, "img.jpeg", "image/jpeg");
            }


            var RawResponse = client.Execute(request);
            var res         = JsonConvert.DeserializeObject <LineNotifyResponse>(RawResponse.Content);

            if (res.status != 200)
            {
                log.Error($"Send Line Notify error status:{res.status} msg:{res.message}");
            }
        }
示例#3
0
        //發送訊息到line
        public void PubNotify(houseEntity house, PhotoListResponse photos)
        {
            var form = new LineNotifyEntity();

            form.message = Helper.NotifyMessageBuilder(house);
            if (photos != null)
            {
                var imageByte = ImageProcessor.ConvertMultipleImageIntoOne(photos);
                LineNotifyApi(form, imageByte);
            }
            else
            {
                LineNotifyApi(form);
            }
        }