py-wecom-toolkit 4.0.0__tar.gz → 4.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. py_wecom_toolkit-4.0.2/LICENSE +21 -0
  2. {py_wecom_toolkit-4.0.0 → py_wecom_toolkit-4.0.2}/PKG-INFO +78 -73
  3. {py_wecom_toolkit-4.0.0 → py_wecom_toolkit-4.0.2}/README.md +74 -72
  4. {py_wecom_toolkit-4.0.0 → py_wecom_toolkit-4.0.2}/pyproject.toml +3 -1
  5. {py_wecom_toolkit-4.0.0 → py_wecom_toolkit-4.0.2}/.gitignore +0 -0
  6. {py_wecom_toolkit-4.0.0 → py_wecom_toolkit-4.0.2}/py_wecom_toolkit/__init__.py +0 -0
  7. {py_wecom_toolkit-4.0.0 → py_wecom_toolkit-4.0.2}/py_wecom_toolkit/py.typed +0 -0
  8. {py_wecom_toolkit-4.0.0 → py_wecom_toolkit-4.0.2}/py_wecom_toolkit/server/__init__.py +0 -0
  9. {py_wecom_toolkit-4.0.0 → py_wecom_toolkit-4.0.2}/py_wecom_toolkit/server/cache.py +0 -0
  10. {py_wecom_toolkit-4.0.0 → py_wecom_toolkit-4.0.2}/py_wecom_toolkit/server/client.py +0 -0
  11. {py_wecom_toolkit-4.0.0 → py_wecom_toolkit-4.0.2}/py_wecom_toolkit/server/exception.py +0 -0
  12. {py_wecom_toolkit-4.0.0 → py_wecom_toolkit-4.0.2}/py_wecom_toolkit/server/material/__init__.py +0 -0
  13. {py_wecom_toolkit-4.0.0 → py_wecom_toolkit-4.0.2}/py_wecom_toolkit/server/material/client.py +0 -0
  14. {py_wecom_toolkit-4.0.0 → py_wecom_toolkit-4.0.2}/py_wecom_toolkit/server/material/msgtype.py +0 -0
  15. {py_wecom_toolkit-4.0.0 → py_wecom_toolkit-4.0.2}/py_wecom_toolkit/server/material/response.py +0 -0
  16. {py_wecom_toolkit-4.0.0 → py_wecom_toolkit-4.0.2}/py_wecom_toolkit/server/message/__init__.py +0 -0
  17. {py_wecom_toolkit-4.0.0 → py_wecom_toolkit-4.0.2}/py_wecom_toolkit/server/message/client.py +0 -0
  18. {py_wecom_toolkit-4.0.0 → py_wecom_toolkit-4.0.2}/py_wecom_toolkit/server/message/msgtype.py +0 -0
  19. {py_wecom_toolkit-4.0.0 → py_wecom_toolkit-4.0.2}/py_wecom_toolkit/server/response.py +0 -0
  20. {py_wecom_toolkit-4.0.0 → py_wecom_toolkit-4.0.2}/py_wecom_toolkit/webhook/__init__.py +0 -0
  21. {py_wecom_toolkit-4.0.0 → py_wecom_toolkit-4.0.2}/py_wecom_toolkit/webhook/client.py +0 -0
  22. {py_wecom_toolkit-4.0.0 → py_wecom_toolkit-4.0.2}/py_wecom_toolkit/webhook/exception.py +0 -0
  23. {py_wecom_toolkit-4.0.0 → py_wecom_toolkit-4.0.2}/py_wecom_toolkit/webhook/msgtype.py +0 -0
  24. {py_wecom_toolkit-4.0.0 → py_wecom_toolkit-4.0.2}/py_wecom_toolkit/webhook/response.py +0 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 郭磊
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,9 +1,12 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: py_wecom_toolkit
3
- Version: 4.0.0
3
+ Version: 4.0.2
4
4
  Summary: Enterprise WeChat (WeCom) API toolkit for Python / 企业微信(WeCom)API 工具包
5
+ Project-URL: homepage, https://gitee.com/guolei19850528/py_wecom_toolkit
6
+ Project-URL: repository, https://gitee.com/guolei19850528/py_wecom_toolkit
5
7
  Author-email: 郭磊 <174000902@qq.com>
6
8
  License: MIT
9
+ License-File: LICENSE
7
10
  Keywords: api,enterprise-wechat,toolkit,wecom,weixin-work,企业微信,企业微信API,企业微信工具
8
11
  Classifier: Development Status :: 4 - Beta
9
12
  Classifier: Intended Audience :: Developers
@@ -173,6 +176,8 @@ uv sync --all-groups
173
176
 
174
177
  ## 📖 使用说明
175
178
 
179
+ > ⚠️ 注意:以下示例中的 `CORP_ID`、`CORP_SECRET`、`AGENT_ID`、`TOUSER`、`WEBHOOK_KEY` 均为占位符,请替换为您的实际值后再使用。
180
+
176
181
  ### 1. server 模块 - 企业微信服务端 API
177
182
 
178
183
  server 模块提供企业微信服务端 API 的访问功能,包括 access_token 获取、应用消息发送、素材管理等。
@@ -188,7 +193,7 @@ from py_wecom_toolkit.server.client import Client
188
193
  from py_wecom_toolkit.server.response import AccessTokenResponse
189
194
 
190
195
  # 初始化客户端
191
- with Client(corpid="your_corp_id", corpsecret="your_corp_secret") as client:
196
+ with Client(corpid=CORP_ID, corpsecret=CORP_SECRET) as client:
192
197
  resp: AccessTokenResponse = client.get_token()
193
198
  if resp.ok:
194
199
  print(f"access_token: {resp.access_token}")
@@ -205,7 +210,7 @@ from py_wecom_toolkit.server.client import AsyncClient
205
210
  from py_wecom_toolkit.server.response import AccessTokenResponse
206
211
 
207
212
  async def main():
208
- async with AsyncClient(corpid="your_corp_id", corpsecret="your_corp_secret") as client:
213
+ async with AsyncClient(corpid=CORP_ID, corpsecret=CORP_SECRET) as client:
209
214
  resp: AccessTokenResponse = await client.get_token()
210
215
  if resp.ok:
211
216
  print(f"access_token: {resp.access_token}")
@@ -228,10 +233,10 @@ asyncio.run(main())
228
233
  from py_wecom_toolkit.server.message.client import Client as MessageClient
