微信用户昵称乱码解决



1、openidusers.php

array(
			
                'method'=>"GET",
                'timeout'=>1000,
				
            )
        );

        $context = stream_context_create($opts);
        $gettoken=file_get_contents("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx6c7xxxxxbddd4&secret=8ab524xxxcc4f6f4ac8617093", false, $context);
        $res=json_decode($gettoken,true);
        $token=$res["access_token"];
		$_SESSION["token"]=$token;
        $getopenid=file_get_contents("https://api.weixin.qq.com/cgi-bin/user/get?access_token={$token}&next_openid=", false, $context);
        $res2=json_decode($getopenid,true);
		$openid=$res2['data']['openid'];
        foreach($openid as $k=>$v){
            $getuser=file_get_contents("https://api.weixin.qq.com/cgi-bin/user/info?access_token={$token}&openid={$v}", false, $context);
            $user=json_decode($getuser,true);
            $userlist[]=$user;
        }
		
		$_SESSION["userllist"]=$userlist;
		var_dump($userlist);
		
		
		
		

2、upd.php

$v){
			if(in_array($v["openid"],$openidlist)){
				@$v['nickname']=bin2hex($v['nickname']);
				@$sql="update wp_follow set nickname='".$v['nickname']."',sex='".$v['sex']."',city='".$v['city']."',province='".$v['province']."',country='".$v['country']."',language='".$v['language']."',headimgurl='".$v['headimgurl']."',mTime='".time()."' where openid='".$v['openid']."'";
				mysql_query($sql);
			}else{
				@$v['nickname']=bin2hex($v['nickname']);
				@$sql2='insert into wp_follow(token,openid,nickname,sex,city,province,country,language,headimgurl,subscribe_time) values("'.$token.'","'.$v['openid'].'","'.$v['nickname'].'","'.$v['sex'].'","'.$v['city'].'","'.$v['province'].'","'.$v['country'].'","'.$v['language'].'","'.$v['headimgurl'].'","'.$v['subscribe_time'].'")';
				mysql_query($sql2);
			}
		}
		
		

3、



你可能感兴趣的:(微信)