ImSendService.php 1.39 KB
<?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;
    }
}