微信小程序获取openid

时间:2019-08-19 19:25:53   收藏:0   阅读:98

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 微信小程序

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!