国内有哪些同步盘?好用的同步网盘有哪些?
648
2022-06-04
### 个人注册企业微信号 ![](https://upload-images.jianshu.io/upload_images/3260639-de461fc3dbedc237.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) ![](https://upload-images.jianshu.io/upload_images/3260639-484df5f0b1151431.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) ![](https://upload-images.jianshu.io/upload_images/3260639-fe5c03e4a6f0468c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) ![](https://upload-images.jianshu.io/upload_images/3260639-546db88ff2c2e718.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) ![](https://upload-images.jianshu.io/upload_images/3260639-c715b79787a2af01.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) ![](https://upload-images.jianshu.io/upload_images/3260639-67b9b080fe392f41.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) ### requests的使用 * 首先需要安装requests库:`pip install requests`; * 然后通过`import requests`导入使用; * `requests.get()`方法可以获取某个网页,requests.post()可以发送POST请求; * 更多可以查看:[http://docs.python-requests.org/zh_CN/latest/user/quickstart.html](http://docs.python-requests.org/zh_CN/latest/user/quickstart.html) ### 企业微信的参数 * `Corpid`:表示企业ID,可以在企业微信->我的企业->企业ID; * `Secret`:应用的Secret,在应用与小程序->创建的应用程序->Secret; * `PartyID`:通讯录部门ID,通讯录->部门->部门ID; * `Agentid`:应用ID,在应用与小程序->创建的应用程序->AgentId; ### JSON 响应内容 * Requests 中也有一个内置的 JSON 解码器,用来处理 JSON 数据,如`r.json()`,如果 JSON 解码失败,`r.json()`就会抛出一个异常; * 需要注意的是,成功调用 `r.json()` 并不意味着响应的成功,有的服务器会在失败的响应中包 含一个 JSON 对象(比如 HTTP 500 的错误细节),这种 JSON 会被解码返回。要检查请 求是否成功,请使用 `r.raise_for_status()` 或者检查 `r.status_code` 是否和你的期望相同; ### 发送测试数据到企业微信 ``` import requests import sys import json def GetToken(Corpid,Secret): Url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken" Data = { "corpid":Corpid, "corpsecret":Secret } r = requests.get(url=Url,params=Data) Token = r.json()['access_token'] return Token def SendMessage(Token,Agentid,Subject,Content,): Url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=%s" % Token Data = { "toparty": PartyID, "msgtype": "text", "agentid": Agentid, "text": { "content": Subject + '\n' + Content }, "safe": "0" } ret = requests.post(url=Url,data=json.dumps(Data)) return ret.text if __name__ == '__main__': Subject = sys.argv[1] Content = sys.argv[2] # CorpID是企业ID Corpid = "ww5cfabaf35ce8cd7b" # 应用的Secret Secret = "uiwvmNj8f1IVy3QYrZ62WePGFKA_BsIPmHigq3TRydM" # 通讯录部门ID PartyID = "1" # 应用ID Agentid = "1000002" Token = GetToken(Corpid, Secret) status = SendMessage(Token, Agentid, Subject, Content) print(status) ``` * 将企业微信封装成接口,提供给外部调用 ``` import requests import json class Wechat_Info: def __init__(self): self.partyID = '1' self.corpID = '企业ID' self.secret = '应用的secret' self.agentID = '1000002' self.token = None def __get_token(self, corpid, secret): Url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken" Data = { "corpid": corpid, "corpsecret": secret } r = requests.get(url=Url, params=Data) token = r.json()['access_token'] return token def send_message(self, message): url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={}".format( self.__get_token(self.corpID, self.secret)) data = { "toparty": self.partyID, "msgtype": "text", "agentid": self.agentID, "text": { "content": message }, "safe": "0" } result = requests.post(url=url, data=json.dumps(data)) return result.text if __name__ == '__main__': wechat_info = Wechat_Info() result = wechat_info.send_message('微信测试') print(result) ``` 参考:[https://www.9xkd.com/user/plan-view.html?id=2632639503](https://www.9xkd.com/user/plan-view.html?id=2632639503)
发表评论
暂时没有评论,来抢沙发吧~