钉钉系统提示消息
下面展示一些 内联代码片
。
public function order(){
//订单支付成功发送钉钉系统提示消息
$name='张三';
$product = '苹果';
$this->dingNews($name,$product);
}
//发送钉钉消息
protected function dingNews($name='',$product=''){
$time = date('Y-m-d H:i:s',time());
$hookmessage = "订单用户:" . $name . "\n";
$hookmessage .= "订单时间:" . $time . "\n";
$hookmessage .= "订单产品:" . $product . "\n";
$hookdata = array('msgtype' => 'text', 'text' => array('content' => $hookmessage));
$hookdata_string = json_encode($hookdata);
],
//$order钉钉消息群的链接
$order = 'https://oapi.dingtalk.com/robot/send?access_token=';
$this->request_by_curl($order, $hookdata_string);
return 1;
}
protected function request_by_curl($remote_server, $post_string) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $remote_server);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_HTTPHEADER, array ('Content-Type: application/json;charset=utf-8'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}