https://github.com/zxj17815/wechatwork-tool
Django module for quick access and development of WeChatWork
https://github.com/zxj17815/wechatwork-tool
django wechatwork
Last synced: 23 days ago
JSON representation
Django module for quick access and development of WeChatWork
- Host: GitHub
- URL: https://github.com/zxj17815/wechatwork-tool
- Owner: zxj17815
- License: mit
- Created: 2020-07-27T07:06:45.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-10-27T05:25:30.000Z (over 5 years ago)
- Last Synced: 2025-06-26T07:43:45.289Z (12 months ago)
- Topics: django, wechatwork
- Language: Python
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
#### WeChatWorkTool
Wechatworktool is a Django app,which is used to facilitate the internal application development of enterprise wechat and call enterprise wechat interface faster
#### Quick start
Install `pip install django-wechatwork-tool`
1. Add "WeChatWorkTool" to your INSTALLED_APPS setting like this:
```python
# setting.py
INSTALLED_APPS = [
...
'WeChatWorkTool',
...
]
```
2. Run python manage.py migrate to create the AccessToken models.
3. Start the development server and visit http://127.0.0.1:8000/admin/ to create a AccessToken (need WeChatWork's corpid and an app secret of WeChatWork)
4. Call where needed:
```python
...
from WeChatWorkTool import tool
...
app=tool.CorpApp('sap')
print(app.app_info())
# Details of WeChatWork internal applications
print(app.get_user('FS0397'))
# Get employee details through employee ID
```
5. Application verification and callback example
```python
import json
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from WeChatWorkTool import tool
@csrf_exempt
def call_back(request):
"""WeChatWork messqge callback Simple Example"""
if request.method == 'GET':
# Authentication url
data = request.GET.dict()
return HttpResponse(tool.call_back_verify(data, 'sap'))
if request.method == 'POST':
url_data = request.GET.dict()
cb = tool.CorpApp('sap').call_back_data(url_data, request.body)
return HttpResponse(json.dumps(cb), content_type="application/json")
```
#### WeChatWorkTool
CorpApp: WeChatWorks custom application
```python
def app_info(self):
"""
get this app info
:return: App Info
"""
def get_userid_by_code(self, code):
"""get userid by code,It's just for webpage authorization link
:param code: in webpage authorization link
:return:UserId
"""
def get_user(self, userid):
"""get user info
:param userid: WeChatWork user's id
:return: a dict that user info
"""
def get_user_tag_list(self):
"""get user tag list
:return: user tag list
"""
def get_department_user_simplelist(self, department_id, fetch_child=False):
"""get user simplelist by department id
:param department_id:
:param fetch_child:
:return
For success example:
{
"errcode" : 0,
"errmsg" : "ok",
"invaliduser" :"",
"invalidparty" : "",
"invalidtag": ""
}
For error example:
{
"errcode" : 0,
"errmsg" : "ok",
"invaliduser" : [userid1,userid2],
"invalidparty" : [partyid1,partyid2],
"invalidtag": [tagid1,tagid2]
}
"""
def get_department_user_list(self, department_id, fetch_child=False):
"""get user list by department id
:param department_id:
:param fetch_child:
:return:
"""
def get_department(self, id):
"""get department info list
:param id: WeChatWork department's id
:return:
"""
def SendMsg(self, msgobj, touser: list = [], toparty: list = [], totag: list = [],
safe=0, enable_id_trans=0,
enable_duplicate_check=0,
duplicate_check_interval=1800):
"""
:param touser:
:param toparty:
:param totag:
:param msgobj:
:param safe:
:param enable_id_trans:
:param enable_duplicate_check:
:param duplicate_check_interval:
:return:
"""
```
#### Massage object
The message type corresponds to the message type of WeChatWork
1. TextMessageObject
2. MediaMessageObject
3. TextCardMessageObject
4. NewsMessageObject
5. MarkDownMessageObject
6. TaskCardBtnTemplate
7. TaskCardMessageObject