微信公众号实现用户管理功能

一个新手
发布: 2017-09-14 10:47:50
原创
5910 人浏览过

1、设置用户备注名

接口:https://api.weixin.qq.com/cgi-bin/user/info/updateremark?access_token=ACCESS_TOKEN

updateremark.php

<?php
require_once("../Utils.php");
$data = &#39;{
    "openid":"o4WmZ0h-4huBUVQUczx2ezaxIL9c",
    "remark":"Jhon"
}&#39;;
$url = "https://api.weixin.qq.com/cgi-bin/user/info/updateremark?"
    ."access_token=".Utils::get_access_token();
$result = Utils::https_request($url, $data);
echo $result;
登录后复制

返回:

{"errcode":0,"errmsg":"ok"}
登录后复制
登录后复制
登录后复制
登录后复制

2、获取用户基本信息

接口:https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN

userInfp.php

<?php
require_once("../Utils.php");
$openId = "o4WmZ0h-4huBUVQUczx2ezaxIL9c";
$url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token="
    .Utils::get_access_token()."&openid=".$openId."&lang=zh_CN ";
$result = Utils::https_request($url);
echo $result;
登录后复制

返回:

{
    "subscribe": 1,
    "openid": "o4WmZ0h-4huBUVQUczx2ezaxIL9c",
    "nickname": "Promise",
    "sex": 1,
    "language": "zh_CN",
    "city": "",
    "province": "",
    "country": "",
    "headimgurl": "http://wx.qlogo.cn/mmopen/Vq7PMkMOaMYgtQNJBrdesiantXGgGkliaoI3StUtnG5DUA1oYaeTlOdjicYHu9EkMvLY2gXf7rHBzGNiaPoDyvmZ0ONEGm7PfGBb/0",
    "subscribe_time": 1504708412,
    "remark": "Jhon",
    "groupid": 0,
    "tagid_list": []
}
登录后复制

3、批量获取用户消息

接口:https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=ACCESS_TOKEN

batchget.php

<?php
require_once("../Utils.php");
$data = &#39;{
    "user_list": [
       {
           "openid": "o4WmZ0h-4huBUVQUczx2ezaxIL9c",
           "lang": "zh_CN"
       }
   ]
}&#39;;
$url = "https://api.weixin.qq.com/cgi-bin/user/info/batchget?"
    ."access_token=".Utils::get_access_token();
$result = Utils::https_request($url, $data);
echo $result;
登录后复制

返回:

{
    "user_info_list": [
        {
            "subscribe": 1,
            "openid": "o4WmZ0h-4huBUVQUczx2ezaxIL9c",
            "nickname": "Promise",
            "sex": 1,
            "language": "zh_CN",
            "city": "",
            "province": "",
            "country": "",
            "headimgurl": "http://wx.qlogo.cn/mmopen/Vq7PMkMOaMYgtQNJBrdesiantXGgGkliaoI3StUtnG5DUA1oYaeTlOdjicYHu9EkMvLY2gXf7rHBzGNiaPoDyvmZ0ONEGm7PfGBb/0",
            "subscribe_time": 1504708412,
            "remark": "Jhon",
            "groupid": 0,
            "tagid_list": []
        }
    ]
}
登录后复制

4、创建标签

接口:https://api.weixin.qq.com/cgi-bin/tags/create?access_token=ACCESS_TOKEN

tags_create.php

<?php
@header(&#39;Content-type: text/plain;charset=UTF-8&#39;);
require_once("../Utils.php");
$data = &#39;{
    "tag" : {
        "name" : "朋友"
  }
}&#39;;
$url = "https://api.weixin.qq.com/cgi-bin/tags/create?"
    ."access_token=".Utils::get_access_token();
$result = Utils::https_request($url, $data);
echo $result;
登录后复制

返回:

{
    "tag": {
        "id": 101,
        "name": "朋友"
    }
}
登录后复制

5、获取以创建标签

接口:https://api.weixin.qq.com/cgi-bin/tags/get?access_token=ACCESS_TOKEN

tags_get.php

