|
|
@@ -53,17 +53,29 @@ class weixin_public
|
|
|
|
|
|
public function getAllInfo($code)
|
|
|
{
|
|
|
- $info = self::getAcessTokenAndOpenId($code);
|
|
|
+ $reader = array();
|
|
|
|
|
|
+ $info = self::getAcessTokenAndOpenId($code);
|
|
|
if (empty($info['access_token']) || empty($info['openid'])) {
|
|
|
- return $info;
|
|
|
+ return $reader;
|
|
|
}
|
|
|
|
|
|
$url = "https://api.weixin.qq.com/sns/userinfo?access_token=".$info['access_token']."&openid=".$info['openid']."&lang=zh_CN";
|
|
|
$jsonInfo = file_get_contents($url);
|
|
|
//$jsonInfo = iconv('ISO-8859-1', 'UTF-8', $jsonInfo);
|
|
|
- $ret = json_decode($jsonInfo, true); //接受一个 JSON 格式的字符串并且把它转换为 PHP 变量
|
|
|
- return $ret;
|
|
|
+ $rs = json_decode($jsonInfo, true); //接受一个 JSON 格式的字符串并且把它转换为 PHP 变量
|
|
|
+
|
|
|
+ $attr['country'] = $rs['country'];
|
|
|
+ $attr['province'] = $rs['province'];
|
|
|
+ $attr['city'] = $rs['city'];
|
|
|
+ $attr['headimgurl'] = $rs['headimgurl'];
|
|
|
+ $attr['openid'] = $rs['openid'];
|
|
|
+ $attr['nickname'] = $rs['nickname'];
|
|
|
+ $attr['sex'] = $rs['sex'];
|
|
|
+ $reader = Reader::getInfoByOpenId($info['openid']);
|
|
|
+ Reader::addOrUpdate($reader['id'], $attr);
|
|
|
+
|
|
|
+ return Reader::getInfoByOpenId($info['openid']);
|
|
|
}
|
|
|
|
|
|
|