首頁  >  文章  >  微信小程式  >  微信公眾號實現用戶管理功能

微信公眾號實現用戶管理功能

一个新手
一个新手原創
2017-09-14 10:47:505921瀏覽

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中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn