关键词搜索

源码搜索 ×
×

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

发布2020-06-08浏览1052次

详情内容

1、设置用户备注名

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

updateremark.php

  1. <?php
  2. require_once("../Utils.php");
  3. $data = '{
  4. "openid":"o4WmZ0h-4huBUVQUczx2ezaxIL9c",
  5. "remark":"Jhon"
  6. }';
  7. $url = "https://api.weixin.qq.com/cgi-bin/user/info/updateremark?"
  8. ."access_token=".Utils::get_access_token();
  9. $result = Utils::https_request($url, $data);
  10. 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

  1. <?php
  2. require_once("../Utils.php");
  3. $openId = "o4WmZ0h-4huBUVQUczx2ezaxIL9c";
  4. $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token="
  5. .Utils::get_access_token()."&openid=".$openId."&lang=zh_CN ";
  6. $result = Utils::https_request($url);
  7. echo $result;

返回:

  1. {
  2. "subscribe": 1,
  3. "openid": "o4WmZ0h-4huBUVQUczx2ezaxIL9c",
  4. "nickname": "Promise",
  5. "sex": 1,
  6. "language": "zh_CN",
  7. "city": "",
  8. "province": "",
  9. "country": "",
  10. "headimgurl": "http://wx.qlogo.cn/mmopen/Vq7PMkMOaMYgtQNJBrdesiantXGgGkliaoI3StUtnG5DUA1oYaeTlOdjicYHu9EkMvLY2gXf7rHBzGNiaPoDyvmZ0ONEGm7PfGBb/0",
  11. "subscribe_time": 1504708412,
  12. "remark": "Jhon",
  13. "groupid": 0,
  14. "tagid_list": []
  15. }

3、批量获取用户消息

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

batchget.php

  1. <?php
  2. require_once("../Utils.php");
  3. $data = '{
  4. "user_list": [
  5. {
  6. "openid": "o4WmZ0h-4huBUVQUczx2ezaxIL9c",
  7. "lang": "zh_CN"
  8. }
  9. ]
  10. }';
  11. $url = "https://api.weixin.qq.com/cgi-bin/user/info/batchget?"
  12. ."access_token=".Utils::get_access_token();
  13. $result = Utils::https_request($url, $data);
  14. echo $result;

返回:

  1. {
  2. "user_info_list": [
  3. {
  4. "subscribe": 1,
  5. "openid": "o4WmZ0h-4huBUVQUczx2ezaxIL9c",
  6. "nickname": "Promise",
  7. "sex": 1,
  8. "language": "zh_CN",
  9. "city": "",
  10. "province": "",
  11. "country": "",
  12. "headimgurl": "http://wx.qlogo.cn/mmopen/Vq7PMkMOaMYgtQNJBrdesiantXGgGkliaoI3StUtnG5DUA1oYaeTlOdjicYHu9EkMvLY2gXf7rHBzGNiaPoDyvmZ0ONEGm7PfGBb/0",
  13. "subscribe_time": 1504708412,
  14. "remark": "Jhon",
  15. "groupid": 0,
  16. "tagid_list": []
  17. }
  18. ]
  19. }

4、创建标签

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

tags_create.php

  1. <?php
  2. @header('Content-type: text/plain;charset=UTF-8');
  3. require_once("../Utils.php");
  4. $data = '{
  5. "tag" : {
  6. "name" : "朋友"
  7. }
  8. }';
  9. $url = "https://api.weixin.qq.com/cgi-bin/tags/create?"
  10. ."access_token=".Utils::get_access_token();
  11. $result = Utils::https_request($url, $data);
  12. echo $result;

返回:

  1. {
  2. "tag": {
  3. "id": 101,
  4. "name": "朋友"
  5. }
  6. }

5、获取以创建标签

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

tags_get.php

  1. <?php
  2. @header('Content-type: text/plain;charset=UTF-8');
  3. require_once("../Utils.php");
  4. $url = "https://api.weixin.qq.com/cgi-bin/tags/get?access_token="
  5. .Utils::get_access_token();
  6. $result = Utils::https_request($url);
  7. echo $result;

