·设为首页收藏本站📧邮箱修改🎁免费下载专区🔐设置/修改密码👽群雄群聊
返回列表 发布新帖

通过掌上论坛的回帖不触发钩子函数

210 1
发表于 2022-2-5 14:32:48 | 显示全部楼层 阅读模式

马上注册,免费下载更多dz插件网资源。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
我写了一个很简单的钩子函数
  1. <?phpif (!defined('IN_DISCUZ')) {    exit('Access Denied');}function sendPostRequest($url,$jsonData){    $curl = curl_init($url);    curl_setopt($curl, CURLOPT_HEADER, false);    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);    curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json"));    curl_setopt($curl, CURLOPT_POST, true);    curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($jsonData));    // set a very low timeout to avoid blocking    curl_exec($curl);    curl_close($curl);}class plugin_dhpush {}class plugin_dhpush_forum extends plugin_dhpush{    function __construct()    { //全局函数定义        global $_G;        $config = $_G['cache']['plugin']['dhpush'];        $this->groupid = $_G['groupid'];        $this->allowPushGroupIds = unserialize($config["allowPushGroups"]);        $this->pushToken = $config["pushToken"];    }    function post_reply_output($params)    {        global $_G;        $DEBUG = true;        $SEND_URL_PREFIX = "https://dhpushservice.kidozh.com/";        $SEND_URL_PATH = "v1/push/reply/";        if ($DEBUG) {            $SEND_URL_PREFIX = "http://localhost:8888/";        }        $SEND_URL = $SEND_URL_PREFIX.$SEND_URL_PATH;        error_log(print_r($params, TRUE));        // check with post reply succeed        if ($params["message"] != "post_reply_succeed") {            return;        }        $fid = $params['values']['fid'];        $tid = $params['values']['tid'];        $pid = $params['values']['pid'];        $mForumPost = C::t("forum_post");        $post = $mForumPost->fetch($tid, $pid);        $senderUid = $post["authorid"];        $senderName = $post["author"];        $replyMessage = $post["message"];        $mForumThread = C::t('forum_thread');        $thread = $mForumThread->fetch($tid);        //主题作者ID        $authorId = $thread['authorid'];        $userResult = DB::fetch_first("SELECT groupid FROM " . DB::table("common_member") . " WHERE uid=" . $authorId);        $receiverGroupId = $userResult["groupid"];        //判断作者是否开启回贴通知        //$mForumPostNotice = C::t('#post_notice#forum_post_notice');        //$isNotice = $mForumPostNotice->getNoticeState($authorId);        // allow notify        if (true) {            $mCommonMember = C::t('common_member');            $author = $mCommonMember->fetch($authorId);//            $email = $author['email'];            $title = $senderName . '回复了帖子' . $thread["subject"];            $siteURL = $_G["siteurl"];            // check whether group id is not null and in the allowed group            if ($receiverGroupId && in_array($receiverGroupId, $this->allowPushGroupIds)) {                // look in the table whether the user in the push database                $pushInfo = DB::fetch_first("SELECT uid, token, allowPush FROM " . DB::table("dhpush_token") . " WHERE uid=" . $authorId);                // start to push the information to device via firebase                $token = $pushInfo["token"];                $deviceToken = $token;                $data = [                    // belong to a reply                    "site_url" => $siteURL,                    "type" => "thread_reply",                    "sender_name" => $senderName,                    "sender_id" => $senderUid,                    "message" => $replyMessage,                    "title" => $title,                    "tid" => $tid,                    "pid" => $pid,                    "fid" => $fid,                    "tokenList"=> $deviceToken                ];                $SEND_URL_WITH_PARAMTER = $SEND_URL."?token=".$this->pushToken;                sendPostRequest($SEND_URL_WITH_PARAMTER,$data);                error_log(print_r($data, TRUE));                error_log(print_r($SEND_URL, TRUE));            } else {                // the user are not able to get a push            }        } else {            // not to send a information        }    }}//    function post_message($params)//    {//        return;//        //file_put_contents('php://stderr', print_r($params, TRUE));//        error_log(print_r($params, TRUE));//        global $_G;//        $fid = $params['param'][2]['fid'];//        $tid = $params['param'][2]['tid'];//        $pid = $params['param'][2]['pid'];////        $action=$params['param'][0];//        if($action=='post_newthread_succeed'){//newthread//            //TODO For newthread//        }//        elseif($action=='post_reply_succeed'){//new reply//            return;//            $senderName = $_G["username"];//            $senderUid = $_G["uid"];////            $mForumThread = C::t('forum_thread');//            //$tid = $params['values']['tid'];//            $thread = $mForumThread->fetch($tid);//            //主题作者ID//            $authorId = $thread['authorid'];//            $userResult = DB::fetch_first("SELECT groupid FROM " . DB::table("common_member") . " WHERE uid=" . $authorId);//            $receiverGroupId = $userResult["groupid"];//            //判断作者是否开启回贴通知//            //$mForumPostNotice = C::t('#post_notice#forum_post_notice');//            //$isNotice = $mForumPostNotice->getNoticeState($authorId);//            // allow notify//            if (true) {//                $mCommonMember = C::t('common_member');//                $author = $mCommonMember->fetch($authorId);//                $email = $author['email'];//                $subject = '您的贴子有回复了!';//                $body = $author['username'] . "\n";//                $body .= "您的主题:" . $thread['subject'] . "有回复了!\n";//                $body .= "复制链接查看:" . $_G['siteurl'] . "forum.php?mod=viewthread&tid=" . $tid . "\n";////                $replyMessage = $body;//                // check whether group id is not null and in the allowed group//                if ($receiverGroupId && in_array($receiverGroupId, $this->allowPushGroupIds)) {//                    // look in the table whether the user in the push database//                    $pushInfo = DB::fetch_first("SELECT uid, token, allowPush FROM ".DB::table("dhpush_token")." WHERE uid=" . $authorId);//                    // start to push the information to device via firebase//                    $token = $pushInfo["token"];//                    $deviceToken = $token;//                    $data = [//                        // belong to a reply//                        "type" => "thread_reply",//                        "sender_name" => $author['username'],//                        "sender_id" => $senderUid,//                        "message" => $replyMessage,////                    ];//                    sendPostRequest($SEND_URL,$data);//                    error_log(print_r($data, TRUE));////                } else {//                    // the user are not able to get a push//                }//            }////        }////        if ($params['message'] != 'post_reply_succeed') {//        }////    }
