123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace app\common\library;
- use getusersig\getusersig;
- use tencentim\tencentim;
- class Trtcim
- {
- public static function sendGroupMsg($groupId, $messageData)
- {
- $msgData = [];
- $msgData["version"] = "1.0";
- $msgData["action"] = 301;
- $msgData["command"] = "";
- $msgData["message"] = json_encode($messageData);
- $random = rand(10000000, 99999999);
- $usersig = self::usersig("administrator");
- // 获取配置信息
- $config = config("tencent_im");
- $url = "https://console.tim.qq.com/v4/group_open_http_svc/send_group_msg";
- $url .= "?sdkappid=" . $config["sdkappid"];
- $url .= "&identifier=administrator";
- $url .= "&usersig=" . $usersig;
- $url .= "&random=" . $random;
- $url .= "&contenttype=json";
- $tencentObj = new tencentim($url);
- $data = [];
- $data["GroupId"] = $groupId;
- $data["Random"] = rand(1000000, 9999999);
- $data["MsgBody"][] = [
- "MsgType" => "TIMCustomElem",
- "MsgContent" => [
- "Data" => json_encode($msgData)
- ],
- ];
- $tencentObj->toSend($data);
- }
- /**
- * 获取usersig签名-具体操作
- */
- private static function usersig($user_id)
- {
- // 获取配置信息
- $config = config("tencent_im");
- $usersigObj = new getusersig($config["sdkappid"], $config["key"]);
- $usersig = $usersigObj->genUserSig($user_id);
- return $usersig;
- }
- }
|