This commit is contained in:
lisida 2019-02-25 11:27:28 +08:00
parent a155f52333
commit 338e38825b
3 changed files with 641 additions and 173 deletions

View File

@ -12,12 +12,17 @@
] ]
}, },
"require": { "require": {
"arch/php-internal-api-client": "^0.6.1" "arch/php-internal-api-client": "^0.6.1",
"paidian/json-rpc": "~1.1"
}, },
"repositories": { "repositories": {
"php-internal-api-client": { "php-internal-api-client": {
"type": "vcs", "type": "vcs",
"url": "git@git.int.haowumc.com:arch/php-internal-api-client.git" "url": "git@git.int.haowumc.com:arch/php-internal-api-client.git"
},
"php-json-rpc": {
"type": "vcs",
"url": "git@git.int.haowumc.com:composer/php-json-rpc.git"
} }
} }
} }

673
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,12 @@
<?php <?php
define('CRM_API_CONFIG', [ define('RPC_CONFIG',[
'base_uri' => 'http://push.in.haowumc.com/api/wechat/', 'app' => env('APP_NAME'),
'appid' => 'notification', 'client' => [
'secret' => '123456', 'auth' => [
'base_uri' => 'http://auth.in.haowumc.com',
],
],
]); ]);
/** /**
@ -15,12 +18,13 @@ define('CRM_API_CONFIG', [
function chat_text_alert($chat, $text) function chat_text_alert($chat, $text)
{ {
$client = new \PdInternalApi\Client('crm', CRM_API_CONFIG); $base_client = new \JsonRpc\Client(RPC_CONFIG);
$client = $base_client->endpoint('auth');
try { try {
$resp = $client->call('work/text', [ $resp = $client->call('notify.text', [
'chat_id' => $chat, ['chat' => $chat],
'text' => $text, $text,
]); ]);
} catch (Exception $ex) { } catch (Exception $ex) {
var_dump($ex->getMessage()); var_dump($ex->getMessage());
@ -32,26 +36,26 @@ function chat_text_alert($chat, $text)
/** /**
* 对单个或多个用户发送报警或通知信息多个用户id使用 | 隔开 * 对单个或多个用户发送报警或通知信息多个用户id使用 | 隔开
* @param $username
* @param $text * @param $text
* @return mixed|null * @return mixed|null
*/ */
function user_text_alert($username, $text) function user_text_alert($username, $text)
{ {
$base_client = new \JsonRpc\Client(RPC_CONFIG);
$client = $base_client->endpoint('auth');
$client = new \PdInternalApi\Client('crm', CRM_API_CONFIG); $username = explode('|',$username);
try { try {
$resp = $client->call('work/text', [ $res = $client->call('notify.text', [
'username' => $username, ['user' => $username],
'text' => $text, $text,
]); ]);
} catch (Exception $ex) { } catch (Exception $ex) {
var_dump($ex->getMessage()); var_dump($ex->getMessage());
return null; return null;
} }
return $resp; return $res;
} }
/** /**
@ -65,16 +69,16 @@ function user_text_alert($username, $text)
*/ */
function chat_card_alert($chat, $title, $desc, $button, $url) function chat_card_alert($chat, $title, $desc, $button, $url)
{ {
$base_client = new \JsonRpc\Client(RPC_CONFIG);
$client = new \PdInternalApi\Client('crm', CRM_API_CONFIG); $client = $base_client->endpoint('auth');
try { try {
$resp = $client->call('work/card', [ $resp = $client->call('notify.card', [
'chat_id' => $chat, ['chat' => $chat],
'title' => $title, $title,
'desc' => $desc, $desc,
'button' => $button, $button,
'url' => $url, $url,
]); ]);
} catch (Exception $ex) { } catch (Exception $ex) {
var_dump($ex->getMessage()); var_dump($ex->getMessage());
@ -95,16 +99,86 @@ function chat_card_alert($chat, $title, $desc, $button, $url)
*/ */
function user_card_alert($username, $title, $desc, $button, $url) function user_card_alert($username, $title, $desc, $button, $url)
{ {
$base_client = new \JsonRpc\Client(RPC_CONFIG);
$client = $base_client->endpoint('auth');
$client = new \PdInternalApi\Client('crm', CRM_API_CONFIG); $username = explode('|',$username);
try {
$resp = $client->call('notify.card', [
['user' => $username],
$title,
$desc,
$button,
$url,
]);
} catch (Exception $ex) {
var_dump($ex->getMessage());
return null;
}
return $resp;
}
/**
* 对单个或多个用户发送文本卡片多个用户id使用 | 隔开
* @param $username
* @param $appid //小程序的appid
* @param $title //标题
* @param $page //小程序页面路径
* @param $desc //描述
* @param $items //消息内容键值对最多允许10个item
* @param $emphasisFirstItem //是否放大第一个content_item
* @return mixed|null
*/
function user_mp_alert($username, $appid, $title, $page = null, $desc = null,$items = null,$emphasisFirstItem = null)
{
$base_client = new \JsonRpc\Client(RPC_CONFIG);
$client = $base_client->endpoint('auth');
$username = explode('|',$username);
try {
$resp = $client->call('notify.mp', [
['user' => $username],
$appid,
$title,
$page,
$desc,
$items,
$emphasisFirstItem
]);
} catch (Exception $ex) {
var_dump($ex->getMessage());
return null;
}
return $resp;
}
/**
* 对单个或多个用户发送文本卡片多个用户id使用 | 隔开
* @param $username
* @param $appid //小程序的appid
* @param $title //标题
* @param $page //小程序页面路径
* @param $desc //描述
* @param $items //消息内容键值对最多允许10个item
* @param $emphasisFirstItem //是否放大第一个content_item
* @return mixed|null
*/
function tag_mp_alert($tag, $appid, $title, $page = null, $desc = null,$items = null,$emphasisFirstItem = null)
{
$base_client = new \JsonRpc\Client(RPC_CONFIG);
$client = $base_client->endpoint('auth');
try { try {
$resp = $client->call('work/card', [ $resp = $client->call('notify.mp', [
'username' => $username, ['tag' => $tag],
'title' => $title, $appid,
'desc' => $desc, $title,
'button' => $button, $page,
'url' => $url, $desc,
$items,
$emphasisFirstItem
]); ]);
} catch (Exception $ex) { } catch (Exception $ex) {
var_dump($ex->getMessage()); var_dump($ex->getMessage());