<?php
@header(&#39;Content-type: text/plain;charset=UTF-8&#39;);
require_once("../Utils.php");
$url = "https://api.weixin.qq.com/cgi-bin/tags/get?access_token="
    .Utils::get_access_token();
$result = Utils::https_request($url);
echo $result;
登录后复制

返回:

{
    "tags": [
        {
            "id": 2,
            "name": "星标组",
            "count": 0
        },
        {
            "id": 100,
            "name": "同学",
            "count": 0
        },
        {
            "id": 101,
            "name": "朋友",
            "count": 0
        }
    ]
}
登录后复制

6、编辑标签

接口:https://api.weixin.qq.com/cgi-bin/tags/update?access_token=ACCESS_TOKEN

tags_update.php

<?php
@header(&#39;Content-type: text/plain;charset=UTF-8&#39;);
require_once("../Utils.php");
$data = &#39;{
    "tag" : {
        "id" : 101,
    "name" : "好朋友"
  }
}&#39;;
$url = "https://api.weixin.qq.com/cgi-bin/tags/update?"
    ."access_token=".Utils::get_access_token();
$result = Utils::https_request($url, $data);
echo $result;
登录后复制

返回:

{"errcode":0,"errmsg":"ok"}
登录后复制
登录后复制
登录后复制
登录后复制

7、删除标签

当某个标签下的粉丝超过10w时,后台不可直接删除标签。此时,开发者可以对该标签下的openid列表,先进行取消标签的操作,直到粉丝数不超过10w后,才可直接删除该标签。

接口:https://api.weixin.qq.com/cgi-bin/tags/delete?access_token=ACCESS_TOKEN

tags_delete.php

<?php
@header(&#39;Content-type: text/plain;charset=UTF-8&#39;);
require_once("../Utils.php");
$data = &#39;{
    "tag" : {
        "id" : 101
    }
}&#39;;
$url = "https://api.weixin.qq.com/cgi-bin/tags/delete?"
    ."access_token=".Utils::get_access_token();
$result = Utils::https_request($url, $data);
echo $result;
登录后复制

返回:

{"errcode":0,"errmsg":"ok"}
登录后复制
登录后复制
登录后复制
登录后复制

8、批量为用户打标签

标签功能目前支持公众号为用户打上最多20个标签。

接口:https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token=ACCESS_TOKEN

tags_batchtagging.php

<?php
@header(&#39;Content-type: text/plain;charset=UTF-8&#39;);
require_once("../Utils.php");
$data = &#39;{
    "openid_list" : [
        "o4WmZ0h-4huBUVQUczx2ezaxIL9c"
    ],
  "tagid" : 100
}&#39;;
$url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?"
    ."access_token=".Utils::get_access_token();
$result = Utils::https_request($url, $data);
echo $result;
登录后复制

返回结果:

{"errcode":0,"errmsg":"ok"}
登录后复制

9、获取标签下粉丝列表

接口:https://api.weixin.qq.com/cgi-bin/user/tag/get?access_token=ACCESS_TOKEN

 "next_openid":""//第一个拉取的OPENID,不填默认从头开始拉取

tags_get_user.php

<?php
@header(&#39;Content-type: text/plain;charset=UTF-8&#39;);
require_once("../Utils.php");
$data = &#39;{
  "tagid" : 100,
  "next_openid":""
}&#39;;
$url = "https://api.weixin.qq.com/cgi-bin/user/tag/get?"
    ."access_token=".Utils::get_access_token();
$result = Utils::https_request($url, $data);
echo $result;
登录后复制

返回:

{
    "count": 1,
    "data": {
        "openid": [
            "o4WmZ0h-4huBUVQUczx2ezaxIL9c"
        ]
    },
    "next_openid": "o4WmZ0h-4huBUVQUczx2ezaxIL9c"
}
登录后复制

10、获取用户身上的标签列表

接口;https://api.weixin.qq.com/cgi-bin/tags/getidlist?access_token=ACCESS_TOKEN

tags_getidlist.php

<?php
@header(&#39;Content-type: text/plain;charset=UTF-8&#39;);
require_once("../Utils.php");
$data = &#39;{
  "openid" : "o4WmZ0h-4huBUVQUczx2ezaxIL9c"
}&#39;;
$url = "https://api.weixin.qq.com/cgi-bin/tags/getidlist?"
    ."access_token=".Utils::get_access_token();
$result = Utils::https_request($url, $data);
echo $result;
登录后复制

返回:

{
    "tagid_list": [
        100
    ]
}
登录后复制

11、批量为用户取消标签

接口:https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging?access_token=ACCESS_TOKEN

tags_batchuntagging.php

<?php
@header(&#39;Content-type: text/plain;charset=UTF-8&#39;);
require_once("../Utils.php");
$data = &#39;{
    "openid_list" : [
        "o4WmZ0h-4huBUVQUczx2ezaxIL9c"
    ],
  "tagid" : 100
}&#39;;
$url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging?"
    ."access_token=".Utils::get_access_token();
$result = Utils::https_request($url, $data);
echo $result;
登录后复制

返回:

{"errcode":0,"errmsg":"ok"}
登录后复制
登录后复制
登录后复制
登录后复制

以上是微信公众号实现用户管理功能的详细内容。更多信息请关注PHP中文网其他相关文章!

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!