zoukankan      html  css  js  c++  java
  • python 微信企业号

     

     

     

     

    python 微信企业号

    准备,如果没有微信企业号,可以先申请体验号
    记下CorpID和Secret(获取Token用)
    这里写图片描述

    发送消息
    首先可以在微信的开发者中心,查看接口文档

    下面就是python代码:
    1、根据CorpID和Secret得到token<喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcD4NCjxwcmUgY2xhc3M9"java;"> def get_token_in_time(corp_id, secret): res = urllib2.urlopen('https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s' % (corp_id, secret)) res_dict = simplejson.loads(res.read()) token = res_dict.get('access_token', False) return token


    2、send

    def send_txt_msg(token, content, to_user="@all", to_party="", to_tag="", application_id=0, safe=0):
        try:
            data = {
                "touser": to_user,
                "toparty": to_party,
                "totag": to_tag,
                "msgtype": "text",
                "agentid": application_id,
                "text": {"content": content},
                "safe": safe
            }
    
            data = simplejson.dumps(data, ensure_ascii=False)
            print data, type(data)
            req = urllib2.Request('https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=%s' % (token,))
            resp = urllib2.urlopen(req, data)
            msg = u'返回值:' + resp.read()
        except Exception, ex:
            msg = u'异常:' + str(ex)
        finally:
            print msg
  • 相关阅读:
    Flume-概述-安装
    Hive-函数
    Hive_查询
    Hive-DML数据操作
    JDBC-文档
    Hive-DDL数据定义
    Hive-数据类型
    理解RESTful架构
    REST介绍
    [转]详述DHCP服务器的三种IP分配方式
  • 原文地址:https://www.cnblogs.com/adolfmc/p/7502818.html
Copyright © 2011-2022 走看看