通过 openid 获取个人信息

//  通过 openid 获取用户信息   返回数组

function getUserInfo( $openid){
    
     $access_token = accessToken();       //  accessToken 函数   http://www.cnblogs.com/thinkxmg/p/4667331.html

     if( is_array( $openid)){
        
         $arr =  array();

         foreach( $openid  as  $key=> $val){
            
             $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token= $access_token&openid= $val&lang=zh_CN";

             $ch = curl_init();

            curl_setopt( $ch, CURLOPT_URL,  $url);

            curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER,  FALSE); 

            curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST,  FALSE); 

            curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);

             $output = curl_exec( $ch);

            curl_close( $ch);

             $arr[] = json_decode( $outputtrue);

        }

         $jsoninfo =  $arr;

    } else{
        
             $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token= $access_token&openid= $openid&lang=zh_CN";

             $ch = curl_init();

            curl_setopt( $ch, CURLOPT_URL,  $url);

            curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER,  FALSE); 

            curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST,  FALSE); 

            curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);

             $output = curl_exec( $ch);

            curl_close( $ch);

             $jsoninfo = json_decode( $outputtrue);

    }

     return  $jsoninfo;

}

你可能感兴趣的:(open)