首页 » 微信公众平台开发:从零基础到ThinkPHP5高性能框架实践 » 微信公众平台开发:从零基础到ThinkPHP5高性能框架实践全文在线阅读

《微信公众平台开发:从零基础到ThinkPHP5高性能框架实践》6.4.1 获取用户列表

关灯直达底部

接口调用请求的说明如下。


https:// api.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&next_openid=NEXT_OPENID  

上述接口的参数说明如表6-11所示。

表6-11 获取用户列表请求的参数说明

构造请求列表如下。


https:// api.weixin.qq.com/cgi-bin/user/get?access_token=5ic8RoqZd7IBUtE0aGXUhcdKBnrwlO1iqtvyJJUgIcDcopJIH7x90QH4yiK_z08fqp4WOD7kfKPDtET29BRYNZO-sSIITaxIj4u72LYAYcFH6t1fiSVzjUuqYWOtHiw0LGDorxx5Qj6SN0Z7GtYGTA  

获取用户列表的代码实现如下。


 1 <?php 2 $access_token = "Ti2h3ujhxdCYlHZKfhNEyUFFTmGTTCYISHz8QyJnPvI29IhfFrd53Xl6_jw3Y       i3xAVNv_TSR9mfkhrBV-nm7WZa-NA2p3v_cp0B3dRTLmbCOSwhMcFArrISEcxUGBVw_XFHhAAAQYA"; 3  4 $url = "https:// api.weixin.qq.com/cgi-bin/user/get?access_token=$access_token"; 5 $result = https_request($url); 6 var_dump($result); 7  8 function https_request($url, $data = null) 9 {10     $curl = curl_init;11     curl_setopt($curl, CURLOPT_URL, $url);12     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);13     curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);14     if (!empty($data)){15         curl_setopt($curl, CURLOPT_POST, 1);16         curl_setopt($curl, CURLOPT_POSTFIELDS, $data);17     }18     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);19     $output = curl_exec($curl);20     curl_close($curl);21     return $output;22 }23 ?>  

代码执行后,返回的结果如下。


{    "total":5701,    "count":5701,    "data":{        "openid":[            "oiPuduD1wqM1DfT8bEMcvm5AS94M",            "oiPuduOCz49SfENckHW-3HhzSVMc",            "oiPuduNiFBwG-YKkBe4mIYIRausw",            "oiPuduB-nmupLByqdsgC6zXoGX5k",            "oiPuduNCi7NFlhVnyjgK403DJgug",            "oiPuduLG154WOgpWWB20RiTORnx0"        ]    },    "next_openid":"oiPuduLG154WOgpWWB20RiTORnx0"}  

返回结果的参数说明如表6-12所示。

表6-12 获取用户列表结果的参数说明