返回:

  1. {
  2. "tags": [
  3. {
  4. "id": 2,
  5. "name": "星标组",
  6. "count": 0
  7. },
  8. {
  9. "id": 100,
  10. "name": "同学",
  11. "count": 0
  12. },
  13. {
  14. "id": 101,
  15. "name": "朋友",
  16. "count": 0
  17. }
  18. ]
  19. }

6、编辑标签

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

tags_update.php

  1. <?php
  2. @header('Content-type: text/plain;charset=UTF-8');
  3. require_once("../Utils.php");
  4. $data = '{
  5. "tag" : {
  6. "id" : 101,
  7. "name" : "好朋友"
  8. }
  9. }';
  10. $url = "https://api.weixin.qq.com/cgi-bin/tags/update?"
  11. ."access_token=".Utils::get_access_token();
  12. $result = Utils::https_request($url, $data);
  13. 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

  1. <?php
  2. @header('Content-type: text/plain;charset=UTF-8');
  3. require_once("../Utils.php");
  4. $data = '{
  5. "tag" : {
  6. "id" : 101
  7. }
  8. }';
  9. $url = "https://api.weixin.qq.com/cgi-bin/tags/delete?"
  10. ."access_token=".Utils::get_access_token();
  11. $result = Utils::https_request($url, $data);
  12. echo $result;

返回:

  1. {"errcode":0,"errmsg":"ok"}

8、批量为用户打标签

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

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

tags_batchtagging.php

  1. <?php
  2. @header('Content-type: text/plain;charset=UTF-8');
  3. require_once("../Utils.php");
  4. $data = '{
  5. "openid_list" : [
  6. "o4WmZ0h-4huBUVQUczx2ezaxIL9c"
  7. ],
  8. "tagid" : 100
  9. }';
  10. $url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?"
  11. ."access_token=".Utils::get_access_token();
  12. $result = Utils::https_request($url, $data);
  13. 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

  1. <?php
  2. @header('Content-type: text/plain;charset=UTF-8');
  3. require_once("../Utils.php");
  4. $data = '{
  5. "tagid" : 100,
  6. "next_openid":""
  7. }';
  8. $url = "https://api.weixin.qq.com/cgi-bin/user/tag/get?"
  9. ."access_token=".Utils::get_access_token();
  10. $result = Utils::https_request($url, $data);
  11. echo $result;

返回:

  1. {
  2. "count": 1,
  3. "data": {
  4. "openid": [
  5. "o4WmZ0h-4huBUVQUczx2ezaxIL9c"
  6. ]
  7. },
  8. "next_openid": "o4WmZ0h-4huBUVQUczx2ezaxIL9c"
  9. }

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

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

tags_getidlist.php

  1. <?php
  2. @header('Content-type: text/plain;charset=UTF-8');
  3. require_once("../Utils.php");
  4. $data = '{
  5. "openid" : "o4WmZ0h-4huBUVQUczx2ezaxIL9c"
  6. }';
  7. $url = "https://api.weixin.qq.com/cgi-bin/tags/getidlist?"
  8. ."access_token=".Utils::get_access_token();
  9. $result = Utils::https_request($url, $data);
  10. echo $result;

返回:

  1. {
  2. "tagid_list": [
  3. 100
  4. ]
  5. }

11、批量为用户取消标签

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

tags_batchuntagging.php

  1. <?php
  2. @header('Content-type: text/plain;charset=UTF-8');
  3. require_once("../Utils.php");
  4. $data = '{
  5. "openid_list" : [
  6. "o4WmZ0h-4huBUVQUczx2ezaxIL9c"
  7. ],
  8. "tagid" : 100
  9. }';
  10. $url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging?"
  11. ."access_token=".Utils::get_access_token();
  12. $result = Utils::https_request($url, $data);
  13. echo $result;

返回:

{"errcode":0,"errmsg":"ok"}

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

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载