美文网首页
企业微信

企业微信

作者: 快去学习不然怎么去看aimer | 来源:发表于2019-09-25 19:20 被阅读0次

    1.注册企业微信

    搜索企业微信,用自己的微信登录即可。

    2.创建自定义应用

    ![image](https://img.haomeiwen.com/i11414906/b5803620314dc6be.png?imageMogr2/auto-orient/strip|imageView2/2/w/753/format/webp)

    3准备发送消息的相关数据

    image

    接着在页面的右上角点击 API文档

    image
    image
    image
    image
    image
    4代码发送:
    参考官方文档
    import requests
    Secret = "gHThgVQ3hsSTV3lYp8k4OQxMHcYyCiu-EX5eAP4XWy8"
    corpid = 'ww8dfe8b7e1596048d'
    url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={}&corpsecret={}'
    getr = requests.get(url=url.format(corpid,Secret))
    #
    # print(r.json())
    # {'errcode': 0, 'errmsg': 'ok', 'access_token': 't2HxARFMOgge-neHJwYXe4MrIXlFcu2m_Ev1pGQIAcmu-Kt1kQ7pey6jkPfdecqyvvZ9RGb3oSfjL1-lbbp1Y6UGGi8ZjNNd64AALtbR58ot1lh6VjE2ITkiWwgIftwWyryNDw_1AJAtVYYQxKU2O16a7NhHVEdcHG20u8czD-QUDUec1LqI4503OcVGzdR4Cq_4yA6a3fIkVLdQ_u3CHg', 'expires_in': 7200}
    access_token = getr.json().get('access_token')
    # access_token ='t2HxARFMOgge-neHJwYXe4MrIXlFcu2m_Ev1pGQIAcmu-Kt1kQ7pey6jkPfdecqyvvZ9RGb3oSfjL1-lbbp1Y6UGGi8ZjNNd64AALtbR58ot1lh6VjE2ITkiWwgIftwWyryNDw_1AJAtVYYQxKU2O16a7NhHVEdcHG20u8czD-QUDUec1LqI4503OcVGzdR4Cq_4yA6a3fIkVLdQ_u3CHg'
    data = {
      #  "touser" : "SheShouZuo",   # 向这些用户账户发送
       "toparty" : "2",   # 向这些部门发送
       "msgtype" : "text",
       "agentid" : 1000002,                       # 应用的 id 号
       "text" : {
           "content" : "一看到你,我^_^。"
       },
       "safe":0
    }
    import json
    r = requests.post(url="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={}".format(access_token),
                  data=json.dumps(data))
    print(r.json())
    

    相关文章

      网友评论

          本文标题:企业微信

          本文链接:https://www.haomeiwen.com/subject/rxhyyctx.html