ThinkSNS-应用开发范例-增加发通知功能

来自站长百科
跳转至: 导航、​ 搜索

导航: 上一页

和发动态一样,发通知也需要增加礼品的通知模板和在在发送礼品成功后增加发送通知功能:

Thinksns052402.jpg

在发送礼品成功后增加以下程序:

//给接收人发送通知
$this->__doNotify($toUser,$sendInfo,$giftInfo,$fromUid,$appId);
__doNotify 方法如下:
/**
* __doNotify
* 发送系统通知
* @param $sendInfo 附加信息$giftInfo 礼品信息$toUser 发送对象
ID
* @return $feedId 插入结果;
*/
private function __doNotify($toUser,$sendInfo,$giftInfo,$fromUid,$appId){
//根据赠送方式组装数据
foreach ($toUser as $uid){
switch ($sendInfo['sendWay']){
case 1: //公开
$user = $this->api->user_getInfo($fromUid,'name');
$title['user'] = $user['name'];
//<a
href="{WR}/apps/gift/index.php?s=/Index/index/uid/10203">给张峰回赠礼物</a>
$sendback = '<br/><a
href=\"{WR}/apps/gift/index.php?s=/Index/index/uid/'。$fromUid。'\">给'。
$user['name']。'回赠礼物</a>';
break;
case 2: //私下
$user = $this->api->user_getInfo($fromUid,'name');
$title['user'] = $user['name'];
$sendback = '<br/><a
href=\"{WR}/apps/gift/index.php?s=/Index/index/uid/'。$fromUid。'\">给'。
$user['name']。'回赠礼物</a>';
break;
case 3: //匿名
$title['user'] = '神秘人物';
$this->api->notify_setAnonymous();
$sendback = '';
break;
default:
continue;
}
//礼品图片
$body['img'] = $this->__realityImage($giftInfo);
//附加消息,用文本过滤t 函数过滤危险代码
$body['content'] = t($sendInfo['sendInfo'])。$sendback;
//组装通知里的‘去看看’的网址
$url =
'{WR}/apps/gift/index.php?s=/Index/receivebox';
//通过API 增加通知到数据库
$this->api->notify_setAppId($appid);
$notify = $this->api-
>notify_send( $uid,"gift_send",$title,$body,$url);
}
}

参考资料[ ]