04:应用管理

目录:企业微信API其他篇

01: 企业微信API开发前准备

02:消息推送

03: 通讯录管理

04:应用管理

目录:

1.1 概述 & 创建应用     返回顶部

  官方文档http://work.weixin.qq.com/api/doc#10025

1.2 获取应用     返回顶部

  官方文档: http://work.weixin.qq.com/api/doc#10087

# -*- coding:UTF-8 -*-
import urllib2
import urllib
import json

def get_access_token():
    url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?'
    # corpid: 每个企业都拥有唯一的corpid       corpsecret: 自建应用secret
    para = {'corpid':'ww2f9a1a85f1806981','corpsecret':'tGFtVLxmjxPf6jj2t5SKyqEUYkpCM9e2hw-OrwSQwSg'}
    req = urllib2.Request(url + urllib.urlencode(para))
    ret = urllib2.urlopen(req)
    ret = json.loads(ret.read())
    return ret

token_id = get_access_token().get('access_token')

def read_app_info(token_id,agentid):
    ''' 获取执行用户信息
    :param token_id:  用于认证的access_token
    :param agentid:   自建应用id
    '''
    url = 'https://qyapi.weixin.qq.com/cgi-bin/agent/get?'
    para = {'access_token': token_id, 'agentid':agentid}
    req = urllib2.Request(url + urllib.urlencode(para))
    ret = urllib2.urlopen(req)
    ret = json.loads(ret.read())
    print ret

read_app_info(token_id, 1000002)
获取自建应用信息

1.3更新应用信息     返回顶部

  官方文档http://work.weixin.qq.com/api/doc#10088

# -*- coding:UTF-8 -*-
import urllib2
import urllib
import json

def get_access_token():
    url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?'
    # corpid: 每个企业都拥有唯一的corpid       corpsecret: 自建应用secret
    para = {'corpid':'ww2f9a1a85f1806981','corpsecret':'tGFtVLxmjxPf6jj2t5SKyqEUYkpCM9e2hw-OrwSQwSg'}
    req = urllib2.Request(url + urllib.urlencode(para))
    ret = urllib2.urlopen(req)
    ret = json.loads(ret.read())
    return ret

token_id = get_access_token().get('access_token')
data = {
    "agentid": "1000002",         # 应用id(必填)
    "name": "修改后的应用名称",   # 要修改的名称(选填)
}

def update_app_info(token_id,data):
    '''更新用户信息
    :param token_id:  用于认证的access_token
    :param data:     需要修改成的内容
    '''
    headers = {'Content-Type': 'application/json'}
    url = "https://qyapi.weixin.qq.com/cgi-bin/agent/set?access_token=%s" % (token_id)
    request = urllib2.Request(url=url, headers=headers, data=json.dumps(data))
    response = urllib2.urlopen(request)
    print response.read()  # 返回结果:{"errcode":0,"errmsg":"ok"}

update_app_info(token_id,data)
更新应用信息

 

posted @ 2018-04-18 11:33  不做大哥好多年  阅读(672)  评论(0编辑  收藏  举报