├── time.log ├── 1.txt ├── .github └── workflows │ └── autoapi.yml ├── 1.py └── README.md /time.log: -------------------------------------------------------------------------------- 1 | 2024-12-09 08:32:18 begin 2 | -------------------------------------------------------------------------------- /1.txt: -------------------------------------------------------------------------------- 1 | 1.AW8AOUOBGYutzUiQ3H2ECCuYLTruVYt0A-BAkb26nL7jYJFvAExvAA.AgABAwEAAADW6jl31mB3T7ugrWTT8pFeAwDs_wUA9P-1RU2Vb8n1AVZbnJPW21fOiPfTpPa0d--tUxruMQd8kSLvB4edmsveoPa3nfesCmJk-IcqGixDdxjzVEbn6euOC0TO9tB67RTLOm7xlWbEtq1i_x2biR6WDpulA_gEEDKiO7dC0lh1GJm_sRooc-7p9exKAtWXiiK-UK3qZPMX3mYczdA6HCSUX_605LY_PxMiUQEFnXkzdRPhR3551xjntIeQSyuCwna5nwY2oqSep1Ohg5lpxsxjcyoD-L7oVtV2g95c0oNku26iPqEhEjLkjOXBQ28802sggknX4TH9yEIX1Wrmg6E2tm5ihgsKQS3kpqkuwOnrAGTg0tWg4ErV4nHl4KOrG3n8GpCH7SGePHLNlwD8t4kPi_OG2rbyZVhc3W2drGviNyQTnZzAlEjap1tw7mlK3tL3OcJxwLMbIRkOktUyeYGCiGRMfaCNQhvTUf-v42RQN4lWE-05mqJDLF1I6jKOVzbNVvPjorLs5L83JdBxsGjzsuXus_wfrcWNeIDtINT9eKhFzFIaDk_3lRlZyB_rOtxHs5fX6q3AUOqC_06aK7zXPLfMK5oCJrBsx5kmDmkSzjeehf9LqrZ--hKbq7wtMCmyL8id4O0q7tgRZx2RxlOJWiuZCv2rPYwoLeGTdtECZV_VB89WbmplkCGTdeLxW7JonB0qZ2dcUHw -------------------------------------------------------------------------------- /.github/workflows/autoapi.yml: -------------------------------------------------------------------------------- 1 | #自动调用api保活,加密版 2 | name: Auto Api Secret 3 | 4 | on: 5 | release: 6 | types: [published, created, edited] 7 | push: 8 | tags: 9 | - 'v*' 10 | branches: 11 | - master 12 | schedule: 13 | - cron: '0 0-8 * * *' 14 | workflow_dispatch: 15 | inputs: 16 | 17 | jobs: 18 | build: 19 | runs-on: ubuntu-latest 20 | steps: 21 | - name: Checkout 22 | uses: actions/checkout@master 23 | - name: Set up Python #安装python 24 | uses: actions/setup-python@v1 25 | with: 26 | python-version: 3.8 27 | - name: Install requirements 28 | run: | 29 | pip install requests 30 | pip install telepot 31 | - name: Read config from secrets #读取机密 32 | env: 33 | CONFIG_ID: ${{ secrets.CONFIG_ID }} # secrets_id 提供 34 | CONFIG_KEY: ${{ secrets.CONFIG_KEY }} # secrets_key 提供 35 | run: | 36 | cp 1.py 2.py 37 | echo $CONFIG_ID > configid.txt 38 | echo $CONFIG_KEY > configkey.txt 39 | sed -i '10 r configid.txt' 2.py 40 | sed -i '12 r configkey.txt' 2.py 41 | - name: Test Api #Api调用 42 | run: | 43 | echo `date +"%Y-%m-%d %H:%M:%S"` begin > time.log 44 | python 2.py ${{ secrets.TELEBOT_TOKEN }} ${{ secrets.CHAT_ID }} 45 | - name: Delete secrets config #删除机密 46 | run: | 47 | rm -f 2.py 48 | rm -f configid.txt 49 | rm -f configkey.txt 50 | - name: Commit #上传新的refresh_token到仓库 51 | run: | 52 | git config --global user.email '${{ secrets.EMAIL }}' 53 | git config --global user.name ccknbc 54 | git add . 55 | git commit -m "update new refresh_token" -a 56 | - name: Push changes 57 | uses: ad-m/github-push-action@master 58 | with: 59 | github_token: ${{ secrets.GITHUB_TOKEN }} 60 | -------------------------------------------------------------------------------- /1.py: -------------------------------------------------------------------------------- 1 | # -*- coding: UTF-8 -*- 2 | import requests as req 3 | import json,sys,time 4 | import telepot 5 | #先注册azure应用,确保应用有以下权限: 6 | #files: Files.Read.All、Files.ReadWrite.All、Sites.Read.All、Sites.ReadWrite.All 7 | #user: User.Read.All、User.ReadWrite.All、Directory.Read.All、Directory.ReadWrite.All 8 | #mail: Mail.Read、Mail.ReadWrite、MailboxSettings.Read、MailboxSettings.ReadWrite 9 | #注册后一定要再点代表xxx授予管理员同意,否则outlook api无法调用 10 | 11 | 12 | 13 | 14 | 15 | 16 | path=sys.path[0]+r'/1.txt' 17 | num1 = 0 18 | token=str(sys.argv[1]) 19 | chat_id=str(sys.argv[2]) 20 | bot=telepot.Bot(token) 21 | fin=None 22 | 23 | def send(message): 24 | bot.sendMessage(chat_id,message, parse_mode=None, disable_web_page_preview=None, disable_notification=None, reply_to_message_id=None, reply_markup=None) 25 | 26 | def gettoken(refresh_token): 27 | headers={'Content-Type':'application/x-www-form-urlencoded' 28 | } 29 | data={'grant_type': 'refresh_token', 30 | 'refresh_token': refresh_token, 31 | 'client_id':id, 32 | 'client_secret':secret, 33 | 'redirect_uri':'http://localhost:53682/' 34 | } 35 | html = req.post('https://login.microsoftonline.com/common/oauth2/v2.0/token',data=data,headers=headers) 36 | jsontxt = json.loads(html.text) 37 | refresh_token = jsontxt['refresh_token'] 38 | access_token = jsontxt['access_token'] 39 | with open(path, 'w+') as f: 40 | f.write(refresh_token) 41 | return access_token 42 | def main(): 43 | fo = open(path, "r+") 44 | refresh_token = fo.read() 45 | fo.close() 46 | global num1 47 | global fin 48 | fin = localtime = time.asctime( time.localtime(time.time()) ) 49 | access_token=gettoken(refresh_token) 50 | headers={ 51 | 'Authorization':access_token, 52 | 'Content-Type':'application/json' 53 | } 54 | try: 55 | if req.get(r'https://graph.microsoft.com/v1.0/me/drive/root',headers=headers).status_code == 200: 56 | num1+=1 57 | print("1调用成功"+str(num1)+'次') 58 | if req.get(r'https://graph.microsoft.com/v1.0/me/drive',headers=headers).status_code == 200: 59 | num1+=1 60 | print("2调用成功"+str(num1)+'次') 61 | if req.get(r'https://graph.microsoft.com/v1.0/drive/root',headers=headers).status_code == 200: 62 | num1+=1 63 | print('3调用成功'+str(num1)+'次') 64 | if req.get(r'https://graph.microsoft.com/v1.0/users ',headers=headers).status_code == 200: 65 | num1+=1 66 | print('4调用成功'+str(num1)+'次') 67 | if req.get(r'https://graph.microsoft.com/v1.0/me/messages',headers=headers).status_code == 200: 68 | num1+=1 69 | print('5调用成功'+str(num1)+'次') 70 | if req.get(r'https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messageRules',headers=headers).status_code == 200: 71 | num1+=1 72 | print('6调用成功'+str(num1)+'次') 73 | if req.get(r'https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/messages/delta',headers=headers).status_code == 200: 74 | num1+=1 75 | print('7调用成功'+str(num1)+'次') 76 | if req.get(r'https://graph.microsoft.com/v1.0/me/drive/root/children',headers=headers).status_code == 200: 77 | num1+=1 78 | print('8调用成功'+str(num1)+'次') 79 | if req.get(r'https://api.powerbi.com/v1.0/myorg/apps',headers=headers).status_code == 200: 80 | num1+=1 81 | print('8调用成功'+str(num1)+'次') 82 | if req.get(r'https://graph.microsoft.com/v1.0/me/mailFolders',headers=headers).status_code == 200: 83 | num1+=1 84 | print('9调用成功'+str(num1)+'次') 85 | if req.get(r'https://graph.microsoft.com/v1.0/me/outlook/masterCategories',headers=headers).status_code == 200: 86 | num1+=1 87 | print('10调用成功'+str(num1)+'次') 88 | print('此次运行结束时间为 :', localtime) 89 | except: 90 | print("pass") 91 | pass 92 | for _ in range(8): 93 | main() 94 | msg='[AutoApiSecret]已成功调用{}次,结束时间为{}'.format(num1,fin) 95 | send(msg) 96 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AutoApiSecret-加密版 2 | 3 | **添加了通过电报机器人`Telegram Bot`反馈运行结果(邮件会在运行失败时由系统提醒,所以就不加入提醒避免垃圾邮件困扰,电报大家也只是偶尔看看就挺好的),由于`This Check was skipped`原因(单纯的强迫症,不想有多余的记录),取消了原来的点击`star`判断,换用手动点击`Run workflow`运行测试** 4 | 5 | AutoApi系列:AutoApi、AutoApiSecret、AutoApiSR、AutoApiS 6 | 7 | # 置顶 # 8 | ## 原教程网站证书问题,大家自行搜索引擎搜索关键词github actions e5即可 9 | 比如 10 | [利用Github Action刷Microsoft 365 E5开发者订阅API实现续订](https://51.ruyo.net/15646.html) 11 | 12 | 13 | 14 | 15 | 16 | [github actions自动调用api – 实现Microsoft 365 E5玄学订阅](https://www.daniao.org/9652.html) (也不知道都是谁写的,复制粘贴真简单) 17 | * 本项目是建立在[原教程](https://blog.432100.xyz/index.php/archives/50/)可以正确调用api的**假设**上的,核心是paran/黑幕大佬的py脚本。 18 | * 本项目只是提供一个自动、免费、无需额外设备的脚本运行方式,换句话说,**借用github的电脑/服务器来干活**。(因为原教程需要服务器/超长时间运转的设备,大部分人都不具备,本项目应运而生) 19 | * 本项目运行依赖**github action**服务,此功能github固有而**非私人提供**的服务器,且整个运行过程只涉及你与github。 20 | * 请务必先阅读理解[原教程](https://blog.432100.xyz/index.php/archives/50/)的**原理说明、设计理念**。 21 | * **不保证一定能续期!不保证一定能续期!不保证一定能续期**!或者说,**只是增大续订可能性**。过期前、后30天都可能续期!!! 22 | * 若理解并接受上述说明,请接着操作;**若否,请点击浏览器右上角 X 。** 23 | 24 | ### 项目说明 ### 25 | * 利用github action实现**定时自动调用api**,保持E5开发活跃。 26 | * **免费,不需要额外设备/服务器**,部署完不用管啦。 27 | * 加密版,隐藏应用id+机密,保护账号安全。 28 | 29 | ### 特别说明/Thanks ### 30 | * 原教程博主-黑幕(酷安id-Paran):https://blog.432100.xyz/index.php/archives/50/ 31 | * 普通版地址:https://github.com/wangziyingwen/AutoApi 32 | * 加密版地址(推荐):https://github.com/wangziyingwen/AutoApiSecret 33 | * 模仿人为应用开发版(包含升级步骤):https://github.com/wangzyingwen/AutoApiSR 34 | * 超级版地址: https://github.com/wangziyingwen/AutoApiS 35 | * **常见错误及解决办法/更新日志**:https://github.com/wangziyingwen/Autoapi-test 36 | * 网页获取refresh_token小工具(不建议使用):https://github.com/wangziyingwen/GetAutoApiToken 37 | * 视频教程:(我操作很慢,自行倍速/快进) 38 | * 在线/下载地址:https://kino-onemanager.herokuapp.com/Video/AutoApi%E6%95%99%E7%A8%8B.mp4?preview 39 | * B站:https://www.bilibili.com/video/av95688306/ 40 | 41 | 42 | 43 | ### 区别 ### 44 | [普通版(弃用)](https://github.com/wangziyingwen/AutoApi):密钥暴露,不在乎的话可以使用 45 | 46 | [加密版(推荐)](https://github.com/wangziyingwen/AutoApiSecret):应用id机密加密隐藏,提高安全性 47 | 48 | [模仿人为应用开发版(半弃用)](https://github.com/wangziyingwen/AutoApiSR):顾名思义,加密版的升级版。由于超级版兼容模拟版的功能,此版本处于一种尴尬位置。(当然也可以正常使用) 49 | 50 | [超级版(不建议)](https://github.com/wangziyingwen/AutoApiS):进一步升级版,增加自定义参数、模式。按目前情况,微软续订要求很低,暂时不需要使用此项目。 51 | 52 | **以上推荐/不建议等只是个人意见,请自行选择版本,可同时使用**。 53 | 54 | -------------------------------------------------------------- 55 | 56 | ## 步骤 ## 57 | 58 | >:blush: :blush: :blush: :blush: :blush: :blush: 59 | 60 | >请注意!请注意!请注意! 61 | 62 | >*** **有错误/问题请看**: [常见错误及解决办法/更新日志](https://github.com/wangziyingwen/Autoapi-test) 63 | 64 | >*** 原教程/博客好像也坏了,看[视频教程](https://www.bilibili.com/video/av95688306/)吧,懒得补充,ORZ. (或者去网上搜一下,有一堆转载,关键词:github action e5 续期) 65 | 66 | >*** 注册应用时用到的[azure管理页面](https://portal.azure.com/),或者直接到[仪表板](https://aad.portal.azure.com/),找到注册应用选项 67 | 68 | >***【重定向URI】填写的内容:http://localhost:53682/ 69 | 70 | >*** rclone下载,请自行百度谷歌,官网好像是[rclone.org](https://rclone.org) 71 | 72 | >:anguished: :anguished: :anguished: :anguished: :anguished: :anguished: 73 | 74 | * 第一步,先大致浏览[原教程](https://blog.432100.xyz/index.php/archives/50/),了解如何获取应用id、机密、refresh_token 3样东西,以方便接下来的操作。 75 | 76 | * 第二步,登陆/新建github账号,回到本项目页面,点击右上角fork本项目的代码到你自己的账号,然后你账号下会出现一个一模一样的项目,接下来的操作均在你的这个项目下进行。(看不到图片/图裂请科学上网) 77 | 78 | ![image](https://github.com/wangziyingwen/ImageHosting/blob/master/AutoApi/fork.png) 79 | 80 | * 根据[原教程](https://blog.432100.xyz/index.php/archives/50/)获取应用id、机密、refresh_token(自己复制保存,注意区分id机密,别弄混了) 81 | 82 | 然后在线编辑你项目里的1.txt,将整个refresh_token覆盖粘贴进去(里面是我的数据,先删掉或者覆盖掉)。(千万不要改1.py) 83 | 84 | > refresh_token位置如图下。复制refresh_token紧接着的双引号里的内容(红竖线框起来的),不要把双引号复制进去。复制进1.txt后,留意结尾不要留空格或者空行 85 | (其实浏览器地址栏地址也能看出,不过还是保险点好,你也可以借助插件完成) 86 | 87 | ![image](https://github.com/wangziyingwen/ImageHosting/blob/master/AutoApi/token地方.png) 88 | 89 | * 第三步,依次点击上栏Setting > Secrets > Add a new secret,新建两个(或四个)secret如图:CONFIG_ID、CONFIG_KEY(TELEBOT_TOKEN、CHAT_ID)。 90 | 91 | 内容分别如下: ( 把你的应用id改成你的应用id , 你的应用机密改成你的机密,单引号不要动 ) 92 | 93 | CONFIG_ID 94 | ```shell 95 | id=r'你的应用id' 96 | ``` 97 | CONFIG_KEY 98 | ```shell 99 | secret=r'你的应用机密' 100 | ``` 101 | 102 | 如果你想通过电报机器人提醒你运行结果,不时上去查看一下(虽然没必要,毕竟失败了会给你发邮件) 103 | 104 | 在Telegram中找[BotFather](https://t.me/BotFather)新建一个机器人得到它的token 105 | ```shell 106 | /newbot 107 | 108 | Alright, a new bot. How are we going to call it? Please choose a name for your bot. 109 | 110 | cctest 111 | 112 | Good. Now let's choose a username for your bot. It must end in `bot`. Like this, for example: TetrisBot or tetris_bot. 113 | 114 | cctest_bot 115 | 116 | Done! Congratulations on your new bot. You will find it at t.me/cctest_bot. You can now add a description, about section and profile picture for your bot, see /help for a list of commands. By the way, when you've finished creating your cool bot, ping our Bot Support if you want a better username for it. Just make sure the bot is fully operational before you do this. 117 | 118 | Use this token to access the HTTP API: 119 | 这就是你的机器人token啦 120 | Keep your token secure and store it safely, it can be used by anyone to control your bot. 121 | 122 | For a description of the Bot API, see this page: https://core.telegram.org/bots/api 123 | 124 | ``` 125 | TELEBOT_TOKEN 126 | ```shell 127 | 机器人的token 128 | ``` 129 | CHAT_ID 130 | ```shell 131 | 你的id 132 | ``` 133 | 134 | 接着是找机器人[userinfobot](https://t.me/userinfobot)获取你的id 135 | 直接start就会返回你的id 136 | 137 | ![image](https://github.com/wangziyingwen/ImageHosting/blob/master/AutoApi/机密.png) 138 | 139 | 最终格式应该是类似这样的: 140 | 141 | ![image](https://github.com/wangziyingwen/ImageHosting/blob/master/AutoApi/格式.png) 142 | 143 | * 第四步,进入你的个人设置页面(右上角头像 Settings,不是仓库里的 Settings),选择 Developer settings > Personal access tokens > Generate new token, 144 | 145 | ![image](https://github.com/wangziyingwen/ImageHosting/blob/master/AutoApi/Settings.png) 146 | ![image](https://github.com/wangziyingwen/ImageHosting/blob/master/AutoApi/token.png) 147 | 148 | 设置名字为GITHUB_TOKEN , 然后勾选 repo , admin:repo_hook , workflow 等选项,最后点击Generate token即可。 149 | 150 | ![image](https://github.com/wangziyingwen/ImageHosting/blob/master/AutoApi/repo.png) 151 | ![image](https://github.com/wangziyingwen/ImageHosting/blob/master/AutoApi/adminrepo.png) 152 | ![image](https://github.com/wangziyingwen/ImageHosting/blob/master/AutoApi/workflow.png) 153 | 154 | * 第五步,点击`Actions`,启用然后在All Workflows下点击`Auto Api Secret`就能看到`Run workflow`按钮,点击就可手动运行一次,然后刷新一次就能看到它在运行了,点击去查看详情运行情况(如果运行成功并且你配置了电报机器人通知你会收到`[AutoApiSecret]已成功调用30次,结束时间为...`,如果你的Actions中不显示workflow,可能是fork的原因,更改一下workflows的yml文件,加一个空格或空行之类的 155 | 156 | (必需点进去Test Api看下,api有没有调用到位,有没有出错。外面的Auto Api打勾只能说明运行是正常的,我们还需要确认10个api调用成功了,默认是执行三遍,也就是要看到调用成功30个,就像图里的一样。如果少了几个api,要么是注册应用的时候赋予api权限没弄好;要么是没登录激活onedrive,登录激活一下) 157 | 158 | ![image](https://github.com/wangziyingwen/ImageHosting/blob/master/AutoApi/日志.png) 159 | 160 | * 第六步,没出错的话,就搞定啦!!再看看下面的定时次数要不要修改,不打算改就忽略。 161 | 162 | **然后第二天回来确认下是否自动运行了(ation里是否多出来几个)**,是的话就不用管了,完结。 163 | 164 | 我设定的每小时自动运行一次,每次调用3轮(修改相关文件/手动运行也可以立马调用一次),你们自行斟酌修改(我也不知道保持活跃要调用多少次、多久): 165 | 166 | * 定时自动启动修改地方:(在.github/workflow/AutoApiSecret.yml文件里,自行百度cron定时任务格式,最短每5分钟一次,Github在线编辑鼠标悬停对应位置会以英文显示定时具体情况) 167 | 168 | ![image](https://github.com/wangziyingwen/ImageHosting/blob/master/AutoApi/定时.png) 169 | 170 | * 每次轮数修改地方:(在1.py最后面) 171 | 172 | ![image](https://github.com/wangziyingwen/ImageHosting/blob/master/AutoApi/次数.png) 173 | 174 | ------------------------------------------------------------ 175 | ### 题外话 ### 176 | > Api调用 177 | 你们可以自己去graph浏览器看一下,学着自己修改要调用什么api(最重要的是调用outlook、onedrive) 178 | https://developer.microsoft.com/zh-CN/graph/graph-explorer/preview 179 | 180 | ### GithubAction介绍 ### 181 | 提供的虚拟环境: 182 | 183 | · 2-core CPU 184 | · 7 GB RAM 内存 185 | · 14 GB SSD 硬盘空间 186 | 187 | 使用限制: 188 | * 每个仓库只能同时支持20个 workflow 并行。 189 | * 每小时可以调用1000次 GitHub API 。 190 | * 每个 job 最多可以执行6个小时。 191 | * 免费版的用户最大支持20个 job 并发执行,macOS 最大只支持5个。 192 | * 私有仓库每月累计使用时间为2000分钟,超过后$ 0.008/分钟,公共仓库则无限制。 193 | 194 | (我们这里用的公共仓库,按理,你们可以设定无限循环调用,然后6小时启动一次,保证24小时全天候调用) 195 | 196 | ### 最后 ### 197 | 教程很直白了,应该都会弄吧! 198 | 199 | 代码小白,多包涵!有问题/修改建议可以点击上方issues发布一下,或者PY给我: 200 | wz.lxh@outlook.com 201 | 202 | Q群:[657581700](https://jq.qq.com/?_wv=1027&k=5FQJbWmV) (项目相关讨论) 203 | 204 | tg群:[OneDrive E5](https://t.me/joinchat/OLlK9RsbBlmTYOJS_BU4Mg) (**非项目相关**讨论!**tg可能不会及时在线回答问题**,任何项目相关的问题或出错请进Q群/邮箱/issue) 205 | 206 | 207 | 208 | 最后的最后,再次感谢黑幕/paran大佬 209 | 210 | ————wangziyingwen/酷安id-卷腿毛菌 211 | --------------------------------------------------------------------------------