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