1、搞个方法
/**
* Notes: 发企业微信消息
* User: admin
* Date: 2021-04-07
* Time:10:14
* @param $msg
* @param string|null $url
* @param null $type
* @return mixed
*/
function sendWebHookMsg($msg, string $url = null, $type = null)
{
$url = $url ?: env('WEBHOOK_PRODUCTALARM');
// echo $url . "\r\n" . $msg . "\r\n";
if ($url) {
$client = new \GuzzleHttp\Client();
$res = $client->request('POST', $url, [
'headers' => ['Content-Type' => 'application/json'],
'json' => [
'msgtype' => 'text',
'text' => [
'content' => $msg,
],
],
'timeout' => 20,
]);
// $res->getStatusCode(); // 获得接口反馈状态码
// $body = $res->getBody(); //获得接口返回的主体对象
// $body->getContents(); //获得主体内容
// return $body;
}
}
2、配置env选项

3、直接调用方法
sendWebHookMsg(join(";\r\n", $notEnoughNames) . ";\r\n以上产品库存量减掉下单锁定数量剩余不足5件,请注意!\r\n消息来自:" . env('APP_NAME'));
效果如图:

4、企业微信支持的参数发送内容格式


文档地址:
https://work.weixin.qq.com/api/doc/90000/90136/91770
时间:2021年4月7日10:54:51
982



被折叠的 条评论
为什么被折叠?



