Let ZenTao also play BearyChat

WBOY
Release: 2016-07-30 13:29:39
Original
1014 people have browsed it

A simple understanding, BearycChat is a kind of IM, something that can aggregate messages from various MS systems, and is a powerful tool for message flow during team collaboration.

I’m a tool lover, so I don’t feel uncomfortable with it.

No more nonsense, here’s the code:

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

<code><?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[&#39;action&#39;] = $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);
	}
</code>
Copy after login

The above introduces how you can play BearyChat with ZenTao, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template