From cf9591a0b555ae303f8694417832bdeb42ad0e26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=80=99=E5=AD=A6=E6=9D=B0?= Date: Wed, 2 Jan 2019 15:17:32 +0800 Subject: [PATCH] card message --- src/functions.php | 60 +++++++++++++++++++++++++++++++++++++++++++++++ tests/text.php | 2 +- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/functions.php b/src/functions.php index 180f1d2..87a0c44 100644 --- a/src/functions.php +++ b/src/functions.php @@ -53,3 +53,63 @@ function user_text_alert($username, $text) return $resp; } + +/** + * 对微信群发送文本卡片 + * @param $chat + * @param $title + * @param $desc + * @param $button + * @param $url + * @return mixed|null + */ +function chat_card_alert($chat, $title, $desc, $button, $url) +{ + + $client = new \PdInternalApi\Client('crm', CRM_API_CONFIG); + + try { + $resp = $client->call('work/card', [ + 'chat_id' => $chat, + 'title' => $title, + 'desc' => $desc, + 'button' => $button, + 'url' => $url, + ]); + } catch (Exception $ex) { + var_dump($ex->getMessage()); + return null; + } + + return $resp; +} + +/** + * 对单个或多个用户发送文本卡片,多个用户id使用 | 隔开 + * @param $username + * @param $title + * @param $desc + * @param $button + * @param $url + * @return mixed|null + */ +function user_card_alert($username, $title, $desc, $button, $url) +{ + + $client = new \PdInternalApi\Client('crm', CRM_API_CONFIG); + + try { + $resp = $client->call('work/card', [ + 'username' => $username, + 'title' => $title, + 'desc' => $desc, + 'button' => $button, + 'url' => $url, + ]); + } catch (Exception $ex) { + var_dump($ex->getMessage()); + return null; + } + + return $resp; +} \ No newline at end of file diff --git a/tests/text.php b/tests/text.php index a7f78bc..7485947 100644 --- a/tests/text.php +++ b/tests/text.php @@ -5,7 +5,7 @@ ini_set('display_errors', 'stderr'); require_once dirname(__DIR__).'/vendor/autoload.php'; -$ret = user_text_alert('houxuejie','dfdfdf'); +$ret = chat_card_alert('szjesh','dfdfdf'); var_dump($ret); if( $ret['err_code'] == '0' ){ echo "发送成功\n";