229
234
  from py_wecom_toolkit.server.message.msgtype import TextMessage
230
235
 
231
- with MessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
236
+ with MessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
232
237
  msg = TextMessage(
233
- touser="Guolei",
234
- agentid=1000035,
238
+ touser=TOUSER,
239
+ agentid=AGENT_ID,
235
240
  text={"content": "Hello, WeCom!"}
236
241
  )
237
242
  resp = client.send(msg)
@@ -249,10 +254,10 @@ from py_wecom_toolkit.server.message.client import AsyncClient as MessageClient
249
254
  from py_wecom_toolkit.server.message.msgtype import TextMessage
250
255
 
251
256
  async def main():
252
- async with AsyncMessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
257
+ async with AsyncMessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
253
258
  msg = TextMessage(
254
- touser="Guolei",
255
- agentid=1000035,
259
+ touser=TOUSER,
260
+ agentid=AGENT_ID,
256
261
  text={"content": "Hello, WeCom!"}
257
262
  )
258
263
  resp = await client.send(msg)
@@ -272,10 +277,10 @@ asyncio.run(main())
272
277
  from py_wecom_toolkit.server.message.client import Client as MessageClient
273
278
  from py_wecom_toolkit.server.message.msgtype import MarkdownMessage
274
279
 
275
- with MessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
280
+ with MessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
276
281
  msg = MarkdownMessage(
277
- touser="Guolei",
278
- agentid=1000035,
282
+ touser=TOUSER,
283
+ agentid=AGENT_ID,
279
284
  markdown={"content": "**加粗**\n*斜体*\n[链接](https://example.com)\n> 引用内容"}
280
285
  )
281
286
  resp = client.send(msg)
@@ -293,10 +298,10 @@ from py_wecom_toolkit.server.message.client import AsyncClient as MessageClient
293
298
  from py_wecom_toolkit.server.message.msgtype import MarkdownMessage
294
299
 
295
300
  async def main():
296
- async with AsyncMessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
301
+ async with AsyncMessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
297
302
  msg = MarkdownMessage(
298
- touser="Guolei",
299
- agentid=1000035,
303
+ touser=TOUSER,
304
+ agentid=AGENT_ID,
300
305
  markdown={"content": "**加粗**\n*斜体*\n[链接](https://example.com)\n> 引用内容"}
301
306
  )
302
307
  resp = await client.send(msg)
@@ -316,10 +321,10 @@ asyncio.run(main())
316
321
  from py_wecom_toolkit.server.message.client import Client as MessageClient
317
322
  from py_wecom_toolkit.server.message.msgtype import MarkdownV2Message
318
323
 
319
- with MessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
324
+ with MessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
320
325
  msg = MarkdownV2Message(
321
- touser="Guolei",
322
- agentid=1000035,
326
+ touser=TOUSER,
327
+ agentid=AGENT_ID,
323
328
  markdown_v2={"content": "# 标题\n- 列表项1\n- 列表项2\n| 姓名 | 年龄 |\n| --- | --- |\n| 张三 | 25 |"}
324
329
  )
325
330
  resp = client.send(msg)
@@ -337,10 +342,10 @@ from py_wecom_toolkit.server.message.client import AsyncClient as MessageClient
337
342
  from py_wecom_toolkit.server.message.msgtype import MarkdownV2Message
338
343
 
339
344
  async def main():
340
- async with AsyncMessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
345
+ async with AsyncMessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
341
346
  msg = MarkdownV2Message(
342
- touser="Guolei",
343
- agentid=1000035,
347
+ touser=TOUSER,
348
+ agentid=AGENT_ID,
344
349
  markdown_v2={"content": "# 标题\n- 列表项1\n- 列表项2\n| 姓名 | 年龄 |\n| --- | --- |\n| 张三 | 25 |"}
345
350
  )
346
351
  resp = await client.send(msg)
@@ -360,10 +365,10 @@ asyncio.run(main())
360
365
  from py_wecom_toolkit.server.message.client import Client as MessageClient
361
366
  from py_wecom_toolkit.server.message.msgtype import ImageMessage
362
367
 
363
- with MessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
368
+ with MessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
364
369
  msg = ImageMessage(
365
- touser="Guolei",
366
- agentid=1000035,
370
+ touser=TOUSER,
371
+ agentid=AGENT_ID,
367
372
  image={"base64": "BASE64_ENCODED_IMAGE_DATA", "md5": "MD5_OF_BASE64_DATA"}
368
373
  )
369
374
  resp = client.send(msg)
@@ -381,10 +386,10 @@ from py_wecom_toolkit.server.message.client import AsyncClient as MessageClient
381
386
  from py_wecom_toolkit.server.message.msgtype import ImageMessage
382
387
 
383
388
  async def main():
384
- async with AsyncMessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
389
+ async with AsyncMessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
385
390
  msg = ImageMessage(
386
- touser="Guolei",
387
- agentid=1000035,
391
+ touser=TOUSER,
392
+ agentid=AGENT_ID,
388
393
  image={"base64": "BASE64_ENCODED_IMAGE_DATA", "md5": "MD5_OF_BASE64_DATA"}
389
394
  )
390
395
  resp = await client.send(msg)
@@ -404,10 +409,10 @@ asyncio.run(main())
404
409
  from py_wecom_toolkit.server.message.client import Client as MessageClient
405
410
  from py_wecom_toolkit.server.message.msgtype import NewsMessage
406
411
 
