line_bot_api = LineBotApi(os.environ['CHANNEL_ACCESS_TOKEN']) handler = WebhookHandler(os.environ['CHANNEL_SECRET']) import os, urllib client_id = os.environ['NOTIFY_CLIENT_ID'] client_secret = os.environ['NOTIFY_CLIENT_SECRET'] redirect_uri = f"https://{os.environ['YOUR_HEROKU_APP_NAME']}.herokuapp.com/callback/notify" def create_auth_link(user_id, client_id=client_id, redirect_uri=redirect_uri): data = { 'response_type': 'code', 'client_id': client_id, 'redirect_uri': redirect_uri, 'scope': 'notify', 'state': user_id } query_str = urllib.parse.urlencode(data) return f'https://notify-bot.line.me/oauth/authorize?{query_str}' |
from flask import request @app.route("/callback/notify", methods=['GET']) def callback_nofity(): #assert request.headers['referer'] == 'https://notify-bot.line.me/' code = request.args.get('code') state = request.args.get('state') #print("Code:"+code) #print("state:"+state) #print(event.source.group_id) # Get Access-Token access_token = get_token(code, client_id, client_secret, redirect_uri) #print("AccessToken="+access_token) #print("Clinet_id"+client_id) google_sheet(client_id,access_token) send_message(access_token,text_message="你好") #發訊息 return '恭喜完成 LINE Notify 連動!請關閉此視窗。' #拿取幫綁訂人的access_token import json def get_token(code, client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri): url = 'https://notify-bot.line.me/oauth/token' headers = { 'Content-Type': 'application/x-www-form-urlencoded' } data = { 'grant_type': 'authorization_code', 'code': code, 'redirect_uri': redirect_uri, 'client_id': client_id, 'client_secret': client_secret } data = urllib.parse.urlencode(data).encode() req = urllib.request.Request(url, data=data, headers=headers) page = urllib.request.urlopen(req).read() res = json.loads(page.decode('utf-8')) #print(data) return res['access_token'] #利用notify發出訊息 def send_message(access_token, text_message): url = 'https://notify-api.line.me/api/notify' headers = {"Authorization": "Bearer "+ access_token} data = {'message': text_message} data = urllib.parse.urlencode(data).encode() req = urllib.request.Request(url, data=data, headers=headers) page = urllib.request.urlopen(req).read() |
CTF (2)
└Misc (3)
└Crypto (6)
└Revers (0)
└Pwn (0)
└Web (1)
└picoCTF 2018 (48)
└AIS3 2020 pre-exam (2)
Telegraf/Prometheus/Grafana (1)
未分類 (3)hyzgdivina 給 喜歡虹咲的LLer:
我的小屋裡有很多Hoenn繪師又香又甜的虹咲漫畫翻譯喔!歡迎大家來我的小屋坐坐~看更多昨天19:53