- 将硬编码的时间配置改为从CONFIG读取 - 支持多接收人配置,修改open_id为数组类型 - 增加发送时间等待功能,确保消息在指定时间发送 - 改进停止定时任务的进程查找逻辑 - 更新配置项,增加checking_time、sending_time和message字段
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
import json
|
|
|
|
import lark_oapi as lark
|
|
from lark_oapi.api.im.v1 import *
|
|
from config import CONFIG
|
|
|
|
def main():
|
|
|
|
Local_openid = CONFIG['open_id']
|
|
# 创建client
|
|
client = lark.Client.builder() \
|
|
.app_id(CONFIG['app_id']) \
|
|
.app_secret(CONFIG['app_secret']) \
|
|
.log_level(lark.LogLevel.DEBUG) \
|
|
.build()
|
|
|
|
# 构造请求对象
|
|
for local_openid in Local_openid:
|
|
request: CreateMessageRequest = CreateMessageRequest.builder() \
|
|
.receive_id_type("open_id") \
|
|
.request_body(CreateMessageRequestBody.builder()
|
|
.receive_id(local_openid)
|
|
.msg_type("text")
|
|
.content("{\"text\":\"请打开微信或者登录微信\"}")
|
|
.build()) \
|
|
.build()
|
|
|
|
# 发起请求
|
|
response: CreateMessageResponse = client.im.v1.message.create(request)
|
|
|
|
# 处理失败返回
|
|
if not response.success():
|
|
lark.logger.error(
|
|
f"client.im.v1.message.create failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}, resp: \n{json.dumps(json.loads(response.raw.content), indent=4, ensure_ascii=False)}")
|
|
return
|
|
|
|
# 处理业务结果
|
|
lark.logger.info(lark.JSON.marshal(response.data, indent=4))
|
|
|
|
if __name__ == "__main__":
|
|
main() |