复制代码
这个可以在每次回帖的时候正常的回调,但是我通过掌上论坛API调用的时候却并不触发这个钩子函数,我想问问是什么原因,需要做哪些事情才能让通过掌上论坛API发帖的时间被正确的通过钩子函数回调?
我要说一句 收起回复

评论1

婷姐楼主Lv.8 发表于 2022-2-5 14:33:47 | 显示全部楼层
试试改成 post_message 嵌入点呢?这个嵌入点应该是不依赖前端的,不过 $params["message"] != "post_reply_succeed" 估计得改。
我要说一句 收起回复

回复

 懒得打字嘛,点击右侧快捷回复【查看最新发布】   【应用商城享更多资源】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

投诉/建议联系

discuzaddons@vip.qq.com

未经授权禁止转载,复制和建立镜像,
如有违反,按照公告处理!!!
  • 联系QQ客服
  • 添加微信客服

联系DZ插件网微信客服|最近更新|Archiver|手机版|小黑屋|DZ插件网! ( 鄂ICP备20010621号-1 )|网站地图

您的IP:3.15.25.32,117.68.34.58,GMT+8, 2024-5-8 03:35 , Processed in 0.208589 second(s), 75 queries , Gzip On, Redis On.

Based on Discuz! W1.0 Licensed

© 2001-2024 Discuz! Team.

关灯 在本版发帖
扫一扫添加微信客服
QQ客服返回顶部
快速回复 返回顶部 返回列表