微擎函数之fansQueryInfo获取粉丝基本信息(包括UnionID机制)

微擎函数fansQueryInfo用于获取粉丝基本信息,其中UnionID机制可参考微信官方文档:https://developers.weixin.qq.com/doc/offiaccount/User_Management/Get_users_basic_information_UnionID.html#UinonId

函数说明

函数调用方法

fansQueryInfo($openid)

函数参数

$openid 粉丝 openid

函数返回值

有如下几种返回值,一一讲解

1、error

'error'字符串 或 error()结构的错误;

2、success

$return = array(
   "subscribe": 1, //用户是否订阅该公众号标识,值为0时,代表此用户没有关注该公众号,拉取不到其余信息。
    "openid": "o6_bmjrPTlm6_2sgVt7hMZOPfL2M", //用户的标识,对当前公众号唯一
    "nickname": "Band", //用户的昵称
    "sex": 1, //用户的性别,值为1时是男性,值为2时是女性,值为0时是未知
    "language": "zh_CN", //用户的语言,简体中文为zh_CN
    "city": "广州", //用户所在城市
    "province": "广东", //用户所在省份
    "country": "中国", //用户所在国家
    "headimgurl":"http://wx.qlogo.cn/mmopen/g3MonUZtNHkdmzicIlibx6iaFqAc56vxLSUfpb6n5WKSYVY0ChQKkiaJSgQ1dZuTOgvLLrhJbERQQ4eMsv84eavHiaiceqxibJxCfHe/0", //用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空。若用户更换头像,原有头像URL将失效
    "subscribe_time": 1382694957,//用户关注时间,为时间戳。如果用户曾多次关注,则取最后关注时间
    "unionid": " o6_bmasdasdsad6_2sgVt7hMZOPfL"//只有在用户将公众号绑定到微信开放平台帐号后,才会出现该字段。
    "remark": "",//公众号运营者对粉丝的备注,公众号运营者可在微信公众平台用户管理界面对粉丝添加备注
    "groupid": 0,//用户所在的分组ID(兼容旧的用户分组接口)
    "tagid_list":[128,2]//用户被打上的标签ID列表
);

调用示例

$account_api = WeAccount::create();
$fans_info = $account_api->fansQueryInfo('o6_bmjrPTlm6_2sgVt7hMZOPfL2M');

或者读取列表

$account_api = WeAccount::createByUniacid();
$wechat_fans_list = $account_api->fansAll();
$wechat_fans = array_slice($wechat_fans_list['fans'], $i * 500, 500);

foreach( $wechat_fans as $openid ){
	$userinfo[] = $account_api->fansQueryInfo($openid);
}
print_r($userinfo);

后者输出示例

Array
(
    [0] => Array
        (
            [subscribe] => 1
            [openid] => ABCDEFGCeOnaxBH3K0KYAC6m0Qek
            [nickname] => YangJunwei
            [sex] => 1
            [language] => zh_CN
            [city] => 郑州
            [province] => 河南
            [country] => 中国
            [headimgurl] => https://thirdwx.qlogo.cn/mmopen/aaaaaaaaaaaa/132
            [subscribe_time] => 1571003287
            [groupid] => 100
            [tagid_list] => Array
                (
                    [0] => 100
                )

        )

    [1] => Array
        (
            [subscribe] => 1
            [openid] => ABCDEFGlPN8AYMS-HhU2Fywj5vXg
            [nickname] => 老杨
            [sex] => 0
            [language] => zh_CN
            [city] => 
            [province] => 
            [country] => 
            [headimgurl] => https://thirdwx.qlogo.cn/mmopen/aaaaaaaaa/132
            [subscribe_time] => 1578008334
            [groupid] => 0
            [tagid_list] => Array
                (
                )

        )

    [2] => Array
        (
            [subscribe] => 1
            [openid] => ABCDEFGcumAnSm8SFle7nX7GwooA
            [nickname] => 测试
            [sex] => 0
            [language] => zh_CN
            [city] => 
            [province] => 
            [country] => 
            [headimgurl] => https://thirdwx.qlogo.cn/mmopen/aaaaaaaaaaaaa/132
            [subscribe_time] => 1577000413
            [groupid] => 0
            [tagid_list] => Array
                (
                )
        )

    …………

)

参与评论