365体育备用网址报道15.2.1猎取门店ID列表_365体育备用网址官网资讯

微信门店接口在其余多个业务场景中都需要用到,比如微信卡券、微信连WiFi等。在这些业务场景中,需要确定使用业务的门店有哪些,因此,事先猎取门店列表并保留下来有助于后续业务的开拓。
微信门店的PHP SDK实世爵国际娱乐码如下。

 1 class class_wxpoint
 2 {
 3     var $appid = APPID;
 4     var $appsecret = APPSECRET;
 5 
 6     //构造函数,猎取Access Token
 7     public function __construct($appid = NULL, $appsecret = NULL)
 8     {
 9         if($appid && $appsecret){
10             $this->appid = $appid;
11             $this->appsecret = $appsecret;
12         }
13         $res = file_get_contents('token.json');
14         $result = json_decode($res, true);
15         $this->expires_time = $result["expires_time"];
16         $this->access_token = $result["access_token"];
17 
18         if (time() > ($this->expires_time + 3600)){
19             $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$this->appid."&secret=".$this->appsecret;
20             $res = $this->http_request($url);
21             $result = json_decode($res, true);
22             $this->access_token = $result["access_token"];
23             $this->expires_time = time();
24             file_put_contents('token.json', '{"access_token": "'.$this->access_token.'", "expires_time": '.$this->expires_time.'}');
25         }
26     }
27 
28     //查询门店列表
29     public function get_poi_list($begin = 0, $limit = 20)
30     {
31         $msg = array('begin' => $begin, 'limit' => $limit);
32         $url = "https://api.weixin.qq.com/cgi-bin/poi/getpoilist?access_token=".$this->access_token;
33         $res = $this->http_request($url, urldecode(json_encode($msg)));
34         return json_decode($res, true);
35     }
36 
37     //HTTP要求(撑腰HTTP/HTTPS,撑腰GET/POST)
38     protected function http_request($url, $data = null)
39     {
40         $curl = curl_init();
41         curl_setopt($curl, CURLOPT_URL, $url);
42         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
43         curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
44         if (!empty($data)){
45             curl_setopt($curl, CURLOPT_POST, 1);
46             curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
47         }
48         curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
49         $output = curl_exec($curl);
50         curl_close($curl);
51         return $output;
52     }
53 }

调用猎取门店ID列表实世爵国际娱乐码如下:

define('APPID',        "wxfd3fd09f8b7c8f84");
define('APPSECRET',   "b45c1dd5152b35cfb3c7c70514decd04");

$weixin = new class_wxpoint();
$result = $weixin->get_poi_list();
var_dump($result);

上述程序执行后结果和本章15.1.4节的结果一致。

------分隔线----------------------------

公布评论 (53人察看0条评论)
请自觉遵守互联网相关的政策法规,严禁公布色情、暴力、反动的言论。
用户名: 验证码: 点击我更换皇浦国际娱乐
最新评论