https://developers.line.biz/zh-hant/
申請完Channel後就可以用QRCode加入好友
點選下方的Edit可以試試修改基本回應訊息
pip install line-bot-sdk==1.8.0
pip install django
在目標資料夾輸入命令
django-admin startproject linebot_server
注意要在和manage.py同層目錄執行
python manage.py startapp testapi
- templates(html模板)
- static(django使用圖片,CSS,javascript..都在此目錄)
python manage.py migrate
預設使用8000 port,可以在後面帶port號調整
python manage.py runserver 8000
啟動成功驗證是否正常 http://127.0.0.1:8000/
ngrok 因為line只接受https,可以簡單使用ngrok.exe生成https網址
ngrok http 8000
記得回到line網站設定Webhook URL、開啟Use webhook
import os
LINE_CHANNEL_ACCESS_TOKEN = '使用者 Channel access token'
LINE_CHANNEL_SECRET = 'Channel secret'
ALLOWED_HOSTS = ['*']
INSTALLED_APPS = [
...
'testapi', #新增的APP
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR), 'templates'], #templates路徑
...
},
]
LANGUAGE_CODE = 'zh-Hant' #繁體中文
TIME_ZONE = 'Asia/Taipei' #台北時區
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'), #加入static路徑
]
from django.conf.urls import url
from testapi import views
urlpatterns = [
url('^callback', views.callback), #設定callback對應
path('admin/', admin.site.urls),
]
撰寫views.py處理回應訊息邏輯