增加机器人提醒
This commit is contained in:
parent
6f587de22a
commit
72940d3d0d
|
@ -3,7 +3,9 @@ namespace app\server;
|
||||||
|
|
||||||
use app\model\Orders;
|
use app\model\Orders;
|
||||||
use app\model\ThirdMobileLogs;
|
use app\model\ThirdMobileLogs;
|
||||||
|
use http\Client;
|
||||||
use support\Log;
|
use support\Log;
|
||||||
|
use support\Redis;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 阿里云市场相关接口
|
* 阿里云市场相关接口
|
||||||
|
@ -28,7 +30,7 @@ class ThirdApiService {
|
||||||
$bodys = "mobile_number=" . $mobile;
|
$bodys = "mobile_number=" . $mobile;
|
||||||
$url = $host . $path;
|
$url = $host . $path;
|
||||||
|
|
||||||
$aliData = $this->curlRequest($url, $method, $headers, $bodys);
|
$aliData = $this->curlMobileRequest($url, $method, $headers, $bodys);
|
||||||
if (isset($aliData['code']) && $aliData['code'] == 200) {
|
if (isset($aliData['code']) && $aliData['code'] == 200) {
|
||||||
ThirdMobileLogs::query()->insert([
|
ThirdMobileLogs::query()->insert([
|
||||||
'mobile' => $mobile,
|
'mobile' => $mobile,
|
||||||
|
@ -47,7 +49,7 @@ class ThirdApiService {
|
||||||
* @param $bodys
|
* @param $bodys
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
private function curlRequest($url, $method, $headers, $bodys){
|
private function curlMobileRequest($url, $method, $headers, $bodys){
|
||||||
$curl = curl_init();
|
$curl = curl_init();
|
||||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
|
||||||
curl_setopt($curl, CURLOPT_URL, $url);
|
curl_setopt($curl, CURLOPT_URL, $url);
|
||||||
|
@ -75,7 +77,7 @@ class ThirdApiService {
|
||||||
*/
|
*/
|
||||||
public function weComNotice($os) {
|
public function weComNotice($os) {
|
||||||
$url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=e138b55c-2886-4729-922e-9a8c753f75ee';
|
$url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=e138b55c-2886-4729-922e-9a8c753f75ee';
|
||||||
$method = 'post';
|
$method = 'POST';
|
||||||
$message = sprintf($this->notice, Orders::OSS[$os] ?? '');
|
$message = sprintf($this->notice, Orders::OSS[$os] ?? '');
|
||||||
$bodys = [
|
$bodys = [
|
||||||
'msgtype' => 'text',
|
'msgtype' => 'text',
|
||||||
|
@ -84,6 +86,44 @@ class ThirdApiService {
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
return $this->curlRequest($url, $method, [], json_encode($bodys));
|
if (Redis::setNx('notice-' . $os, 600, 1)) {
|
||||||
|
$this->curlRequest($url, $method, [], $bodys);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $url
|
||||||
|
* @param $method
|
||||||
|
* @param $headers
|
||||||
|
* @param $bodys
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
private function curlRequest($url, $method, $headers, $bodys){
|
||||||
|
$curl = curl_init();
|
||||||
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
|
||||||
|
curl_setopt($curl, CURLOPT_URL, $url);
|
||||||
|
curl_setopt($curl, CURLOPT_FAILONERROR, false);
|
||||||
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
//设定返回信息中是否包含响应信息头,启用时会将响应信息头作为数据流输出,true 表示输出信息头, false表示不输出信息头
|
||||||
|
//如果想将响应结果json字符串转为json数组,建议将 CURLOPT_HEADER 设置成 false
|
||||||
|
curl_setopt($curl, CURLOPT_HEADER, true);
|
||||||
|
if (1 == strpos("$".$url, "https://"))
|
||||||
|
{
|
||||||
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||||
|
}
|
||||||
|
if (is_array($bodys)) {
|
||||||
|
$bodys = json_encode($bodys);
|
||||||
|
}
|
||||||
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
|
||||||
|
curl_setopt($curl, CURLOPT_HTTPHEADER, array_merge($headers, [
|
||||||
|
'Content-Type: application/json',
|
||||||
|
'Content-Length: ' . strlen($bodys)
|
||||||
|
]));
|
||||||
|
curl_close($curl);
|
||||||
|
list($header, $body) = explode("\r\n\r\n", curl_exec($curl), 2);
|
||||||
|
Log::info(sprintf('third req:%s, res:%s', $url, $body));
|
||||||
|
return json_decode($body, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue