Home  >  Article  >  php教程  >  微信公众平台开发(74) 用户分组管理

微信公众平台开发(74) 用户分组管理

WBOY
WBOYOriginal
2016-06-13 10:17:401638browse

微信公众平台开发 用户分组管理 分组管理接口 查询分组 创建分组 修改分组名 移动用户分组
作者:方倍工作室 
地址:http://www.cnblogs.com/txw1958/p/weixin74-group-manage.html 

 

开发者可以使用接口,对公众平台的分组进行查询、创建、修改操作,也可以使用接口在需要时移动用户到某个分组。

 

创建分组

一个公众账号,最多支持创建500个分组。 接口调用请求说明

http请求方式: POST(请使用https协议)
https://api.weixin.qq.com/cgi-bin/groups/create?access_token=ACCESS_TOKEN
POST数据格式:json
POST数据例子:{"group":{"name":"test"}}

参数说明

参数 说明
access_token 调用接口凭证
name 分组名字(30个字符以内)

返回说明 正常时的返回JSON数据包示例:

{
    "group": {
        "id": 107, 
        "name": "test"
    }
}

参数说明

参数 说明
id 分组id,由微信分配
name 分组名字,UTF8编码

错误时的JSON数据包示例(该示例为AppID无效错误):

{"errcode":40013,"errmsg":"invalid appid"}<br /><br /><br /><br />

创建代码:

<span $json</span> = '{"group":{"name":"朋友"}}'<span ;
</span><span $url</span> = "https://api.weixin.qq.com/cgi-bin/groups/create?access_token=6j68MFz5WyxI2_xrdSj1XfjhZu7c3qTpgC8PrBznfqUbHe8kbaEe_mEDWZi2TdPYpAx9ljJNkmy1B6-A7dPe2y9L7RdwcjN2QKrhOydyOnveek111j7crIrNHzFzuKpii8VpFpizs7YGcwuangkEXg"<span ;
</span><span $result</span> = https_post(<span $url</span>,<span $json</span><span );
</span><span var_dump</span>(<span $result</span><span );

</span><span function</span> https_post(<span $url</span>,<span $data</span><span )
{
    </span><span $curl</span> =<span  curl_init();
    curl_setopt(</span><span $curl</span>, CURLOPT_URL, <span $url</span><span ); 
    curl_setopt(</span><span $curl</span>, CURLOPT_SSL_VERIFYPEER, <span FALSE</span><span );
    curl_setopt(</span><span $curl</span>, CURLOPT_SSL_VERIFYHOST, <span FALSE</span><span );
    curl_setopt(</span><span $curl</span>, CURLOPT_POST, 1<span );
    curl_setopt(</span><span $curl</span>, CURLOPT_POSTFIELDS, <span $data</span><span );
    curl_setopt(</span><span $curl</span>, CURLOPT_RETURNTRANSFER, 1<span );
    </span><span $result</span> = curl_exec(<span $curl</span><span );
    </span><span if</span> (curl_errno(<span $curl</span><span )) {
       </span><span return</span> 'Errno'.curl_error(<span $curl</span><span );
    }
    curl_close(</span><span $curl</span><span );
    </span><span return</span> <span $result</span><span ;
}</span>

返回

<span string</span>(36) "{"group":{"id":100,"name":"朋友"}}"

效果

 

<br /><br /><br />

============================================

方倍工作室微信公众平台账号关注方法:
1. 微信通讯录-添加朋友-查找公众号-搜索“方倍工作室”
2. 微信通讯录-添加朋友-搜号码-输入“pondbaystudio”
3. 使用微信扫描下面的二维码

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn