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

微信小程序获取openid

上一篇:程序员的专属微信公众号编辑器:定制 Markdown 转 HTML


下一篇:使用charls抓包微信小程序的解决方案(终极解决,各种坑不怕,亲测可用,不服来战!)