phpjson数据中继器fisheye 钉钉webhook实现

内容目录
<?php
//获取输入json
$data= file_get_contents("php://input");
$obj=json_decode($data); 
//构造格式
// $content="repository: ".$obj->repository->name."\n".
//           "author: ".$obj->changeset->author."\n".
//           "versionId:".$obj->changeset->displayId."\n".
//           "time: ".date("Y-m-d H:i:s", $obj->changeset->date/1000)."\n".
//           "branches: ".implode(',',$obj->changeset->branches)."\n".
//           "tags: ".implode(',',$obj->changeset->tags)."\n".
//           "comment: ".$obj->changeset->comment;

// **cyj commit to sjtjyy**
// branches:trunk
// >version:[626](http://XXX:8060/changelog/XXX?cs=626)
// ><font color=gray>comment:单位端手机改版</font>

$content="**".$obj->changeset->author." commit to ".$obj->repository->name."**\n".
         "branches:".implode(',',$obj->changeset->branches)."\n".
         ">version:[".$obj->changeset->csid."](http://XXX:8060/changelog/".$obj->repository->name."?cs=".$obj->changeset->csid.")\n".
         "><font color=gray>comment:".$obj->changeset->comment."</font>";
//生成文件
$file  = 'log.txt';//要写入文件的文件名(可以是任意文件名),如果文件不存在,将会创建一个
if($f  = file_put_contents($file,$data."**************************\n".$content ,FILE_APPEND)){// 这个函数支持版本(PHP 5) 
  echo "写入成功。<br />";
}

//构造钉钉格式
$data = array ("msgtype" => "markdown","markdown" => array("text"=>$content,"title"=>"测试"));
$data_string = json_encode($data);

//发送数据
$ch = curl_init('https://oapi.dingtalk.com/robot/send?access_token=XXX');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: '.strlen($data_string))
);
$result = curl_exec($ch);
curl_close($ch);
//输出返回结果
print_r($result);

?>

发表回复