# PushService **Repository Path**: Hemingway2003/pushservice ## Basic Information - **Project Name**: PushService - **Description**: Push service by wechart work version - **Primary Language**: Python - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 4 - **Forks**: 3 - **Created**: 2022-01-29 - **Last Updated**: 2025-05-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # PushService This is a sample code to push message by `WeCom`. #### Shell version: run ``` bash wecom.sh "Hello" ``` But you must install `jq` on your machine first, and set the right config file. #### Shell版本 运行 ``` bash wecom.sh "Hello" ``` 但是你必须现在你的机器上安装`jq`并正确设置好配置文件。 ------------------------------------------------------------- #### How to use You must install pip package by run: ``` python -m pip install -r requirements.txt ``` - In some Linux version you must use `python3` instead of `python` just like: ``` python3 -m pip install -r requirements.txt ``` And in your `py` file, import `wecom.py` just like: ``` from wecom import wecom ``` Then you will find an error in the first running, but don't worry, you need a config file, the program will auto create a sample config, the config file is like: ``` { "corpid": "wwabcddzxdkrsdv", "corpsecret": "vQT_03RDVA3uE6JDASDASDAiXUvccqV8mDgLdLI", "AgentId": 1000002, "dataRecord": 1 } ``` - `corpid`: You will find it at https://work.weixin.qq.com/wework_admin/frame#profile - `corpsecret`and `AgentId`: You will find them at https://work.weixin.qq.com/wework_admin/frame#apps - `dataRecord`: 0 means the program will not record the `accessToken` on your disk, and will record the data while it is not zero(This is more helpful while you are debugging your main program, avoiding to ask server for `accessToken` every times). After all has done, just add this code in your main program: ``` we = WeCom() we.senMsg("This is a test msg") ``` You will receive an message on your phone or PC and it shows: `This is a test msg`. - `we.senMsg()` will also return `False` and `True` ------------------------------------------ 这是一个使用`企业微信`接口来推送消息的实例程序。 #### 如何使用 必须使用如下命令来安装pip包: ``` python -m pip install -r requirements.txt ``` - 在某些Linux上你必须使用`python3`来替代`python`,就像这样: ``` python3 -m pip install -r requirements.txt ``` 并且在你的`py`文件中,导入`wecom.py`: ``` from wecom import wecom ``` 然后在你的首次运行中你会发现一个错误,别担心,你仅仅需要一个配置文件,程序会自动创建一个配置文件,以下是配置文件内容: ``` { "corpid": "wwabcddzxdkrsdv", "corpsecret": "vQT_03RDVA3uE6JDASDASDAiXUvccqV8mDgLdLI", "AgentId": 1000002, "dataRecord": 1 } ``` - `corpid`: 你将在这个网址找到 https://work.weixin.qq.com/wework_admin/frame#profile - `corpsecret`and `AgentId`: 你将在这个网址找到他们 https://work.weixin.qq.com/wework_admin/frame#apps - `dataRecord`: 0 意味着程序将不会在你的硬盘中记录 `accessToken` ,在非0时会记录(这在调试过程中非常有用, 避免了每次都要向服务器获取`accessToken`). 在所有都做完了之后,添加如下代码进你的主程序: ``` we = WeCom() we.senMsg("This is a test msg") ``` 你将在你的电脑或手机中收到一条信息: `This is a test msg`. - `we.senMsg()` 也会返回 `False` 和 `True`