MessageService.php
1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
namespace App\Http\Services;
//后台消息相关服务
use App\Model\SupplierBlacklistModel;
use App\Model\SupplierChannelModel;
class MessageService
{
public function sendMessage($keyword, $data, $to_user = '', $cnUncode = false)
{
if (config('website.SkipSendEmail')) {
return true;
}
// 推送给内部人员
if ($cnUncode) {
if (isset($data['data'])) {
$send_data = json_encode($data['data'], JSON_UNESCAPED_UNICODE); //防止中文乱码
} else {
$send_data = json_encode($data, JSON_UNESCAPED_UNICODE); //防止中文乱码
}
} else {
$send_data = json_encode($data['data']);
}
if (!$to_user) { // 给正式的内部人员推送
$to_user = 'INNER_PERSON';
}
$toUserJson = json_encode($to_user);
$check['touser'] = $toUserJson;
$check['data'] = $send_data;
$check['pf'] = -1;
$check['keyword'] = $keyword;
$check['is_ignore'] = 1;
$check = array_merge($check, $this->authkey());
$res = curl(config('website.MessageUrl') . '/msg/sendMessageByAuto', $check, true);
if (!empty($res)) {
$res = json_decode($res, true);
}
return $res;
}
public function authkey($pf = -1)
{
return array(
'pf' => 1,
'k1' => $_SERVER['REQUEST_TIME'],
'k2' => $this->pwdhash($_SERVER['REQUEST_TIME'], config('website.MessageKey'))
);
}
private function pwdhash($pwd, $salt)
{
return md5(md5($pwd).$salt);
}
}