• 让禅道也可以玩BearyChat


    简单的理解,BearycChat是一种IM,是一种能聚合各种MS系统消息的东西,是团队协作过程中消息流转的利器。

    我是工具控,所以不折腾不舒服。

    废话不说,上码:

    /path_to_zentao/module/action/ext/model/logHistory.php

    <?php
    
    /**
         * Log histories for an action.
         * 
         * @param  int    $actionID 
         * @param  array  $changes 
         * @access public
         * @return void
         */
        public function logHistory($actionID, $changes)
        {
            foreach($changes as $change) 
            {
                $change['action'] = $actionID;
                $result = $this->dao->insert(TABLE_HISTORY)->data($change)->exec();
    			
    			//bearychat notice
    			$this->notifyBearychat($actionID, $change['new']);
            }
        }
    	
    	protected function notifyBearychat($actionID, $text) {
    		$action = $this->dao->select('*')->from(TABLE_ACTION)
                ->where('id')->eq($actionID)
                ->fetch();
    		
    		$_actions = $this->loadModel('action')->transformActions(array($action));
    		$action = $_actions[0];
    		
    		$title = strip_tags(sprintf("%s, %s <em>%s</em> %s %s %s。", $action->date, $action->actor, $action->actionLabel, $action->objectLabel, $action->objectName, 'http://'.(isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '')) . $action->objectLink));
    		
    		return $this->curlPostPayload2Bearychat($title, $text);//, 'project-' . $action->project . ''
    	}
    	
    	protected function curlPostPayload2Bearychat($title, $text, $channel = 'pms') {
    		
    		$url = 'https://hook.bearychat.com/your_self_params';//简单的定义于此
    		
    		$str = array('payload' => json_encode(array('text' => $title, 'markdown' => true, 'channel' => $channel, 'attachments' => array(array('text' => strip_tags($text))))));//
    		$ch = curl_init();
    		curl_setopt($ch, CURLOPT_URL, $url);
    		curl_setopt($ch, CURLOPT_POST, 1);
    		curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
    		
    		if (substr($url, 0, 8) == "https://")
    		{
    			$opt[CURLOPT_SSL_VERIFYHOST] = 1;
    			$opt[CURLOPT_SSL_VERIFYPEER] = FALSE;
    		}
    		curl_setopt_array($ch, $opt);
    		curl_exec($ch);
    		curl_close($ch);
    	}
    
    
  • 相关阅读:
    【转】分治法求最大值最小值
    JPA基本实体映射学习
    android权限
    Servlet实现基本文件上传
    Flask项目部署(nginx+supervisor+uwsgi)
    DevExpress学习笔记(三)XtraGrid
    DevExpress学习笔记(五)-以拖拽的方式构建树(TreeList)
    使用ICE建立C++与C#的通讯
    带有Wallet的impdp导入过程
    调用ODAC报BadImageFormatException异常的解决方法
  • 原文地址:https://www.cnblogs.com/x3d/p/zentao-pms-bearychat.html
Copyright © 2020-2023  润新知