微信用户昵称乱码解决



1、openidusers.php

<?php
		set_time_limit(600); 
		header("Content-type: text/html; charset=utf-8"); 
		session_start();
        $opts = array(
            'http'=>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

<?php
		header("Content-type: text/html; charset=utf-8"); 
        session_start();
		$link=mysql_connect("localhost","root","") or die('连接数据库失败!');
		$db_selected = mysql_select_db('vshop', $link);
		mysql_query("set names utf8;"); 
		$query = 'select openid from wp_follow';
		$result = mysql_query($query);
		while($row = mysql_fetch_array($result)){
			$openidlist[]=$row['openid'];
		}
		$userlist=$_SESSION['userllist'];
		$token = "gh_4df8efbb2caf";	
		foreach($userlist as $k=>$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、

<?php
		header("Content-type: text/html; charset=utf-8"); 
		$link=mysql_connect("127.0.0.1","root","") or die('连接数据库失败!');
		$db_selected = mysql_select_db('vshop', $link);
		mysql_query("set names utf8;"); 
		$query = 'select * from wp_follow';
		$result = mysql_query($query);
		while($row = mysql_fetch_array($result)){
			$openidlist[]=hex2bin($row['nickname']);
		}
		var_dump($openidlist);
?>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值