python 微信企业号

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

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

下面就是python代码:
1、根据CorpID和Secret得到token

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
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值