Trtcim.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\common\library;
  3. use getusersig\getusersig;
  4. use tencentim\tencentim;
  5. class Trtcim
  6. {
  7. public static function sendGroupMsg($groupId, $messageData)
  8. {
  9. $msgData = [];
  10. $msgData["version"] = "1.0";
  11. $msgData["action"] = 301;
  12. $msgData["command"] = "";
  13. $msgData["message"] = json_encode($messageData);
  14. $random = rand(10000000, 99999999);
  15. $usersig = self::usersig("administrator");
  16. // 获取配置信息
  17. $config = config("tencent_im");
  18. $url = "https://console.tim.qq.com/v4/group_open_http_svc/send_group_msg";
  19. $url .= "?sdkappid=" . $config["sdkappid"];
  20. $url .= "&identifier=administrator";
  21. $url .= "&usersig=" . $usersig;
  22. $url .= "&random=" . $random;
  23. $url .= "&contenttype=json";
  24. $tencentObj = new tencentim($url);
  25. $data = [];
  26. $data["GroupId"] = $groupId;
  27. $data["Random"] = rand(1000000, 9999999);
  28. $data["MsgBody"][] = [
  29. "MsgType" => "TIMCustomElem",
  30. "MsgContent" => [
  31. "Data" => json_encode($msgData)
  32. ],
  33. ];
  34. $tencentObj->toSend($data);
  35. }
  36. /**
  37. * 获取usersig签名-具体操作
  38. */
  39. private static function usersig($user_id)
  40. {
  41. // 获取配置信息
  42. $config = config("tencent_im");
  43. $usersigObj = new getusersig($config["sdkappid"], $config["key"]);
  44. $usersig = $usersigObj->genUserSig($user_id);
  45. return $usersig;
  46. }
  47. }