php调用接口发送钉钉消息

钉钉系统提示消息

下面展示一些 内联代码片

     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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值