初识企业微信(企业号)开发(3)

648 阅读1分钟

前面已经获取了开发需要的重要参数access_token 以及 code,下面我们在根据code获取一下用户信息:

https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=ACCESS_TOKEN&code=CODE

根据上面的地址我们可以取到一个JSONObject,数据结构如下

{
   "errcode": 0,
   "errmsg": "ok",
   "UserId":"USERID",
   "DeviceId":"DEVICEID",
   "user_ticket": "USER_TICKET""expires_in":7200
}

我们可以在根据UserId 进一步的获取我们用户的详细信息

https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&userid=USERID

取到的也是一个JSONObject,数据结构如下

{
    "errcode": 0,
    "errmsg": "ok",
    "userid": "zhangsan",
    "name": "李四",
    "department": [1, 2],
    "order": [1, 2],
    "position": "后台工程师",
    "mobile": "15913215421",
    "gender": "1",
    "email": "zhangsan@gzdev.com",
    "isleader": 1,
    "avatar": "http://wx.qlogo.cn/mmopen/ajNVdqHZLLA3WJ6DSZUfiakYe37PKnQhBIeOQBO4czqrnZDS79FH5Wm5m4X69TBicnHFlhiafvDwklOpZeXYQQ2icg/0",
    "telephone": "020-123456",
    "enable": 1,
    "english_name": "jackzhang",
    "extattr": {
        "attrs": [{
            "name": "爱好",
            "value": "旅游"
        }, {
            "name": "卡号",
            "value": "1234567234"
        }]
    },
    "status": 1,
    "qr_code": "https://open.work.weixin.qq.com/wwopen/userQRCode?vcode=xxx",
    "external_profile": {
        "external_attr": [{
                "type": 0,
                "name": "文本名称",
                "text": {
                    "value": "文本"
                }
            },
            {
                "type": 1,
                "name": "网页名称",
                "web": {
                    "url": "http://www.test.com",
                    "title": "标题"
                }
            },
            {
                "type": 2,
                "name": "测试app",
                "miniprogram": {
                    "appid": "wx8bd80126147df384",
                    "pagepath": "/index",
                    "title": "my miniprogram"
                }
            }
        ]
    }
}

后面在介绍一下JSSDK 相关的东西