获取openid

小程序获取openid:
获取openid_第1张图片
后台(thinkphp):
//获取openid
public function queryId(Request $request ){
$code = $request ->param( 'code' );
$appid = 'wxc23a104cb7d25068' ;
$appsecret = 'ac8843b11a13ee1eb1359634f88eb037' ;
$url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' . $appid . '&secret=' . $appsecret . '&js_code=' . $code . '&grant_type=authorization_code' ;

function getcurl( $url ){
$ch = curl_init ();
curl_setopt ( $ch , CURLOPT_URL , $url );
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 );
curl_setopt ( $ch , CURLOPT_TIMEOUT , 30 );
curl_setopt ( $ch , CURLOPT_SSL_VERIFYPEER , false ); //不验证证书下同
curl_setopt ( $ch , CURLOPT_SSL_VERIFYHOST , false ); //
$content = curl_exec ( $ch );
curl_close ( $ch );
echo $content ;
return $content ;
}
getcurl( $url );
}
获取openid_第2张图片

你可能感兴趣的:(获取openid)