Skip to content

Commit

Permalink
增加微信互动
Browse files Browse the repository at this point in the history
  • Loading branch information
tencent-wechat authored Oct 31, 2021
1 parent 156b5ac commit 90021a8
Show file tree
Hide file tree
Showing 12 changed files with 457 additions and 87 deletions.
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
-->
### 清单

- [ ] 我已经仔细阅读过 README.md (https://github.com/TechXueXi/TechXueXi/blob/master/README.md)
- [ ] 我已经仔细阅读过 README.md ( https://github.com/TechXueXi/TechXueXi/blob/developing/README.md )
- [ ] 我已经查看/搜索过所有已有 issue,无论是open还是close的
- [ ] 我已经通过搜索引擎搜索 www.google.com www.baidu.com
- [ ] 我已经到提供的在线聊天室询问过 (聊天室说明:https://github.com/TechXueXi/TechXueXi/issues/14)
Expand Down Expand Up @@ -60,7 +60,7 @@
许多IT人员本终日埋头写代码,对我们这类软件确实有需求,
与其各人重复修改编写浪费生产力不如团队合作维护,因此我们希望长期维护此生态。
有意愿加入本组织者,请https://techxuexi.github.io/
有意愿加入本组织者,请 https://techxuexi.js.org/
我们不接受任何捐赠。远离非法牟利。
-->
72 changes: 60 additions & 12 deletions DOCKER.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ docker pull techxuexi/techxuexi-arm64v8:{tag}

### 版本说明

分为开发版:tag含有dev
分为开发版:tag 含有 dev

稳定版: tag为 latest
稳定版: tag 为 latest

# Docker 命令运行

Expand Down Expand Up @@ -270,15 +270,62 @@ services:
5.`/xuexi/user/settings.conf`中添加微信配置
```
addition {
Pushmode="2"
wechat{
appid = "第2步中获取的appid"
appsecret = "第2步中获取的appsecret"
openid = "第4步中获取的微信号"
}
}
```
_后续 **可能** 会增加`账号绑定`功能,允许多用户关注并绑定学 xi 账号,进行消息分发_

### 微信进阶设置

以下操作适用于有公网 IP,且需要跟微信互动的用户

1. 修改上面第五步中的配置文件追加`token`属性。token 用于验证请求,随意填写 8~16 位字符即可,也可以到[这里](https://www.toolzl.com/tools/createString.html)生成,_不要勾选字符_
```
addition {
wechat{
appid = "第2步中获取的appid"
appsecret = "第2步中获取的appsecret"
openid = "第4步中获取的微信号"
token = "随机字符串"
}
}
```
2. 在【接口配置信息】中填入`URL`和第 1 步的`token`![image](https://user-images.githubusercontent.com/91232777/139572541-42184b52-350c-4c49-b646-d763f16b715f.png)
_图中 url 仅为参考,请以文档为准_
URL:`http://你的域名或IP地址:端口号/wechat`
【端口号】是你从 docker 中映射出来的本地端口号,记得在路由器或防火墙中开启端口转发。访问链大概为:`微信--端口A-->路由--端口B-->docker--端口8088-->程序`
这里要填写的就是`端口A`
3. 点【提交】,如果提示`token验证失败`,要么端口不通,要么 docker 没启动监听,就不用往下看了。

#### 微信的使用

恭喜你完成所有配置,下面开始介绍功能的使用

配置成功之后,给公众号发送`/help`即可获得答复,如果没有,检查第一步中的 openid 是不是你的微信号。**只有主账号才能使用指令**

首先,给公众号发送 `/init` 初始化订阅号菜单,操作成功后等菜单出现,或者重新关注微信号,即可看到菜单,
![image](https://user-images.githubusercontent.com/91232777/139573137-141675e4-8939-4ce4-8cff-4432e7ff6fd8.png)

点击`我的-账号编码`获取微信号编码。

发送`/add` 登录学 xi 账号,登录完成后获得 `数字ID_昵称`登录成功的消息。

发送`/bind 微信编码 数字ID` 吧微信号和学 xi 账号绑定。如`/bind gw_djahdhfs 155555555`,不要有多余的空格。可以重复绑定,最后绑定的账号有效。

`开始学xi`即可开始今天的学习。

`我的-今日积分` 获取今天学习积分。

其他账号绑定

1.`用户A`先关注你的公众号。然后点击`账号编码`,并将编码给你。
2. 给你的公众号发送`/add`指令,让`用户A`登录。你可以获得 ta 的数字 ID
3. 给你的公众号发送`/bind 用户A的账号编码 用户A的数字ID`绑定成功后,`用户A`就可以自己学习和查分了。

`\unbind 微信编码` 解绑指定用户。

## Server 酱

Expand Down Expand Up @@ -325,11 +372,12 @@ services:

其他没有固定下来的用法,请加群了解。

# Web网页控制台
# Web 网页控制台

参考 telegram 需要打开端口映射

docker指令
docker 指令

```sh


Expand All @@ -343,9 +391,11 @@ docker run \
-d --name=techxuexi --shm-size="2g" \
-p 9980:80 \
techxuexi/techxuexi-amd64:latest

```
docker-config.yaml配置

docker-config.yaml 配置

```yaml
version: '3.5'
services:
Expand All @@ -356,20 +406,18 @@ services:
ports:
- 9980:80/tcp
volumes:
- ./user:/xuexi/user
- ./user:/xuexi/user
environment:
- Scheme=https://techxuexi.js.org/jump/techxuexi-20211023.html?
- ZhuanXiang=True
- Pushmode=6
- CRONTIME=30 9 * * *
build:
context: .
shm_size: '2gb'
shm_size: '2gb'
shm_size: '2gb'

```

**[交流群地址及说明](https://github.com/TechXueXi/TechXueXi/issues/14)**
## Docker 如果发给你一个学习强国链接,不是让你下载,是让你登录,复制链接到学习#国 app,发给某个人,比如自己,再点击链接
Expand Down
1 change: 1 addition & 0 deletions SourcePackages/config/default_template.conf
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ addition {
appid = ""
appsecret = ""
openid = ""
token = "" #互动操作需要,6~16位任意半角字符
}
}

Expand Down
28 changes: 19 additions & 9 deletions SourcePackages/pandalearning.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def start_learn(uid, name):
else:
msg = name+" 登录信息失效,请重新扫码"
print(msg)
gl.pushprint(msg)
gl.pushprint(msg, chat_id=uid)
driver_login = Mydriver()
cookies = driver_login.login()
driver_login.quit()
Expand All @@ -85,7 +85,7 @@ def start_learn(uid, name):
video_index = 1 # user.get_video_index(uid)

total, scores = show_score(cookies)
gl.pushprint(output)
gl.pushprint(output, chat_id=uid)
if TechXueXi_mode in ["1", "3"]:

article_thread = threads.MyThread(
Expand Down Expand Up @@ -114,8 +114,8 @@ def start_learn(uid, name):

seconds_used = int(time.time() - start_time)
gl.pushprint(name+" 总计用时 " + str(math.floor(seconds_used / 60)) +
" 分 " + str(seconds_used % 60) + " 秒")
show_scorePush(cookies)
" 分 " + str(seconds_used % 60) + " 秒", chat_id=uid)
show_scorePush(cookies, chat_id=uid)
try:
user.shutdown(stime)
except Exception as e:
Expand All @@ -132,14 +132,24 @@ def start(nick_name=None):
user_list.append(["", "新用户"])
for i in range(len(user_list)):
try:
if nick_name == None or nick_name == user_list[i][1]:
if nick_name == None or nick_name == user_list[i][1] or nick_name == user_list[i][0]:
_learn = threads.MyThread(
user_list[i][0]+"开始学xi", start_learn, user_list[i][0], user_list[i][1], lock=Single)
_learn.start()
except:
gl.pushprint("学习页面崩溃,学习终止")


def get_my_score(uid):
get_argv()
user.refresh_all_cookies()
cookies = user.get_cookie(uid)
if not cookies:
return False
show_scorePush(cookies, chat_id=uid)
return True


def get_user_list():
get_argv()
dic = user.refresh_all_cookies(display_score=True)
Expand All @@ -160,20 +170,20 @@ def get_all_user_name():
return names


def add_user():
def add_user(chat_id=None):
get_argv()
gl.pushprint("请扫码登录:")
gl.pushprint("请扫码登录:", chat_id=chat_id)
driver_login = Mydriver()
cookies = driver_login.login()
driver_login.quit()
if not cookies:
gl.pushprint("登录超时。")
gl.pushprint("登录超时。", chat_id=chat_id)
return
user.save_cookies(cookies)
uid = user.get_userId(cookies)
user_fullname = user.get_fullname(uid)
user.update_last_user(uid)
gl.pushprint(user_fullname+"登录成功")
gl.pushprint(user_fullname+"登录成功", chat_id=chat_id)


if __name__ == '__main__':
Expand Down
11 changes: 7 additions & 4 deletions SourcePackages/pdlearn/globalvar.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def init_global():
nohead = True
else:
nohead = cfg_get("addition.Nohead", False)

if os.getenv('islooplogin') == "True":
islooplogin = True

Expand All @@ -52,7 +52,7 @@ def init_global():

if os.getenv("Scheme") != None:
scheme = os.getenv("Scheme")
#elif pushmode in ["5"]: # telegram 默认开启我们提供的
# elif pushmode in ["5"]: # telegram 默认开启我们提供的
# scheme = 'https://techxuexi.js.org/jump/techxuexi-20211023.html?'

if os.getenv('AccessToken'):
Expand Down Expand Up @@ -82,7 +82,8 @@ def init_global():
wechat = WechatHandler()
is_init = True

def pushprint(text):

def pushprint(text, chat_id=None):
"""
推送或者显示
"""
Expand All @@ -97,7 +98,9 @@ def pushprint(text):
push = DingDingHandler(accesstoken, secret)
push.ddtextsend(text)
elif pushmode == "2":
wechat.send_text(text)
if chat_id:
chat_id = wechat.get_opendid_by_uid(chat_id)
wechat.send_text(text, uid=chat_id)
elif pushmode == "3":
push = FangtangHandler(accesstoken)
push.fttext(text)
Expand Down
Loading

0 comments on commit 90021a8

Please sign in to comment.