因为有些微信用户的昵称是带表情符号的,受权存用户昵称的时候因为数据库类型问题存不进去,改了数据库类型也不行,因此就找了一些过滤方法, 亲测有效:数据库
注册接口json
public function register(Request $request){微信
$avatar = $request->input("userimage");this
$nickname_new = $request->input("username");code
$weixin_openid = $request->input("openid");接口
$nickname = $this->filter($nickname_new);//过滤后的用户昵称 以后直接判断用户是否受权而后储存数据库就行input
}io
过滤接口function
/**request
* $str 微信昵称
**/
public function filter($str) {
if($str){
$name = $str;
$name = preg_replace('/\xEE[\x80-\xBF][\x80-\xBF]|\xEF[\x81-\x83][\x80-\xBF]/', '', $name);
$name = preg_replace('/xE0[x80-x9F][x80-xBF]‘.‘|xED[xA0-xBF][x80-xBF]/S','?', $name);
$return = json_decode(preg_replace("#(\\\ud[0-9a-f]{3})#","",json_encode($name)));
}else{
$return = '';
}
return $return;
}
而后问题就解决了。