PHP 获取小程序openID

$appid = '';
$secret = $this->app;
$code = $_REQUEST["code"];
$url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' . $appid . '&secret=' . $secret . '&js_code=' . $code . '&grant_type=authorization_code';

$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 500);
// To ensure communication security,all api use https,so need use two line code to open ssl safety check
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_URL, $url);

$res = curl_exec($curl);
curl_close($curl);

$json_obj = json_decode($res, true);
$openid = $json_obj["openid"];
$data['openid'] = $openid;
return json_encode($data);