Created
May 30, 2018 10:18
-
-
Save jackrobotics/e880d987bd60bc1ae88ebd8aff689aa3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void notifyPicture(string url) | |
{ | |
_lineNotify(" ", 0, 0, url); | |
} | |
private void notifySticker(int stickerID, int stickerPackageID) | |
{ | |
_lineNotify(" ", stickerPackageID, stickerID, ""); | |
} | |
private void lineNotify(string msg) | |
{ | |
_lineNotify(msg, 0, 0, ""); | |
} | |
private void _lineNotify(string msg,int stickerPackageID, int stickerID, string pictureUrl) | |
{ | |
string token = "9IBnp37LVHj0a6W5HLq2dF7sqIjGyEVn2DQtpQq7wYv"; | |
try | |
{ | |
var request = (HttpWebRequest)WebRequest.Create("https://notify-api.line.me/api/notify"); | |
var postData = string.Format("message={0}", msg); | |
if (stickerPackageID>0 && stickerID>0) | |
{ | |
var stickerPackageId = string.Format("stickerPackageId={0}", stickerPackageID); | |
var stickerId = string.Format("stickerId={0}", stickerID); | |
postData += "&" + stickerPackageId.ToString() + "&" + stickerId.ToString(); | |
} | |
if (pictureUrl != "") | |
{ | |
var imageThumbnail = string.Format("imageThumbnail={0}", pictureUrl); | |
var imageFullsize = string.Format("imageFullsize={0}", pictureUrl); | |
postData += "&" + imageThumbnail.ToString() + "&" + imageFullsize.ToString(); | |
} | |
var data = Encoding.UTF8.GetBytes(postData); | |
request.Method = "POST"; | |
request.ContentType = "application/x-www-form-urlencoded"; | |
request.ContentLength = data.Length; | |
request.Headers.Add("Authorization", "Bearer "+token); | |
using (var stream = request.GetRequestStream())stream.Write(data, 0, data.Length); | |
var response = (HttpWebResponse)request.GetResponse(); | |
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.ToString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment