NodeRed動態產QRcode

--

NodeRed 一景

專案目的

根據網址動態生成QRcode圖檔。

設計流程

  1. 將必須套件匯入NodeRed
  2. 使用context.global.[套件名]

參考資料

  1. [匯入套件]

匯入NodeRed

先透過npm install 裝入自己想要的套件,然後在 bluemix-settings.js 裡面加上自己想要放入的套件

functionGlobalContext: {humixapi: require('./server/lib/index.js'),qr: require('qr-image'),crypto: require('crypto'),
[想要的套件名稱]: require('想要匯入的套件')
},

接著在NodeRed 裡面的 function Node裡面,透過 contexnt.global.[想要的套件名稱] 就能引用出自己想要的功能與服務。

根據 Facebook id 加密產出範例

  1. input 拿到http node,並在URL設定 /encode/:user
  2. function 拿到 function node,並在裡面撰寫如下內文,其中msg.req.params.user 就是可以拿到 input裡面那個user裡的資訊

3. 到output 拿 http response node

這樣deploy之後,就能順利將服務啟動,連線到以下位置

http://localhost:1880/node-red/encode/[fb_id]http://localhost:1880/node-red/encode/123  <- 參考連結{href: "http://localhost:1880/node-red/qrcode/99123_6d6cd63284be4a47ba7aec4a3458939a95dcbdd5cd0438f23d7457099b4b917c"}

動態產出Qrcode 範例

  1. input 拿到http node,並在URL設定 /qrcode/:user
  2. function 拿到 function node,並在裡面撰寫如下內文,其中msg.req.params.user 就是可以拿到 input裡面那個user裡的資訊

3. 到output 拿 http response node

這樣deploy之後,就能順利將服務啟動,連線到以下位置

http://localhost:1880/node-red/qrcode/[自己想要埋藏的代碼]
http://localhost:1880/node-red/qrcode/asfsafadf

--

--

aha (Cheng-Yu Lin)
aha (Cheng-Yu Lin)

Written by aha (Cheng-Yu Lin)

Passionate about reading, gaming, and travel. Using AI to connect the physical & virtual worlds, I enjoy sharing ideas with others. Let's connect!

No responses yet