發表文章

目前顯示的是有「spring boot」標籤的文章

Line Robot ( 四 ) - Reply Message API (Include reply message object)

圖片
前 言:     在 上一章 有提到如何回應使用者訊息,故本文就來探討Line回應訊息及主動發送訊息的功能。     Line提供了各網路接口(API)提供開發者去使用其服務,其中有Reply Message API以及Push Message API與Send Multicast Message API。 Reply Message API 網址 https://api.line.me/v2/bot/message/reply 請求方法 POST Request headers Content-Type application/json Authorization Bearer { channel access token } channel access token在Line機器人設定中有Channel access token選項,按下右方按鈕即可產生channel access token。 Request body 屬性名稱 資料型別 註解 replyToken String Reply token received via webhook messages Array of message objects Messages Max: 5     Line官方提供了數個Message Object供使用者任意搭配使用,要注意的是每次傳送的Message Object數量最大為五個,接下來開始介紹基本的Message Object Text message Property Type Description type String text text String Message text. You can include the following emoji: Unicode emoj...

Line Robot ( 三 ) - 實作echo Robot

圖片
前 言:     此功能如標題所描述,當使用者對Line Robot傳送什麼訊息,Line Robot就回應什麼訊息至使用 者。 編譯環境(工具): JDK1.8、eclipse 開始製作:     前幾篇 有提到,編寫Line Robot如同撰寫Web API,而在Java近幾年比較流行使用Spring boot開發,故作者以Spring boot框架去製作,而在Spring boot官網中有提供 Spring Initializr 製作Spring boot的開發包,故我們先點選我們所需要的套件後並下載。 將專案導入至eclipse 接著先撰寫測試的API街口判斷Spring boot是否正常運作(萬年的 Hello java出場) @RequestMapping("/robot") @RestController public class RobotController { @Value("${line.user.secret}") private String LINE_SECRET; @Autowired private HttpServletRequest httpServletRequest; @GetMapping("/test") public ResponseEntity test(){ return new ResponseEntity ("Hello J A V A", HttpStatus.OK); } }     完工後運行並在瀏覽器輸入   http://localhost:8080/robot/test  ,網頁是否出現Hello Java等字樣,如果有的話證明了Spring boot功能正常,接著開始進入主題 - Line echo robot。     首先在第二章節有提到所有Line的訊息皆是由Line伺服器傳送至Line robot中,而其間的協定走的是Post Method,且還要處理 第二章節 提到的Line伺服器驗證故作者的程式如下: public boolean checkFromLine(String requestBody...