Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

Administrator / lesson7_2

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Commit cc762189 authored 3 years ago by BellCodeEditor's avatar BellCodeEditor
Browse files
Options
  • Browse Files
  • Download
  • Email Patches
  • Plain Diff

auto save

parent 027d3568
Hide whitespace changes
Inline Side-by-side
Showing with 153 additions and 4 deletions
  • diy2.py
  • test.py
  • test3.py
  • weixin.py
diy2.py deleted 100644 → 0
View file @ 027d3568
message = "诺依,周末一起去看动漫展吧!"
# 请对message进行遍历,取出所有元素
This diff is collapsed. Click to expand it.
test.py 0 → 100644
View file @ cc762189
import json
import time
import requests
'''
本文件主要实现通过企业微信应用给企业成员发消息
'''
CORP_ID = "ww6c197cad656c4f0c"
SECRET = "VqDsDTNVBdoDFovXSe9Wpd8Ar5gUEGal-wDK0hkGpgI"
class WeChatPub:
s = requests.session()
def __init__(self):
self.token = self.get_token()
def get_token(self):
url = f"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={CORP_ID}&corpsecret={SECRET}"
rep = self.s.get(url)
if rep.status_code != 200:
print("request failed.")
return
return json.loads(rep.content)['access_token']
def send_msg(self, content):
url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + self.token
header = {
"Content-Type": "application/json"
}
form_data = {
"touser": "FengXianMei",#接收人
"toparty": "1",#接收部门
"totag": " TagID1 | TagID2 ",#通讯录标签id
"msgtype": "textcard",
"agentid": 1000002,#应用ID
"textcard": {
"title": "债券打新提醒",
"description": content,
"url": "URL",
"btntxt": "更多"
},
"safe": 0
}
rep = self.s.post(url, data=json.dumps(form_data).encode('utf-8'), headers=header)
if rep.status_code != 200:
print("request failed.")
return
return json.loads(rep.content)
if __name__ == "__main__":
wechat = WeChatPub()
timenow = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
wechat.send_msg(f"<div class=\"gray\">{timenow}</div> <div class=\"normal\">注意!</div><div class=\"highlight\">今日有新债,坚持打新!</div>")
print('消息已发送!')
\ No newline at end of file
This diff is collapsed. Click to expand it.
test3.py 0 → 100644
View file @ cc762189
import json
import datetime
import requests
CORP_ID = "ww6c197cad656c4f0c"
SECRET = "vyYdOzCPEaeY4-hcQ10FWIX0buFnH-NlrnfGyTgGSmQ"
class WeChatPub:
s = requests.session()
def __init__(self):
self.token = self.get_token()
def get_token(self):
url = f"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={CORP_ID}&corpsecret={SECRET}"
rep = self.s.get(url)
if rep.status_code != 200:
print("request failed.")
return
return json.loads(rep.content)['access_token']
def send_msg(self, content):
url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + self.token
header = {
"Content-Type": "application/json"
}
form_data = {
"touser": "@all",
"toparty": " PartyID1 | PartyID2 ",
"totag": " TagID1 | TagID2 ",
"msgtype": "textcard",
"agentid": 1000003,
"textcard": {
"title": "服务异常告警",
"description": content,
"url": "URL",
"btntxt": "更多"
},
"safe": 0
rep = self.s.post(url, data=json.dumps(form_data).encode('utf-8'), headers=header)
return json.loads(rep.content)
wechat = WeChatPub()
now = datetime.datetime.now()
timenow = now.strftime('%Y年%m月%d日 %H:%M:%S')
wechat.send_msg(f"<div class=\"gray\">{timenow}</div> <div class=\"normal\">阿里云 cookie 已失效</div><div class=\"highlight\">请尽快更换新的 cookie</div>")
\ No newline at end of file
This diff is collapsed. Click to expand it.
weixin.py 0 → 100644
View file @ cc762189
import json
import time
import requests
'''
本文件主要实现通过企业微信应用给企业成员发消息
'''
CORP_ID = "ww6c197cad656c4f0c"
SECRET = "yANmG547H_CggNaOPPxsQaccO7dutWoTW_fL_IPqCdA"
class WeChatPub:
s = requests.session()
def __init__(self):
self.token = self.get_token()
def get_token(self):
url = f"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={CORP_ID}&corpsecret={SECRET}"
rep = self.s.get(url)
if rep.status_code != 200:
print("request failed.")
return
return json.loads(rep.content)['access_token']
def send_msg(self, content):
url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + self.token
header = {
"Content-Type": "application/json"
}
form_data = {
"touser": "FengXianMei",#接收人
"toparty": "1",#接收部门
"totag": " TagID1 | TagID2 ",#通讯录标签id
"msgtype": "textcard",
"agentid": 1000004,#应用ID
"textcard": {
"title": "债券打新提醒",
"description": content,
"url": "URL",
"btntxt": "更多"
},
"safe": 0
}
rep = self.s.post(url, data=json.dumps(form_data).encode('utf-8'), headers=header)
if rep.status_code != 200:
print("request failed.")
return
return json.loads(rep.content)
if __name__ == "__main__":
wechat = WeChatPub()
timenow = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
wechat.send_msg(f"<div class=\"gray\">{timenow}</div> <div class=\"normal\">注意,今晚隔扣小罗!</div><div class=\"highlight\">今日有新债,坚持打新!</div>")
print('消息已发送!')
\ No newline at end of file
This diff is collapsed. Click to expand it.
  • Write
  • Preview
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment