1 /**获取用户openid:post**/
2 function getUserOpenid(){
3 $appid = "wx************fd";
4 $secret = "64d**********************55";
5 $grant_type = "authorization_code";
6
7 //获取微信小程序传过来的code
8 $js_code = $this->request->param("code");
9 $curl = curl_init();
10 //使用curl_setopt() 设置要获得url地址
11 $url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' . $appid . '&secret=' . $secret . '&js_code=' . $js_code . '&grant_type=' . $grant_type;
12 curl_setopt($curl, CURLOPT_URL, $url);
13
14 //设置是否输出header
15 curl_setopt($curl, CURLOPT_HEADER, false);
16
17 //设置是否输出结果
18 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
19
20 //设置是否检查服务器端的证书
21 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
22
23 //使用curl_exec()将curl返回的结果转换成正常数据并保存到一个变量中
24 $data = curl_exec($curl);
25
26 //关闭会话
27 curl_close($curl);
28 $this->success('返回成功', $data);
29 //print_r($data);
30 }