thongkorn โพสต์ 2018-9-25 22:32:39

[VB.NET] แจกฟรีโค้ดการแจ้งเตือนผ่าน Line หรือที่เรียกกันว่า Line Notify

http://www.g2gnet.com/webboard/images/vbnet/LineNotify.png

การแจ้งเตือนผ่าน Line หรือ Line Notify จัดเป็นของเล่นสำหรับตัวแอดมินในเวลานี้ เพราะแอดมินก็ยังไม่รู้จะเอาไปทำประโยชน์อะไรดี นอกจากจะแจกโค้ดและอธิบายวิธีการทำ Line Notify ขึ้นมาด้วย VB.NET ... อันดับแรกต้องมี Line Account ก่อนล่ะครับ (ปกติก็มีกันอยู่แล้วแน่นอน) จากนั้นสมัครใช้ Line Notify ได้ที่ https://notify-bot.line.me/th/ ... เมื่อเรียบร้อยแล้วให้เข้ามาที่ หน้าออก Access Token (สำหรับผู้พัฒนา) ...

ต้องเพิ่ม LINE Nottify เป็นเพื่อน ก่อนที่จะใช้งาน API และส่งการแจ้งเตือน ท่านต้องเพิ่ม LINE Notify เป็นเพื่อนก่อน โดยสแกน QR Code ด้านล่างนี้
http://www.g2gnet.com/webboard/images/vbnet/linenotifyadd.png


http://www.g2gnet.com/webboard/images/vbnet/LineNotifyStart.png
คลิ๊กเลือก ออก Token ...

http://www.g2gnet.com/webboard/images/vbnet/LineNotifyToken.png
ออก Token ก็ทำตามภาพเลยครับ โดยที่หมายเลข 2 แอดมินเลือกให้ส่งหรือแจ้งเตือนมายังไลน์แอดมิน (หรือจะเลือก Group ก็ได้ครับ) ...

http://www.g2gnet.com/webboard/images/vbnet/LineNotifyTokenGet.png
Token ที่ออก จะเป็นรหัสยาวเฟื้อย เราควรคัดลอกเก็บเอาไว้ด้วยครับ และต้องนำค่านี้ไปใช้ต่อหลังคำว่า Bearer ที่อยู่ในโค้ด VB.NET ...


http://www.g2gnet.com/webboard/images/vbnet/LineNotifyEnd.png
หลังจากกดปุ่มปิด ... ก็เป็นอันจบในการกำหนดค่าต่างๆใน Line จากนั้นไปดูโค้ดโปรแกรมได้เลยทันที ...

มาดูโค้ดกันเถอะ ... ให้แก้ไขโดยการใส่ Token บริเวณคำว่า YOUR TOKEN HERE ตามคำสั่งนี้ Request.Headers.Add("Authorization", "Bearer YOUR TOKEN HERE")
' / --------------------------------------------------------------------------------
' / Developer : Mr.Surapon Yodsanga (Thongkorn Tubtimkrob)
' / eMail : thongkorn@hotmail.com
' / URL: http://www.g2gnet.com (Khon Kaen - Thailand)
' / Facebook: https://www.facebook.com/g2gnet (For Thailand)
' / Facebook: https://www.facebook.com/commonindy (Worldwide)
' / Purpose: Line Notify with VB.NET (2010)
' / Microsoft Visual Basic .NET (2010)
' /
' / This is open source code under @Copyleft by Thongkorn Tubtimkrob.
' / You can modify and/or distribute without to inform the developer.
' / --------------------------------------------------------------------------------
Imports System.Net
Imports System.Text
Imports System.IO

Public Class frmLineNotify
    '//
    Private Sub frmLineNotify_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
      txtMessage.Text = "ทดสอบการส่ง Line Notify จากคุณทองก้อน นารีแขยง"
    End Sub

    Private Sub btnSend_Click(sender As System.Object, e As System.EventArgs) Handles btnSend.Click
      If String.IsNullOrEmpty(txtMessage.Text.Trim) Then
            MessageBox.Show("Nothing message to send.", "Report Status", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Return
      End If
      Try
            Cursor.Current = Cursors.WaitCursor
            System.Net.ServicePointManager.Expect100Continue = False
            Dim Request = DirectCast(WebRequest.Create("https://notify-api.line.me/api/notify"), HttpWebRequest)
            '// Message to Line
            Dim LineMessage = String.Format("message={0}", txtMessage.Text & vbCrLf & "วันที่ - เวลา : " & FormatDateTime(Now(), DateFormat.GeneralDate))
            Dim MyData = Encoding.UTF8.GetBytes(LineMessage)
            '//
            Request.Method = "POST"
            '// Initialize
            With Request
                .ContentType = "application/x-www-form-urlencoded"
                .ContentLength = MyData.Length
                '// Change your Token and don't cut "Bearer".
                .Headers.Add("Authorization", "Bearer YOUR TOKEN HERE")
                .AllowWriteStreamBuffering = True
                .KeepAlive = False
                .Credentials = CredentialCache.DefaultCredentials
            End With
            '//
            Using Stream = Request.GetRequestStream()
                Stream.Write(MyData, 0, MyData.Length)
            End Using
            Dim response = DirectCast(Request.GetResponse(), HttpWebResponse)
            Dim responseString = New StreamReader(response.GetResponseStream()).ReadToEnd()

      Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
      Finally
            Cursor.Current = Cursors.Default
      End Try
    End Sub

    Private Sub btnClose_Click(sender As System.Object, e As System.EventArgs) Handles btnClose.Click
      Me.Close()
    End Sub

    Private Sub frmLineNotify_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
      Me.Dispose()
      Application.Exit()
    End Sub

End Class
ดาวน์โหลดโค้ดฉบับเต็ม VB.NET (2010) ได้ที่นี่ ...

hot2 โพสต์ 2018-9-26 05:50:55

ขอบคุณครับเฮีย เอาไว้ส่งสรุปยอดขายรายวันเข้าถืออก็น่าจะดีครับ

g2gsoftuser โพสต์ 2022-10-25 16:50:49

ขอบคุณครับ
หน้า: [1]
ดูในรูปแบบกติ: [VB.NET] แจกฟรีโค้ดการแจ้งเตือนผ่าน Line หรือที่เรียกกันว่า Line Notify