ImSendService.php
1.39 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
<?php
namespace App\Http\Service;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
class ImSendService
{
public function batchSend($sign,$to_user,$from_user,$sendData,$SyncOtherMachine=1)
{
$to_users = [];
if (env('APP_ENV') != 'production'){
if ($from_user != 'system'){
$from_user= 'test'.$from_user;
}
foreach ($to_user as $id){
$id = 'test'.$id;
array_push($to_users,$id);
}
}
else{
$from_user= (string)$from_user;
foreach ($to_user as $id){
array_push($to_users,(string)$id);
}
}
$MsgRandom = rand(1000000, 9999999);
$url = 'https://console.tim.qq.com/v4/openim/batchsendmsg?sdkappid='.config('services.im.key').'&identifier=administrator&usersig=' . $sign . '&random=99999999&contenttype=json';
$data = [
"SyncOtherMachine" => $SyncOtherMachine,
"From_Account" => $from_user,
"To_Account" => $to_users,
"MsgLifeTime" => 3600,
"MsgSeq" => 93847636,
"MsgRandom" => $MsgRandom,
"MsgBody" => $sendData['MsgBody'],
"OfflinePushInfo" =>$sendData['OfflinePushInfo']
];
$resp = Http::asJson()->post($url,$data )->throw(true)->json();
return $resp;
}
}