码迷,mamicode.com
首页 > 微信 > 详细

微信小程序获取openid

时间:2019-08-19 19:25:53      阅读:98      评论:0      收藏:0      [点我收藏+]

标签:decode   微信小程序   close   nsf   result   http   head   utf-8   lis   

public function indexAction(){
$appid = ‘wx3d2dd6b811128‘;
$appsecret = ‘3707622221affc0f3dsffs30823770‘;
$wxcode =$_POST[‘code‘];
$cont = $this->curlGet(‘https://api.weixin.qq.com/sns/jscode2session?appid=‘.$appid.‘&secret=‘.$appsecret.‘&js_code=‘.$wxcode.‘&grant_type=authorization_code‘);
if(empty($cont)) return ‘‘;
  $sessonkeyid=json_decode($cont,true);
  $list=array(‘code‘ => 0 , ‘msg‘ => ‘登录成功‘,‘data‘ => $sessonkeyid);
exit(json_encode($rtn));
}

 

public function curlGet($url){
$ch = curl_init();
$header = array("Accept-Charset:utf-8");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//获得内容
$result = curl_exec($ch);
//关闭curl
curl_close($ch);
return $result;
}

 

 

获取openid 微信小程序

微信小程序获取openid

标签:decode   微信小程序   close   nsf   result   http   head   utf-8   lis   

原文地址:https://www.cnblogs.com/qgzr/p/11378781.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!