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";