修改方法:
3.修改/Application/Common/Model/FollowModel.class.php
5.进入前台,基础插件-微信用户中心-拉取10000个已有粉丝,搞定
1.下载附件覆盖插件UserCenter(附件会替换所有文件,有做过修改的记得备份修改)
链接: http://pan.baidu.com/s/1ntHYaoD 密码: ysl1
2.修改/Application/Common/Common/function.php找到
/**
* 短链接功能
*
* @param float $long_url
* 长链接
* @return string 如果没有微信短链接接口权限或者不成功,就原样返回长链接,否则返回短链接
*/
function short_url($long_url)
在这段代码之上增加以下代码
//处理头像
function get_name_by_touxiang($val) {
if(!empty($val)){
return('<img height="48px" src="'.$val.'" />');
}else{
return('<img height="48px" src="'.ADDON_PUBLIC_PATH.'/face.png" />');
}
}
// 拉取10000个用户列表,通过openid获取微信用户基本信息,此功能只有认证的服务号才能用
function getWeixinUserAllInfo($token) {
$access_token = get_access_token ( $token );
if (empty ( $access_token )) {
return false;
}
$param ['access_token'] = $access_token;
$url = 'https://api.weixin.qq.com/cgi-bin/user/get?'. http_build_query ( $param );
$content = file_get_contents ( $url );
$content = json_decode ( $content, true );
return $content;
}
3.修改/Application/Common/Model/FollowModel.class.php
<?php
namespace Common\Model;
use Think\Model;
use User\Api\UserApi;
/**
* 粉丝操作
*/
class FollowModel extends Model {
function init_follow($openid) {
if (empty ( $openid ) || $openid == - 1)
return false;
$data ['token'] = get_token ();
$data ['openid'] = $openid;
$winfo = getWeixinUserInfo ($openid, $data ['token']); //获取用户所有信息
$info = $this->where ( $data )->find ();
if ($info) {
$save ['subscribe_time'] = $winfo ['subscribe_time'];
$save ['nickname'] = $winfo ['nickname'];
$save ['sex'] = $winfo ['sex'];
$save ['city'] = $winfo ['city'];
$save ['province'] = $winfo ['province'];
$save ['country'] = $winfo ['country'];
$save ['headimgurl'] = $winfo ['headimgurl'];
$res = $this->where ( $data )->save ( $save );
} else {
// $data ['subscribe_time'] = time ();
// $uid = $this->get_uid_by_ucenter ( $data ['openid'], $data ['token'] );
//if ($uid > 0) {
// $data ['id'] = $uid;
$data ['subscribe_time'] = $winfo ['subscribe_time'];
$data ['nickname'] = $winfo ['nickname'];
$data ['sex'] = $winfo ['sex'];
$data ['city'] = $winfo ['city'];
$data ['province'] = $winfo ['province'];
$data ['country'] = $winfo ['country'];
$data ['headimgurl'] = $winfo ['headimgurl'];
$res = $this->add ( $data );
//}
$info = $data;
}
return $info;
}
//处理头像
function get_name_by_touxiang($val) {
if(!empty($val)){
return('<img height="48px" src="'.$val.'" />');
}else{
return('<img height="48px" src="'.ADDON_PUBLIC_PATH.'/face.png" />');
}
}
// 自动初始化微信用户
function get_uid_by_ucenter($openid, $token) {
static $_email_int = 0;
$info ['openid'] = $openid;
$info ['token'] = $token;
$res = M ( 'ucenter_member' )->where ( $info )->find ();
if ($res)
return $res ['id'];
$email = time () . rand ( 01, 99 ) . $_email_int . '@weiphp.cn';
$nickname = uniqid () . rand ( 01, 99 ) . $_email_int;
/* 调用注册接口注册用户 */
$User = new UserApi ();
$uid = $User->register ( $nickname, '123456', $email, '', $openid, $token );
$_email_int += 1;
return $uid;
}
/**
* 获取粉丝全部信息
*/
public function getFollowInfo($id) {
static $_followInfo;
if (isset ( $_followInfo [$id] )) {
return $_followInfo [$id];
}
$_followInfo [$id] = $this->find ( $id );
return $_followInfo [$id];
}
}
?>
4.进入后台,模型管理-粉丝管理-编辑,把列表定义改成:
id:粉丝编号
openid:OpenId
headimgurl|get_name_by_touxiang:头像
nickname:昵称
sex|get_name_by_status:性别
province:省份
city:城市
subscribe_time|time_format:关注时间
ids:操作:[EDIT]|编辑
5.进入前台,基础插件-微信用户中心-拉取10000个已有粉丝,搞定