• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
金记缘
博客园    首页    新随笔    联系   管理    订阅  订阅

十、区块量化 通用文件 微信接口

1、首先申请开通微信企业号

2、新建一个应用

3、把应用id、企业Id、Secret 替换以下weixin.py文件

# -*- coding: utf-8 -*-
import requests
import json
import time
import sys

AppId = "1000002" # 应用id
CropID = 'wx00000000000000' # 企业Id
Secret = 'S_00000000000000000000000'

Gtoken = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=" + CropID + "&corpsecret=" + Secret
Purl = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token="
headers = {'Content-Type': 'application/json'}
Time = "\n告警时间:" + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())


def gettoken():
try:
r = requests.get(Gtoken)
json_data = json.loads(r.content.decode())
token = json_data["access_token"]
return token
except:
exit(1)


def senddata(user, content):
token = gettoken()
send_values = {
"touser": user,
"msgtype": "text",
"agentid": AppId,
"text": {
"content": content + Time
},
"safe": "0"
}
push = requests.post(Purl + token, data=json.dumps(send_values), headers=headers)
code = json.loads(push.content.decode())


if __name__ == '__main__':
user = str(sys.argv[1])
title = str(sys.argv[2])
content = str(sys.argv[3])
senddata(user, content)

 

posted @ 2023-06-17 21:48  一生所悟  阅读(121)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3