程序开发-方法接口 CMS3


一.临时缓存

后台更新缓存之后将被删除掉

存储方法

$this->set_cache_data("缓存名称", $data, 有效期秒);

读取方法

$this->get_cache_data("缓存名称");


二.金钱增加/减少

为用户uid888充值999元

$this->load->model('pay_model');
$this->pay_model->add(888, 999, "充值原因");

为用户uid888减少999元

$this->load->model('pay_model');
$this->pay_model->add(888, -999, "扣钱的原因");


三.经验值增加

为用户uid33增加999经验值

$this->member_model->update_score(0, 333, 999, '', '自定义增加');

第一个参数:固定值0
第二个参数:用户的uid号
第三个参数:变动值必须正数
第四个参数:留空
第五个参数:备注信息,说明原因


四.充值虚拟币

1、为用户uid33充值999虚拟币

$this->member_model->update_score(1, 333, 999, '', '自定义增加');

第一个参数:固定值1
第二个参数:用户的uid号
第三个参数:变动值,增加为正数、减少为负数
第四个参数:留空
第五个参数:备注信息,说明原因

2、为用户uid33减少888虚拟币

$this->member_model->update_score(1, 333, -888, '', '自定义减少');

第一个参数:固定值1
第二个参数:用户的uid号
第三个参数:变动值,增加为正数、减少为负数
第四个参数:留空
第五个参数:备注信息,说明原因


五.会员登录方法

1.调用方式

$this->member_model->login($username, $password, $expire, $back)

2.参数值

参数
介绍
$username
会员账号
$password
明文密码
$expire
有效期时间,判断登录时可以设置为1
$back是否返回登录会员信息

3.返回值

    * array        登录成功

     * int -1会员不存在

     * int -2密码不正确

     * int      -3Ucenter注册失败

     * int      -4Ucenter:会员名称不合法

4.相关例子

$r = $this->member_model->login('admin', 'admin', 1, 1);
if (is_array($r)) {
    // 登录成功
} else {
    // 登录失败
}


六.会员注册方法

1.调用方式

$this->member_model->register($data, $groupid)

2.参数值

参数
介绍
$data
array('username' => 会员账号, 'password' => 明文密码, 'email' => 邮箱)
$groupid
会员组id

3.返回值

     * int 数字  注册成功

     * int -1         会员名称已经存在

     * int -2         Email格式有误

     * int -3         Email已经被注册

     * int -4         同一IP注册限制

     * int -5         Ucenter 会员名不合法

     * int -6         Ucenter 包含不允许注册的词语

     * int -7 Ucenter Email 格式有误

     * int -8 Ucenter Email 不允许注册

     * int -9 Ucenter Email 已经被注册 

4.开发示例

注册一个正式会员

$r = $this->member_model->register(array(
    'username' => 'admin',
    'password' => 'admin',
    'email' => 'admin@admin.com'
), 3);
if ($r > 0) {
    // 注册成功
} else {
    // 注册失败
}


七.同步新浪微博

1.调用方式

$this->cron_model->add(4,  array(数组参数值))

2.参数值

参数
介绍
$uid
会员id
$url
分享的地址
$thumb
分享的图片地址
$title分享的内容信息

3.返回值

无返回值

此方法会将数据加入到消息发送队列之中

4.开发示例

分享一条信息到微博

$this->cron_model->add(4,  array(
    'uid' => 1,
    'url' => 'http://www.tianruiyun.com/',
    'thumb' => 'http://www.dayrui.net/static/image/common/logo.png',
    'title' => '这是一条分享信息',
));


八.关注Ta

1.调用方式

$this->load->model('sns_model'); //引用时需要加载sns模型类,只加载一次即可
$this->sns_model->following($ta_uid, $my_uid);

2.参数值

参数
介绍
$ta_uid关注Ta的uid
$my_uid我的Uid

3.返回值

 0    关注失败

 1    关注成功

 2    相互关注

-1    取消关注

4.开发示例

a.通过类方法的方式来关注

// 
....
public function guanzhu($ta_uid, $my_uid) {
    $this->load->model('sns_model');
    $rt = $this->sns_model->following($ta_uid, $my_uid);
    if ($rt == 1) {
        return '关注成功';
    } elseif ($rt == 2) {
        return '相互关注';
    } elseif ($rt == -1) {
        return '取消关注';
    } else {
        return '关注失败';
    }
}
......

b.通过url方式来关注

创建文件/member/controllers/guanzhu.php

 
class Guanzhu extends M_Controller {
    
    public function __construct() {
        parent::__construct();
    }
    
    public function index() {
        $ta_uid = $this->input->get('uid');
        if (!$this->uid) {
            $this->member_msg('您尚未登录,无法关注对方');
        }
        $this->load->model('sns_model');
        $rt = $this->sns_model->following($ta_uid, $this->uid);
        if ($rt == 1) {
            $this->member_msg('关注成功', '', 1);
        } elseif ($rt == 2) {
            $this->member_msg('相互关注', '', 1);
        } elseif ($rt == -1) {
            $this->member_msg('取消关注', '', 1);
        } else {
            $this->member_msg('关注失败');
        }
    }
}

关注链接为:{MEMBER_URL}index.php?c=guanzhu&uid={关注对象的uid}


九.发布动态(微博)

1.调用方式

$this->member_model->add_sns($uid, $content, $attach, $source = 0, $repost = 0)

2.参数值

参数
介绍
$uid
会员id
$contnet
动态/微博内容
$attach
附件,多个附件以|分隔
$source来源名称
$repost转发id

3.返回值

FLASE:失败

TRUE:成功

4.开发示例

$this->member_model->add_sns(1, '这是一条系统通知内容', 0);//给会员id=1的发送一条动态


十.发送邮件

1.调用方式

$this->sendmail_queue($tomail, $subject, $message)

2.参数值

参数
介绍
$tomail
邮件接收者
$subject
邮件标题
$message
邮件内容

3.返回值

TRUE/FALSE

4.开发示例

$thi->sendmail_queue('admin@cndo.org', '邮件标题---', '这是邮件的内容');
// 添加到邮件队列中
// 此方法不会实时发送


十一.发送手机短信

1.调用方式

$this->member_model->sendsms($mobile, $content)

2.参数值

参数
介绍
$mobile短信号码,多个号码,分隔,不得超过40个
$content内容不得超过40个字

3.返回值

①、返回false时,发送失败
②、发送失败时返回数组格式:array('status' => 0, 'msg' => '错误说明文字')
③、发送成功时返回数组格式:array('status' => 1, 'msg' => '发送成功')

4.开发示例

$mobile = '139999999,138999999,1339999999';
$content = '短信内容';//系统自动会加后缀签名
$result = $this->member_model->sendsms($mobile, $content);
if ($result === FALSE) {
    echo '发送失败';
} elseif ($result['status'] == 1) {
    echo '发送成功:'.$result['msg'];
} elseif ($result['status'] == 0) {
    echo '发送失败:'.$result['msg'];
}


十二.发送通知

1.调用方式

$this->member_model->add_notice($uid, $type, $note)

2.参数值

参数
介绍
$uid
会员id
$type
通知类型:1系统,2互动,3模块,4应用
$note
通知内容

3.返回值

NULL

4.开发示例

$this->member_model->add_notice(1, 1, '这是一条系统通知内容');//给会员id=1的会员发送一条系统通知


签名:这个人很懒,什么也没有留下!
最新回复 (0)
返回