407
- with MessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
412
+ with MessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
408
413
  msg = NewsMessage(
409
- touser="Guolei",
410
- agentid=1000035,
414
+ touser=TOUSER,
415
+ agentid=AGENT_ID,
411
416
  news={
412
417
  "articles": [
413
418
  {
@@ -434,10 +439,10 @@ from py_wecom_toolkit.server.message.client import AsyncClient as MessageClient
434
439
  from py_wecom_toolkit.server.message.msgtype import NewsMessage
435
440
 
436
441
  async def main():
437
- async with AsyncMessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
442
+ async with AsyncMessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
438
443
  msg = NewsMessage(
439
- touser="Guolei",
440
- agentid=1000035,
444
+ touser=TOUSER,
445
+ agentid=AGENT_ID,
441
446
  news={
442
447
  "articles": [
443
448
  {
@@ -466,10 +471,10 @@ asyncio.run(main())
466
471
  from py_wecom_toolkit.server.message.client import Client as MessageClient
467
472
  from py_wecom_toolkit.server.message.msgtype import FileMessage
468
473
 
469
- with MessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
474
+ with MessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
470
475
  msg = FileMessage(
471
- touser="Guolei",
472
- agentid=1000035,
476
+ touser=TOUSER,
477
+ agentid=AGENT_ID,
473
478
  file={"media_id": "MEDIA_ID_123"} # 需要先上传文件获取 media_id
474
479
  )
475
480
  resp = client.send(msg)
@@ -487,10 +492,10 @@ from py_wecom_toolkit.server.message.client import AsyncClient as MessageClient
487
492
  from py_wecom_toolkit.server.message.msgtype import FileMessage
488
493
 
489
494
  async def main():
490
- async with AsyncMessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
495
+ async with AsyncMessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
491
496
  msg = FileMessage(
492
- touser="Guolei",
493
- agentid=1000035,
497
+ touser=TOUSER,
498
+ agentid=AGENT_ID,
494
499
  file={"media_id": "MEDIA_ID_123"} # 需要先上传文件获取 media_id
495
500
  )
496
501
  resp = await client.send(msg)
@@ -510,10 +515,10 @@ asyncio.run(main())
510
515
  from py_wecom_toolkit.server.message.client import Client as MessageClient
511
516
  from py_wecom_toolkit.server.message.msgtype import VoiceMessage
512
517
 
513
- with MessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
518
+ with MessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
514
519
  msg = VoiceMessage(
515
- touser="Guolei",
516
- agentid=1000035,
520
+ touser=TOUSER,
521
+ agentid=AGENT_ID,
517
522
  voice={"media_id": "MEDIA_ID_VOICE"} # 需要先上传语音文件获取 media_id
518
523
  )
519
524
  resp = client.send(msg)
@@ -531,10 +536,10 @@ from py_wecom_toolkit.server.message.client import AsyncClient as MessageClient
531
536
  from py_wecom_toolkit.server.message.msgtype import VoiceMessage
532
537
 
533
538
  async def main():
534
- async with AsyncMessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
539
+ async with AsyncMessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
535
540
  msg = VoiceMessage(
536
- touser="Guolei",
537
- agentid=1000035,
541
+ touser=TOUSER,
542
+ agentid=AGENT_ID,
538
543
  voice={"media_id": "MEDIA_ID_VOICE"} # 需要先上传语音文件获取 media_id
539
544
  )
540
545
  resp = await client.send(msg)
@@ -554,10 +559,10 @@ asyncio.run(main())
554
559
  from py_wecom_toolkit.server.message.client import Client as MessageClient
555
560
  from py_wecom_toolkit.server.message.msgtype import TemplateCardMessage
556
561
 
557
- with MessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
562
+ with MessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
558
563
  msg = TemplateCardMessage(
559
- touser="Guolei",
560
- agentid=1000035,
564
+ touser=TOUSER,
565
+ agentid=AGENT_ID,
561
566
  template_card={
562
567
  "card_type": "text_notice",
563
568
  "main_title": {
@@ -589,10 +594,10 @@ from py_wecom_toolkit.server.message.client import AsyncClient as MessageClient
589
594
  from py_wecom_toolkit.server.message.msgtype import TemplateCardMessage
590
595
 
591
596
  async def main():
592
- async with AsyncMessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
597
+ async with AsyncMessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
593
598
  msg = TemplateCardMessage(
594
- touser="Guolei",
595
- agentid=1000035,
599
+ touser=TOUSER,
600
+ agentid=AGENT_ID,
596
601
  template_card={
597
602
  "card_type": "text_notice",
598
603
  "main_title": {
@@ -630,7 +635,7 @@ asyncio.run(main())
630
635
  from py_wecom_toolkit.server.material.client import Client as MaterialClient
631
636
  from py_wecom_toolkit.server.material.msgtype import MaterialType
632
637
 
633
- with MaterialClient(corpid="your_corp_id", corpsecret="your_corp_secret") as client:
638
+ with MaterialClient(corpid=CORP_ID, corpsecret=CORP_SECRET) as client:
634
639
  resp = client.upload(
635
640
  media_type=MaterialType.FILE, # 文件类型:file
636
641
  file="path/to/your/file.txt", # 本地文件路径
@@ -650,7 +655,7 @@ from py_wecom_toolkit.server.material.client import AsyncClient as MaterialClien
650
655
  from py_wecom_toolkit.server.material.msgtype import MaterialType
651
656
 
652
657
  async def main():
653
- async with AsyncMaterialClient(corpid="your_corp_id", corpsecret="your_corp_secret") as client:
658
+ async with AsyncMaterialClient(corpid=CORP_ID, corpsecret=CORP_SECRET) as client:
654
659
  resp = await client.upload(
655
660
  media_type=MaterialType.FILE, # 文件类型:file
656
661
  file="path/to/your/file.txt", # 本地文件路径
@@ -671,7 +676,7 @@ asyncio.run(main())
671
676
  ```python
672
677
  from py_wecom_toolkit.server.material.client import Client as MaterialClient
673
678
 
674
- with MaterialClient(corpid="your_corp_id", corpsecret="your_corp_secret") as client:
679
+ with MaterialClient(corpid=CORP_ID, corpsecret=CORP_SECRET) as client:
675
680
  resp = client.upload_img(
676
681
  file="path/to/your/image.jpg",
677
682
  filename="image.jpg"
@@ -689,7 +694,7 @@ import asyncio
689
694
  from py_wecom_toolkit.server.material.client import AsyncClient as MaterialClient
690
695
 
691
696
  async def main():
692
- async with AsyncMaterialClient(corpid="your_corp_id", corpsecret="your_corp_secret") as client:
697
+ async with AsyncMaterialClient(corpid=CORP_ID, corpsecret=CORP_SECRET) as client:
693
698
  resp = await client.upload_img(
694
699
  file="path/to/your/image.jpg",
695
700
  filename="image.jpg"
@@ -709,7 +714,7 @@ asyncio.run(main())
709
714
  ```python
710
715
  from py_wecom_toolkit.server.material.client import Client as MaterialClient
711
716
 
712
- with MaterialClient(corpid="your_corp_id", corpsecret="your_corp_secret") as client:
717
+ with MaterialClient(corpid=CORP_ID, corpsecret=CORP_SECRET) as client:
713
718
  data = client.download(media_id="MEDIA_ID_123")
714
719
 
715
720
  if isinstance(data, bytes):
@@ -727,7 +732,7 @@ import asyncio
727
732
  from py_wecom_toolkit.server.material.client import AsyncClient as MaterialClient
728
733
 
729
734
  async def main():
730
- async with AsyncMaterialClient(corpid="your_corp_id", corpsecret="your_corp_secret") as client:
735
+ async with AsyncMaterialClient(corpid=CORP_ID, corpsecret=CORP_SECRET) as client:
731
736
  data = await client.download(media_id="MEDIA_ID_123")
732
737
 
733
738
  if isinstance(data, bytes):
@@ -751,7 +756,7 @@ Webhook 消息推送(原群机器人)不需要 `corpid` 和 `corpsecret`,
751
756
  ```python
752
757
  from py_wecom_toolkit.webhook.client import Client as WebhookClient
753
758
 
754
- with WebhookClient(key="your_webhook_key") as client:
759
+ with WebhookClient(key=WEBHOOK_KEY) as client:
755
760
  resp = client.send_text("Hello, WeCom Webhook!")
756
761
  if resp.ok:
757
762
  print("文本消息发送成功")
@@ -766,7 +771,7 @@ import asyncio
766
771
  from py_wecom_toolkit.webhook.client import AsyncClient as WebhookClient
767
772
 
768
773
  async def main():
769
- async with WebhookClient(key="your_webhook_key") as client:
774
+ async with WebhookClient(key=WEBHOOK_KEY) as client:
770
775
  resp = await client.send_text("Hello, WeCom Webhook!")
771
776
  if resp.ok:
772
777
  print("文本消息发送成功")
@@ -783,7 +788,7 @@ asyncio.run(main())
783
788
  ```python
784
789
  from py_wecom_toolkit.webhook.client import Client as WebhookClient
785
790
 
786
- with WebhookClient(key="your_webhook_key") as client:
791
+ with WebhookClient(key=WEBHOOK_KEY) as client:
787
792
  resp = client.send_markdown("**加粗文本**\n[链接](https://example.com)\n> 引用内容")
788
793
  if resp.ok:
789
794
  print("Markdown 消息发送成功")
@@ -798,7 +803,7 @@ import asyncio
798
803
  from py_wecom_toolkit.webhook.client import AsyncClient as WebhookClient
799
804
 
800
805
  async def main():
801
- async with WebhookClient(key="your_webhook_key") as client:
806
+ async with WebhookClient(key=WEBHOOK_KEY) as client:
802
807
  resp = await client.send_markdown("**加粗文本**\n[链接](https://example.com)\n> 引用内容")
803
808
  if resp.ok:
804
809
  print("Markdown 消息发送成功")
@@ -815,7 +820,7 @@ asyncio.run(main())
815
820
  ```python
816
821
  from py_wecom_toolkit.webhook.client import Client as WebhookClient
817
822
 
818
- with WebhookClient(key="your_webhook_key") as client:
823
+ with WebhookClient(key=WEBHOOK_KEY) as client:
819
824
  resp = client.send_markdown_v2("# 标题\n- 列表项1\n- 列表项2")
820
825
  if resp.ok:
821
826
  print("Markdown V2 消息发送成功")
@@ -830,7 +835,7 @@ import asyncio
830
835
  from py_wecom_toolkit.webhook.client import AsyncClient as WebhookClient
831
836
 
832
837
  async def main():
833
- async with WebhookClient(key="your_webhook_key") as client:
838
+ async with WebhookClient(key=WEBHOOK_KEY) as client:
834
839
  resp = await client.send_markdown_v2("# 标题\n- 列表项1\n- 列表项2")
835
840
  if resp.ok:
836
841
  print("Markdown V2 消息发送成功")
@@ -847,7 +852,7 @@ asyncio.run(main())
847
852
  ```python
848
853
  from py_wecom_toolkit.webhook.client import Client as WebhookClient
849
854
 
850
- with WebhookClient(key="your_webhook_key") as client:
855
+ with WebhookClient(key=WEBHOOK_KEY) as client:
851
856
  resp = client.send_image(base64="BASE64_DATA", md5="MD5_HASH")
852
857
  if resp.ok:
853
858
  print("图片消息发送成功")
@@ -862,7 +867,7 @@ import asyncio
862
867
  from py_wecom_toolkit.webhook.client import AsyncClient as WebhookClient
863
868
 
864
869
  async def main():
865
- async with WebhookClient(key="your_webhook_key") as client:
870
+ async with WebhookClient(key=WEBHOOK_KEY) as client:
866
871
  resp = await client.send_image(base64="BASE64_DATA", md5="MD5_HASH")
867
872
  if resp.ok:
868
873
  print("图片消息发送成功")
@@ -879,7 +884,7 @@ asyncio.run(main())
879
884
  ```python
880
885
  from py_wecom_toolkit.webhook.client import Client as WebhookClient
881
886
 
882
- with WebhookClient(key="your_webhook_key") as client:
887
+ with WebhookClient(key=WEBHOOK_KEY) as client:
883
888
  resp = client.send_news(
884
889
  articles=[
885
890
  {
@@ -903,7 +908,7 @@ import asyncio
903
908
  from py_wecom_toolkit.webhook.client import AsyncClient as WebhookClient
904
909
 
905
910
  async def main():
906
- async with WebhookClient(key="your_webhook_key") as client:
911
+ async with WebhookClient(key=WEBHOOK_KEY) as client:
907
912
  resp = await client.send_news(
908
913
  articles=[
909
914
  {
@@ -929,7 +934,7 @@ asyncio.run(main())
929
934
  ```python
930
935
  from py_wecom_toolkit.webhook.client import Client as WebhookClient
931
936
 
932
- with WebhookClient(key="your_webhook_key") as client:
937
+ with WebhookClient(key=WEBHOOK_KEY) as client:
933
938
  resp = client.send_file(media_id="MEDIA_ID_123")
934
939
  if resp.ok:
935
940
  print("文件消息发送成功")
@@ -944,7 +949,7 @@ import asyncio
944
949
  from py_wecom_toolkit.webhook.client import AsyncClient as WebhookClient
945
950
 
946
951
  async def main():
947
- async with WebhookClient(key="your_webhook_key") as client:
952
+ async with WebhookClient(key=WEBHOOK_KEY) as client:
948
953
  resp = await client.send_file(media_id="MEDIA_ID_123")
949
954
  if resp.ok:
950
955
  print("文件消息发送成功")
@@ -961,7 +966,7 @@ asyncio.run(main())
961
966
  ```python
962
967
  from py_wecom_toolkit.webhook.client import Client as WebhookClient
963
968
 
964
- with WebhookClient(key="your_webhook_key") as client:
969
+ with WebhookClient(key=WEBHOOK_KEY) as client:
965
970
  resp = client.send_voice(media_id="MEDIA_ID_VOICE")
966
971
  if resp.ok:
967
972
  print("语音消息发送成功")
@@ -976,7 +981,7 @@ import asyncio
976
981
  from py_wecom_toolkit.webhook.client import AsyncClient as WebhookClient
977
982
 
978
983
  async def main():
979
- async with WebhookClient(key="your_webhook_key") as client:
984
+ async with WebhookClient(key=WEBHOOK_KEY) as client:
980
985
  resp = await client.send_voice(media_id="MEDIA_ID_VOICE")
981
986
  if resp.ok:
982
987
  print("语音消息发送成功")
@@ -993,7 +998,7 @@ asyncio.run(main())
993
998
  ```python
994
999
  from py_wecom_toolkit.webhook.client import Client as WebhookClient
995
1000
 
996
- with WebhookClient(key="your_webhook_key") as client:
1001
+ with WebhookClient(key=WEBHOOK_KEY) as client:
997
1002
  resp = client.send_template_card(
998
1003
  card_type="text_notice",
999
1004
  main_title_title="欢迎使用企业微信",
@@ -1014,7 +1019,7 @@ import asyncio
1014
1019
  from py_wecom_toolkit.webhook.client import AsyncClient as WebhookClient
1015
1020
 
1016
1021
  async def main():
1017
- async with WebhookClient(key="your_webhook_key") as client:
1022
+ async with WebhookClient(key=WEBHOOK_KEY) as client:
1018
1023
  resp = await client.send_template_card(
1019
1024
  card_type="text_notice",
1020
1025
  main_title_title="欢迎使用企业微信",
@@ -120,6 +120,8 @@ uv sync --all-groups
120
120
 
121
121
  ## 📖 使用说明
122
122
 
123
+ > ⚠️ 注意:以下示例中的 `CORP_ID`、`CORP_SECRET`、`AGENT_ID`、`TOUSER`、`WEBHOOK_KEY` 均为占位符,请替换为您的实际值后再使用。
124
+
123
125
  ### 1. server 模块 - 企业微信服务端 API
124
126
 
125
127
  server 模块提供企业微信服务端 API 的访问功能,包括 access_token 获取、应用消息发送、素材管理等。
@@ -135,7 +137,7 @@ from py_wecom_toolkit.server.client import Client
135
137
  from py_wecom_toolkit.server.response import AccessTokenResponse
136
138
 
137
139
  # 初始化客户端
138
- with Client(corpid="your_corp_id", corpsecret="your_corp_secret") as client:
140
+ with Client(corpid=CORP_ID, corpsecret=CORP_SECRET) as client:
139
141
  resp: AccessTokenResponse = client.get_token()
140
142
  if resp.ok:
141
143
  print(f"access_token: {resp.access_token}")
@@ -152,7 +154,7 @@ from py_wecom_toolkit.server.client import AsyncClient
152
154
  from py_wecom_toolkit.server.response import AccessTokenResponse
153
155
 
154
156
  async def main():
155
- async with AsyncClient(corpid="your_corp_id", corpsecret="your_corp_secret") as client:
157
+ async with AsyncClient(corpid=CORP_ID, corpsecret=CORP_SECRET) as client:
156
158
  resp: AccessTokenResponse = await client.get_token()
157
159
  if resp.ok:
158
160
  print(f"access_token: {resp.access_token}")
@@ -175,10 +177,10 @@ asyncio.run(main())
175
177
  from py_wecom_toolkit.server.message.client import Client as MessageClient
176
178
  from py_wecom_toolkit.server.message.msgtype import TextMessage
177
179
 
178
- with MessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
180
+ with MessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
179
181
  msg = TextMessage(
180
- touser="Guolei",
181
- agentid=1000035,
182
+ touser=TOUSER,
183
+ agentid=AGENT_ID,
182
184
  text={"content": "Hello, WeCom!"}
183
185
  )
184
186
  resp = client.send(msg)
@@ -196,10 +198,10 @@ from py_wecom_toolkit.server.message.client import AsyncClient as MessageClient
196
198
  from py_wecom_toolkit.server.message.msgtype import TextMessage
197
199
 
198
200
  async def main():
199
- async with AsyncMessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
201
+ async with AsyncMessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
200
202
  msg = TextMessage(
201
- touser="Guolei",
202
- agentid=1000035,
203
+ touser=TOUSER,
204
+ agentid=AGENT_ID,
203
205
  text={"content": "Hello, WeCom!"}
204
206
  )
205
207
  resp = await client.send(msg)
@@ -219,10 +221,10 @@ asyncio.run(main())
219
221
  from py_wecom_toolkit.server.message.client import Client as MessageClient
220
222
  from py_wecom_toolkit.server.message.msgtype import MarkdownMessage
221
223
 
222
- with MessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
224
+ with MessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
223
225
  msg = MarkdownMessage(
224
- touser="Guolei",
225
- agentid=1000035,
226
+ touser=TOUSER,
227
+ agentid=AGENT_ID,
226
228
  markdown={"content": "**加粗**\n*斜体*\n[链接](https://example.com)\n> 引用内容"}
227
229
  )
228
230
  resp = client.send(msg)
@@ -240,10 +242,10 @@ from py_wecom_toolkit.server.message.client import AsyncClient as MessageClient
240
242
  from py_wecom_toolkit.server.message.msgtype import MarkdownMessage
241
243
 
242
244
  async def main():
243
- async with AsyncMessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
245
+ async with AsyncMessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
244
246
  msg = MarkdownMessage(
245
- touser="Guolei",
246
- agentid=1000035,
247
+ touser=TOUSER,
248
+ agentid=AGENT_ID,
247
249
  markdown={"content": "**加粗**\n*斜体*\n[链接](https://example.com)\n> 引用内容"}
248
250
  )
249
251
  resp = await client.send(msg)
@@ -263,10 +265,10 @@ asyncio.run(main())
263
265
  from py_wecom_toolkit.server.message.client import Client as MessageClient
264
266
  from py_wecom_toolkit.server.message.msgtype import MarkdownV2Message
265
267
 
266
- with MessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
268
+ with MessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
267
269
  msg = MarkdownV2Message(
268
- touser="Guolei",
269
- agentid=1000035,
270
+ touser=TOUSER,
271
+ agentid=AGENT_ID,
270
272
  markdown_v2={"content": "# 标题\n- 列表项1\n- 列表项2\n| 姓名 | 年龄 |\n| --- | --- |\n| 张三 | 25 |"}
271
273
  )
272
274
  resp = client.send(msg)
@@ -284,10 +286,10 @@ from py_wecom_toolkit.server.message.client import AsyncClient as MessageClient
284
286
  from py_wecom_toolkit.server.message.msgtype import MarkdownV2Message
285
287
 
286
288
  async def main():
287
- async with AsyncMessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
289
+ async with AsyncMessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
288
290
  msg = MarkdownV2Message(
289
- touser="Guolei",
290
- agentid=1000035,
291
+ touser=TOUSER,
292
+ agentid=AGENT_ID,
291
293
  markdown_v2={"content": "# 标题\n- 列表项1\n- 列表项2\n| 姓名 | 年龄 |\n| --- | --- |\n| 张三 | 25 |"}
292
294
  )
293
295
  resp = await client.send(msg)
@@ -307,10 +309,10 @@ asyncio.run(main())
307
309
  from py_wecom_toolkit.server.message.client import Client as MessageClient
308
310
  from py_wecom_toolkit.server.message.msgtype import ImageMessage
309
311
 
310
- with MessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
312
+ with MessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
311
313
  msg = ImageMessage(
312
- touser="Guolei",
313
- agentid=1000035,
314
+ touser=TOUSER,
315
+ agentid=AGENT_ID,
314
316
  image={"base64": "BASE64_ENCODED_IMAGE_DATA", "md5": "MD5_OF_BASE64_DATA"}
315
317
  )
316
318
  resp = client.send(msg)
@@ -328,10 +330,10 @@ from py_wecom_toolkit.server.message.client import AsyncClient as MessageClient
328
330
  from py_wecom_toolkit.server.message.msgtype import ImageMessage
329
331
 
330
332
  async def main():
331
- async with AsyncMessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
333
+ async with AsyncMessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
332
334
  msg = ImageMessage(
333
- touser="Guolei",
334
- agentid=1000035,
335
+ touser=TOUSER,
336
+ agentid=AGENT_ID,
335
337
  image={"base64": "BASE64_ENCODED_IMAGE_DATA", "md5": "MD5_OF_BASE64_DATA"}
336
338
  )
337
339
  resp = await client.send(msg)
@@ -351,10 +353,10 @@ asyncio.run(main())
351
353
  from py_wecom_toolkit.server.message.client import Client as MessageClient
352
354
  from py_wecom_toolkit.server.message.msgtype import NewsMessage
353
355
 
354
- with MessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
356
+ with MessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
355
357
  msg = NewsMessage(
356
- touser="Guolei",
357
- agentid=1000035,
358
+ touser=TOUSER,
359
+ agentid=AGENT_ID,
358
360
  news={
359
361
  "articles": [
360
362
  {
@@ -381,10 +383,10 @@ from py_wecom_toolkit.server.message.client import AsyncClient as MessageClient
381
383
  from py_wecom_toolkit.server.message.msgtype import NewsMessage
382
384
 
383
385
  async def main():
384
- async with AsyncMessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
386
+ async with AsyncMessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
385
387
  msg = NewsMessage(
386
- touser="Guolei",
387
- agentid=1000035,
388
+ touser=TOUSER,
389
+ agentid=AGENT_ID,
388
390
  news={
389
391
  "articles": [
390
392
  {
@@ -413,10 +415,10 @@ asyncio.run(main())
413
415
  from py_wecom_toolkit.server.message.client import Client as MessageClient
414
416
  from py_wecom_toolkit.server.message.msgtype import FileMessage
415
417
 
416
- with MessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
418
+ with MessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
417
419
  msg = FileMessage(
418
- touser="Guolei",
419
- agentid=1000035,
420
+ touser=TOUSER,
421
+ agentid=AGENT_ID,
420
422
  file={"media_id": "MEDIA_ID_123"} # 需要先上传文件获取 media_id
421
423
  )
422
424
  resp = client.send(msg)
@@ -434,10 +436,10 @@ from py_wecom_toolkit.server.message.client import AsyncClient as MessageClient
434
436
  from py_wecom_toolkit.server.message.msgtype import FileMessage
435
437
 
436
438
  async def main():
437
- async with AsyncMessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
439
+ async with AsyncMessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
438
440
  msg = FileMessage(
439
- touser="Guolei",
440
- agentid=1000035,
441
+ touser=TOUSER,
442
+ agentid=AGENT_ID,
441
443
  file={"media_id": "MEDIA_ID_123"} # 需要先上传文件获取 media_id
442
444
  )
443
445
  resp = await client.send(msg)
@@ -457,10 +459,10 @@ asyncio.run(main())
457
459
  from py_wecom_toolkit.server.message.client import Client as MessageClient
458
460
  from py_wecom_toolkit.server.message.msgtype import VoiceMessage
459
461
 
460
- with MessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
462
+ with MessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
461
463
  msg = VoiceMessage(
462
- touser="Guolei",
463
- agentid=1000035,
464
+ touser=TOUSER,
465
+ agentid=AGENT_ID,
464
466
  voice={"media_id": "MEDIA_ID_VOICE"} # 需要先上传语音文件获取 media_id
465
467
  )
466
468
  resp = client.send(msg)
@@ -478,10 +480,10 @@ from py_wecom_toolkit.server.message.client import AsyncClient as MessageClient
478
480
  from py_wecom_toolkit.server.message.msgtype import VoiceMessage
479
481
 
480
482
  async def main():
481
- async with AsyncMessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
483
+ async with AsyncMessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
482
484
  msg = VoiceMessage(
483
- touser="Guolei",
484
- agentid=1000035,
485
+ touser=TOUSER,
486
+ agentid=AGENT_ID,
485
487
  voice={"media_id": "MEDIA_ID_VOICE"} # 需要先上传语音文件获取 media_id
486
488
  )
487
489
  resp = await client.send(msg)
@@ -501,10 +503,10 @@ asyncio.run(main())
501
503
  from py_wecom_toolkit.server.message.client import Client as MessageClient
502
504
  from py_wecom_toolkit.server.message.msgtype import TemplateCardMessage
503
505
 
504
- with MessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
506
+ with MessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
505
507
  msg = TemplateCardMessage(
506
- touser="Guolei",
507
- agentid=1000035,
508
+ touser=TOUSER,
509
+ agentid=AGENT_ID,
508
510
  template_card={
509
511
  "card_type": "text_notice",
510
512
  "main_title": {
@@ -536,10 +538,10 @@ from py_wecom_toolkit.server.message.client import AsyncClient as MessageClient
536
538
  from py_wecom_toolkit.server.message.msgtype import TemplateCardMessage
537
539
 
538
540
  async def main():
539
- async with AsyncMessageClient(corpid="your_corp_id", corpsecret="your_corp_secret", agentid=1000035) as client:
541
+ async with AsyncMessageClient(corpid=CORP_ID, corpsecret=CORP_SECRET, agentid=AGENT_ID) as client:
540
542
  msg = TemplateCardMessage(
541
- touser="Guolei",
542
- agentid=1000035,
543
+ touser=TOUSER,
544
+ agentid=AGENT_ID,
543
545
  template_card={
544
546
  "card_type": "text_notice",
545
547
  "main_title": {
@@ -577,7 +579,7 @@ asyncio.run(main())
577
579
  from py_wecom_toolkit.server.material.client import Client as MaterialClient
578
580
  from py_wecom_toolkit.server.material.msgtype import MaterialType
579
581
 
580
- with MaterialClient(corpid="your_corp_id", corpsecret="your_corp_secret") as client:
582
+ with MaterialClient(corpid=CORP_ID, corpsecret=CORP_SECRET) as client:
581
583
  resp = client.upload(
582
584
  media_type=MaterialType.FILE, # 文件类型:file
583
585
  file="path/to/your/file.txt", # 本地文件路径
@@ -597,7 +599,7 @@ from py_wecom_toolkit.server.material.client import AsyncClient as MaterialClien
597
599
  from py_wecom_toolkit.server.material.msgtype import MaterialType
598
600
 
599
601
  async def main():
600
- async with AsyncMaterialClient(corpid="your_corp_id", corpsecret="your_corp_secret") as client:
602
+ async with AsyncMaterialClient(corpid=CORP_ID, corpsecret=CORP_SECRET) as client:
601
603
  resp = await client.upload(
602
604
  media_type=MaterialType.FILE, # 文件类型:file
603
605
  file="path/to/your/file.txt", # 本地文件路径
@@ -618,7 +620,7 @@ asyncio.run(main())
618
620
  ```python
619
621
  from py_wecom_toolkit.server.material.client import Client as MaterialClient
620
622
 
621
- with MaterialClient(corpid="your_corp_id", corpsecret="your_corp_secret") as client:
623
+ with MaterialClient(corpid=CORP_ID, corpsecret=CORP_SECRET) as client:
622
624
  resp = client.upload_img(
623
625
  file="path/to/your/image.jpg",
624
626
  filename="image.jpg"
@@ -636,7 +638,7 @@ import asyncio
636
638
  from py_wecom_toolkit.server.material.client import AsyncClient as MaterialClient
637
639
 
638
640
  async def main():
639
- async with AsyncMaterialClient(corpid="your_corp_id", corpsecret="your_corp_secret") as client:
641
+ async with AsyncMaterialClient(corpid=CORP_ID, corpsecret=CORP_SECRET) as client:
640
642
  resp = await client.upload_img(
641
643
  file="path/to/your/image.jpg",
642
644
  filename="image.jpg"
@@ -656,7 +658,7 @@ asyncio.run(main())
656
658
  ```python
657
659
  from py_wecom_toolkit.server.material.client import Client as MaterialClient
658
660
 
659
- with MaterialClient(corpid="your_corp_id", corpsecret="your_corp_secret") as client:
661
+ with MaterialClient(corpid=CORP_ID, corpsecret=CORP_SECRET) as client:
660
662
  data = client.download(media_id="MEDIA_ID_123")
661
663
 
662
664
  if isinstance(data, bytes):
@@ -674,7 +676,7 @@ import asyncio
674
676
  from py_wecom_toolkit.server.material.client import AsyncClient as MaterialClient
675
677
 
676
678
  async def main():
677
- async with AsyncMaterialClient(corpid="your_corp_id", corpsecret="your_corp_secret") as client:
679
+ async with AsyncMaterialClient(corpid=CORP_ID, corpsecret=CORP_SECRET) as client:
678
680
  data = await client.download(media_id="MEDIA_ID_123")
679
681
 
680
682
  if isinstance(data, bytes):
@@ -698,7 +700,7 @@ Webhook 消息推送(原群机器人)不需要 `corpid` 和 `corpsecret`,
698
700
  ```python
699
701
  from py_wecom_toolkit.webhook.client import Client as WebhookClient
700
702
 
701
- with WebhookClient(key="your_webhook_key") as client:
703
+ with WebhookClient(key=WEBHOOK_KEY) as client:
702
704
  resp = client.send_text("Hello, WeCom Webhook!")
703
705
  if resp.ok:
704
706
  print("文本消息发送成功")
@@ -713,7 +715,7 @@ import asyncio
713
715
  from py_wecom_toolkit.webhook.client import AsyncClient as WebhookClient
714
716
 
715
717
  async def main():
716
- async with WebhookClient(key="your_webhook_key") as client:
718
+ async with WebhookClient(key=WEBHOOK_KEY) as client:
717
719
  resp = await client.send_text("Hello, WeCom Webhook!")
718
720
  if resp.ok:
719
721
  print("文本消息发送成功")
@@ -730,7 +732,7 @@ asyncio.run(main())
730
732
  ```python
731
733
  from py_wecom_toolkit.webhook.client import Client as WebhookClient
732
734
 
733
- with WebhookClient(key="your_webhook_key") as client:
735
+ with WebhookClient(key=WEBHOOK_KEY) as client:
734
736
  resp = client.send_markdown("**加粗文本**\n[链接](https://example.com)\n> 引用内容")
735
737
  if resp.ok:
736
738
  print("Markdown 消息发送成功")
@@ -745,7 +747,7 @@ import asyncio
745
747
  from py_wecom_toolkit.webhook.client import AsyncClient as WebhookClient
746
748
 
747
749
  async def main():
748
- async with WebhookClient(key="your_webhook_key") as client:
750
+ async with WebhookClient(key=WEBHOOK_KEY) as client:
749
751
  resp = await client.send_markdown("**加粗文本**\n[链接](https://example.com)\n> 引用内容")
750
752
  if resp.ok:
751
753
  print("Markdown 消息发送成功")
@@ -762,7 +764,7 @@ asyncio.run(main())
762
764
  ```python
763
765
  from py_wecom_toolkit.webhook.client import Client as WebhookClient
764
766
 
765
- with WebhookClient(key="your_webhook_key") as client:
767
+ with WebhookClient(key=WEBHOOK_KEY) as client:
766
768
  resp = client.send_markdown_v2("# 标题\n- 列表项1\n- 列表项2")
767
769
  if resp.ok:
768
770
  print("Markdown V2 消息发送成功")
@@ -777,7 +779,7 @@ import asyncio
777
779
  from py_wecom_toolkit.webhook.client import AsyncClient as WebhookClient
778
780
 
779
781
  async def main():
780
- async with WebhookClient(key="your_webhook_key") as client:
782
+ async with WebhookClient(key=WEBHOOK_KEY) as client:
781
783
  resp = await client.send_markdown_v2("# 标题\n- 列表项1\n- 列表项2")
782
784
  if resp.ok:
783
785
  print("Markdown V2 消息发送成功")
@@ -794,7 +796,7 @@ asyncio.run(main())
794
796
  ```python
795
797
  from py_wecom_toolkit.webhook.client import Client as WebhookClient
796
798
 
797
- with WebhookClient(key="your_webhook_key") as client:
799
+ with WebhookClient(key=WEBHOOK_KEY) as client:
798
800
  resp = client.send_image(base64="BASE64_DATA", md5="MD5_HASH")
799
801
  if resp.ok:
800
802
  print("图片消息发送成功")
@@ -809,7 +811,7 @@ import asyncio
809
811
  from py_wecom_toolkit.webhook.client import AsyncClient as WebhookClient
810
812
 
811
813
  async def main():
812
- async with WebhookClient(key="your_webhook_key") as client:
814
+ async with WebhookClient(key=WEBHOOK_KEY) as client:
813
815
  resp = await client.send_image(base64="BASE64_DATA", md5="MD5_HASH")
814
816
  if resp.ok:
815
817
  print("图片消息发送成功")
@@ -826,7 +828,7 @@ asyncio.run(main())
826
828
  ```python
827
829
  from py_wecom_toolkit.webhook.client import Client as WebhookClient
828
830
 
829
- with WebhookClient(key="your_webhook_key") as client:
831
+ with WebhookClient(key=WEBHOOK_KEY) as client:
830
832
  resp = client.send_news(
831
833
  articles=[
832
834
  {
@@ -850,7 +852,7 @@ import asyncio
850
852
  from py_wecom_toolkit.webhook.client import AsyncClient as WebhookClient
851
853
 
852
854
  async def main():
853
- async with WebhookClient(key="your_webhook_key") as client:
855
+ async with WebhookClient(key=WEBHOOK_KEY) as client:
854
856
  resp = await client.send_news(
855
857
  articles=[
856
858
  {
@@ -876,7 +878,7 @@ asyncio.run(main())
876
878
  ```python
877
879
  from py_wecom_toolkit.webhook.client import Client as WebhookClient
878
880
 
879
- with WebhookClient(key="your_webhook_key") as client:
881
+ with WebhookClient(key=WEBHOOK_KEY) as client:
880
882
  resp = client.send_file(media_id="MEDIA_ID_123")
881
883
  if resp.ok:
882
884
  print("文件消息发送成功")
@@ -891,7 +893,7 @@ import asyncio
891
893
  from py_wecom_toolkit.webhook.client import AsyncClient as WebhookClient
892
894
 
893
895
  async def main():
894
- async with WebhookClient(key="your_webhook_key") as client:
896
+ async with WebhookClient(key=WEBHOOK_KEY) as client:
895
897
  resp = await client.send_file(media_id="MEDIA_ID_123")
896
898
  if resp.ok:
897
899
  print("文件消息发送成功")
@@ -908,7 +910,7 @@ asyncio.run(main())
908
910
  ```python
909
911
  from py_wecom_toolkit.webhook.client import Client as WebhookClient
910
912
 
911
- with WebhookClient(key="your_webhook_key") as client:
913
+ with WebhookClient(key=WEBHOOK_KEY) as client:
912
914
  resp = client.send_voice(media_id="MEDIA_ID_VOICE")
913
915
  if resp.ok:
914
916
  print("语音消息发送成功")
@@ -923,7 +925,7 @@ import asyncio
923
925
  from py_wecom_toolkit.webhook.client import AsyncClient as WebhookClient
924
926
 
925
927
  async def main():
926
- async with WebhookClient(key="your_webhook_key") as client:
928
+ async with WebhookClient(key=WEBHOOK_KEY) as client:
927
929
  resp = await client.send_voice(media_id="MEDIA_ID_VOICE")
928
930
  if resp.ok:
929
931
  print("语音消息发送成功")
@@ -940,7 +942,7 @@ asyncio.run(main())
940
942
  ```python
941
943
  from py_wecom_toolkit.webhook.client import Client as WebhookClient
942
944
 
943
- with WebhookClient(key="your_webhook_key") as client:
945
+ with WebhookClient(key=WEBHOOK_KEY) as client:
944
946
  resp = client.send_template_card(
945
947
  card_type="text_notice",
946
948
  main_title_title="欢迎使用企业微信",
@@ -961,7 +963,7 @@ import asyncio
961
963
  from py_wecom_toolkit.webhook.client import AsyncClient as WebhookClient
962
964
 
963
965
  async def main():
964
- async with WebhookClient(key="your_webhook_key") as client:
966
+ async with WebhookClient(key=WEBHOOK_KEY) as client:
965
967
  resp = await client.send_template_card(
966
968
  card_type="text_notice",
967
969
  main_title_title="欢迎使用企业微信",
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "py_wecom_toolkit"
7
- version = "4.0.0"
7
+ version = "4.0.2"
8
8
  description = "Enterprise WeChat (WeCom) API toolkit for Python / 企业微信(WeCom)API 工具包"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -44,6 +44,8 @@ dependencies = [
44
44
  "diskcache>=5.6.0",
45
45
  "redis>=5.0.0",
46
46
  ]
47
+
48
+ [project.urls]
47
49
  homepage = "https://gitee.com/guolei19850528/py_wecom_toolkit"
48
50
  repository = "https://gitee.com/guolei19850528/py_wecom_toolkit"
49
51