2024年11月21日 星期四

Messaging API作為替代方案

 LINE超好用功能要沒了!LINE Notify明年3月底終止服務,有什麼替代方案?

LINE Notify將於2025年3月31日結束服務,官方建議改用Messaging API作為替代方案。





















//CHANNEL_ACCESS_TOKEN = 'Messaging API Token';


CHANNEL_ACCESS_TOKEN = 'E2ElxCQeoDszSHF0N1TJsyytnnae+HF1XZ733YVYj1RQcpjAT1oi2Fa2TScNbOz+q815fFVp4MuFW+UC4PsfKbvtc/o0OM6hchpxuQURZyvizGq+/cAz/TgCwJ9wQ4ebkQyEXEDzaYUZ/Dx3yaaBgwdB04t89/1O/w1cDnyilFU=';

USER_ID = 'Ua2f646d82a75d31dee884a6fdfa95f76';   //'使用者ID(不是Line ID)';



message = {

    type:'text',

    text:'目前日圓匯率:'+msg.payload.jpy

};

headers = {

    'Content-Type': 'application/json; charset=UTF-8',

    'Authorization': 'Bearer ' + CHANNEL_ACCESS_TOKEN,

};


payload = {

    'to':  USER_ID,

    'messages': [message]

};

msg.headers = headers;

msg.payload = payload;


return msg;



Node-Red程式


[{"id":"e3c78b4eb9b36766","type":"function","z":"e4f0d10c6b941ff5","name":"Set Line API ","func":"msg.headers = {'content-type':'application/x-www-form-urlencoded','Authorization':'Bearer A4wwPNh2WqB7dlfeQyyIAwtggn1kfZSI5LkkCdia1gB'};\nmsg.payload = {\"message\":msg.payload};\nreturn msg;\n\n//oR7KdXvK1eobRr2sRRgsl4PMq23DjDlhfUs96SyUBZu","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":350,"y":80,"wires":[["d259989e5f0c687e","32a55009c3264c1a"]]},{"id":"d259989e5f0c687e","type":"http request","z":"e4f0d10c6b941ff5","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"https://notify-api.line.me/api/notify","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":510,"y":80,"wires":[["9a3461f722903f80"]]},{"id":"9a3461f722903f80","type":"debug","z":"e4f0d10c6b941ff5","name":"debug 319","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":80,"wires":[]},{"id":"e8c26f627214b891","type":"comment","z":"e4f0d10c6b941ff5","name":"Line Notify Message ","info":"","x":160,"y":20,"wires":[]},{"id":"95a71388533af3b8","type":"ui_audio","z":"e4f0d10c6b941ff5","name":"","group":"c9efaecb79309b70","voice":"Microsoft Hanhan - Chinese (Traditional, Taiwan)","always":"","x":510,"y":140,"wires":[]},{"id":"93f1a65f0c4b5f5e","type":"delay","z":"e4f0d10c6b941ff5","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":350,"y":140,"wires":[["95a71388533af3b8"]]},{"id":"f55a546528eea8fa","type":"inject","z":"e4f0d10c6b941ff5","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"哈囉","payloadType":"str","x":140,"y":80,"wires":[["e3c78b4eb9b36766","93f1a65f0c4b5f5e","9cde4d571ca039f8"]]},{"id":"9cde4d571ca039f8","type":"debug","z":"e4f0d10c6b941ff5","name":"debug 320","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":340,"y":40,"wires":[]},{"id":"32a55009c3264c1a","type":"debug","z":"e4f0d10c6b941ff5","name":"debug 321","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":540,"y":40,"wires":[]},{"id":"639381b4.decba","type":"inject","z":"e4f0d10c6b941ff5","name":"","repeat":"3600","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":520,"wires":[["63a4a95.925ad58"]]},{"id":"63a4a95.925ad58","type":"http request","z":"e4f0d10c6b941ff5","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://rate.bot.com.tw/xrt?Lang=zh-TW","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":280,"y":520,"wires":[["38a8cc.2269c734","62c92c02bdc3eb99"]]},{"id":"38a8cc.2269c734","type":"html","z":"e4f0d10c6b941ff5","name":"filter","property":"payload","outproperty":"payload","tag":".rate-content-cash.text-right.print_hide","ret":"html","as":"single","x":430,"y":520,"wires":[["29ecf860.b24508","91e26219.6161e"]]},{"id":"29ecf860.b24508","type":"function","z":"e4f0d10c6b941ff5","name":"Get JPY Currency 1","func":"var currency = 0.20;\n\nvar data = {\n    jpy: Number(msg.payload[15])\n}\n\nvar isLow =  flow.get('isLow') || false;\nmsg.payload = data\nif (data.jpy < currency && !isLow) {\n    isLow = true;\n    flow.set('isLow', isLow);\n    return msg;\n}\nif (data.jpy > currency && !isLow) {\n    isLow = false;\n    flow.set('isLow', isLow);\n    return msg;\n}","outputs":1,"noerr":0,"x":640,"y":520,"wires":[["8dc397w373.5403288","038ebd4c7f77884c"]]},{"id":"1d418e6a.0e52a2","type":"debug","z":"e4f0d10c6b941ff5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":830,"y":480,"wires":[]},{"id":"8dc397w373.5403288","type":"function","z":"e4f0d10c6b941ff5","name":"傳送信息","func":"//CHANNEL_ACCESS_TOKEN = 'Messaging API Token';\nCHANNEL_ACCESS_TOKEN = 'E2ElxCQeoDszSHF0N1TJsyytnnae+HF1XZ733YVYj1RQcpjAT1oi2Fa2TScNbOz+q815fFVp4MuFW+UC4PsfKbvtc/o0OM6hchpxuQURZyvizGq+/cAz/TgCwJ9wQ4ebkQyEXEDzaYUZ/Dx3yaaBgwdB04t89/1O/w1cDnyilFU=';\nUSER_ID = 'Ua2f646d82a75d31dee884a6fdfa95f76'; //'使用者ID(不是Line ID)';\nmessage = {\n    type:'text',\n    text:'目前日圓匯率:'+msg.payload.jpy\n};\nheaders = {\n    'Content-Type': 'application/json; charset=UTF-8',\n    'Authorization': 'Bearer ' + CHANNEL_ACCESS_TOKEN,\n};\npayload = {\n    'to':  USER_ID,\n    'messages': [message]\n};\nmsg.headers = headers;\nmsg.payload = payload;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":820,"y":580,"wires":[["ea9fccf4.509b4"]]},{"id":"ea9fccf4.509b4","type":"http request","z":"e4f0d10c6b941ff5","name":"Messaging API 傳送","method":"POST","ret":"txt","paytoqs":"ignore","url":"https://api.line.me/v2/bot/message/push","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":1000,"y":580,"wires":[["5c8619a1.7b35a8"]]},{"id":"a3af338a.4308","type":"http in","z":"e4f0d10c6b941ff5","name":"Messaging API 接收","url":"","method":"post","upload":false,"swaggerDoc":"","x":170,"y":700,"wires":[["3774c8fd.50b198"]]},{"id":"3774c8fd.50b198","type":"debug","z":"e4f0d10c6b941ff5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":370,"y":700,"wires":[]},{"id":"5c8619a1.7b35a8","type":"debug","z":"e4f0d10c6b941ff5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1190,"y":580,"wires":[]},{"id":"91e26219.6161e","type":"function","z":"e4f0d10c6b941ff5","name":"GET JP Currency 2","func":"//var jp = msg.payload[15];\nvar data = {\n    jpy: Number(msg.payload[15])\n}\nvar date = new Date();\nmsg.payload = data\nvar h = date.getHours();\nvar m = date.getMinutes();\nvar s = date.getSeconds();\nif(h<10){\n    h = '0'+h;\n}\nif(m<10){\n    m = '0' + m;\n}\nif(s<10){\n    s = '0' + s;\n}\nmsg.payload = '(' + h + ':' + m + ':' + s + ')\\n'+\n'日幣匯率:' + data.jpy ;\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":480,"wires":[["1d418e6a.0e52a2"]]},{"id":"62c92c02bdc3eb99","type":"debug","z":"e4f0d10c6b941ff5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":450,"y":560,"wires":[]},{"id":"038ebd4c7f77884c","type":"debug","z":"e4f0d10c6b941ff5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":830,"y":520,"wires":[]},{"id":"a77dd5e79cda71ae","type":"function","z":"e4f0d10c6b941ff5","name":"LINE  Messaging API","func":"//CHANNEL_ACCESS_TOKEN = 'Messaging API Token';\nCHANNEL_ACCESS_TOKEN = 'E2ElxCQeoDszSHF0N1TJsyytnnae+HF1XZ733YVYj1RQcpjAT1oi2Fa2TScNbOz+q815fFVp4MuFW+UC4PsfKbvtc/o0OM6hchpxuQURZyvizGq+/cAz/TgCwJ9wQ4ebkQyEXEDzaYUZ/Dx3yaaBgwdB04t89/1O/w1cDnyilFU=';\nUSER_ID = 'Ua2f646d82a75d31dee884a6fdfa95f76'; //'使用者ID(不是Line ID)';\n\nvar msg1=msg.payload;\n\nmessage = {\n    type:'text',\n    text:'Line Developers傳送的訊息:'+msg1\n};\n\n\nheaders = {\n    'Content-Type': 'application/json; charset=UTF-8',\n    'Authorization': 'Bearer ' + CHANNEL_ACCESS_TOKEN,\n};\npayload = {\n    'to':  USER_ID,\n    'messages': [message]\n};\nmsg.headers = headers;\nmsg.payload = payload;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":280,"wires":[["b9697b72e188770b"]]},{"id":"b9697b72e188770b","type":"http request","z":"e4f0d10c6b941ff5","name":"LINE Developers Messaging API 傳送","method":"POST","ret":"txt","paytoqs":"ignore","url":"https://api.line.me/v2/bot/message/push","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":610,"y":280,"wires":[["868ceae98d227c48"]]},{"id":"868ceae98d227c48","type":"debug","z":"e4f0d10c6b941ff5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":890,"y":280,"wires":[]},{"id":"19fef339aba6cd45","type":"inject","z":"e4f0d10c6b941ff5","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"哈囉","payloadType":"str","x":130,"y":280,"wires":[["a77dd5e79cda71ae"]]},{"id":"3004785b1fd576ce","type":"comment","z":"e4f0d10c6b941ff5","name":"Line  Developers","info":"","x":140,"y":240,"wires":[]},{"id":"d2749fb6ac34f812","type":"comment","z":"e4f0d10c6b941ff5","name":"官方建議改用Messaging API作為替代方案","info":"LINE Notify將於2025年3月31日結束服務,官方建議改用Messaging API作為替代方案。","x":220,"y":200,"wires":[]},{"id":"a2b7ba62fa9265d9","type":"node-line-bot-push-message","z":"e4f0d10c6b941ff5","name":"","useExternalMessage":false,"useExternalDestinationId":false,"hasDestinationId":true,"hasMessage":true,"message":"Hi, I am push message node 😊","messageType":0,"disabledNotification":false,"apiConfig":"b159d4d910a9bb05","credentials":{},"x":360,"y":340,"wires":[["6e6b1b08023263a3"]]},{"id":"6e6b1b08023263a3","type":"debug","z":"e4f0d10c6b941ff5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":570,"y":340,"wires":[]},{"id":"684deafd4ac910c9","type":"inject","z":"e4f0d10c6b941ff5","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":340,"wires":[["a2b7ba62fa9265d9"]]},{"id":"5d412d443b0f7ba3","type":"node-line-bot-push-message","z":"e4f0d10c6b941ff5","name":"","useExternalMessage":true,"useExternalDestinationId":false,"hasDestinationId":true,"hasMessage":true,"message":"Hi, I am push message node 😊","messageType":0,"disabledNotification":true,"apiConfig":"b159d4d910a9bb05","x":360,"y":400,"wires":[["67abc426251151d6"]]},{"id":"67abc426251151d6","type":"debug","z":"e4f0d10c6b941ff5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":570,"y":400,"wires":[]},{"id":"08175c5e5d2432e1","type":"debug","z":"e4f0d10c6b941ff5","name":"debug 322","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":330,"y":440,"wires":[]},{"id":"8ebe9e3e08e9d256","type":"inject","z":"e4f0d10c6b941ff5","name":"Send msg","props":[{"p":"payload"},{"p":"messageType","v":"0","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Normal Text Example 😊","payloadType":"str","x":140,"y":420,"wires":[["5d412d443b0f7ba3","08175c5e5d2432e1"]]},{"id":"c9efaecb79309b70","type":"ui_group","name":"LED控制區","tab":"fd234124f2ccfcf6","order":1,"disp":true,"width":4,"collapse":false,"className":""},{"id":"b159d4d910a9bb05","type":"line-messaging-api-config","channelName":"日幣匯率","hasToken":true,"hasSecret":true,"credentials":{}},{"id":"fd234124f2ccfcf6","type":"ui_tab","name":"2024-09-EX3","icon":"dashboard","order":135,"disabled":false,"hidden":false}]

沒有留言:

張貼留言

113 學年度第 1 學期 RFID應用課程 Arduino程式

113 學年度第 1 學期 RFID應用課程 Arduino程式 https://www.mediafire.com/file/zr0h0p3iosq12jw/MFRC522+(2).7z/file 內含修改過後的 MFRC522 程式庫 (原程式有錯誤) //定義MFRC522...