TencentIm.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. <?php
  2. namespace app\utils\Service\Tencent;
  3. use app\utils\CurlUtil;
  4. class TencentIm extends Module
  5. {
  6. private $config;
  7. private $host = "https://console.tim.qq.com";
  8. public function __construct()
  9. {
  10. // 获取配置信息
  11. $this->config = [
  12. 'appid' => config('tencent_im.sdkappid'),
  13. 'identifier' => config('tencent_im.identifier'),
  14. 'key' => config('tencent_im.key'),
  15. ];
  16. }
  17. /**
  18. * 注册im
  19. * @param string $userid
  20. * @param string $nickname
  21. * @param string $avatar
  22. * @return bool
  23. */
  24. public function register(string $userid, string $nickname, string $avatar = '')
  25. {
  26. $data = [
  27. 'UserID' => $userid,
  28. 'Nick' => $nickname,
  29. 'FaceUrl' => $avatar
  30. ];
  31. $res = $this->postJson('/v4/im_open_login_svc/account_import', $data);
  32. if (empty($res['ActionStatus']) || $res['ActionStatus'] != 'OK') {
  33. return $this->error(!empty($res['ErrorInfo']) ? $res['ErrorInfo'] : 'im error', $res ?? []);
  34. }
  35. return $this->success('操作成功', $res);
  36. }
  37. /**
  38. * 设置用户资料
  39. * @param string $userid
  40. * @param array $params
  41. * @return bool
  42. */
  43. public function set_info(string $userid,array $params = [])
  44. {
  45. $data = [];
  46. foreach ($params as $key => $value) {
  47. $data[] = [
  48. 'Tag' => $key,
  49. 'Value' => $value,
  50. ];
  51. }
  52. $data = [
  53. 'From_Account' => $userid,
  54. 'ProfileItem' => $data
  55. ];
  56. $res = $this->postJson('/v4/profile/portrait_set', $data);
  57. if (empty($res['ActionStatus']) || $res['ActionStatus'] != 'OK') {
  58. return $this->error(!empty($res['ErrorInfo']) ? $res['ErrorInfo'] : 'im error', $res ?? []);
  59. }
  60. return $this->success('操作成功', $res);
  61. }
  62. /**
  63. * 发送消息给某人
  64. * @param $from_user
  65. * @param $to_user
  66. * @param $message
  67. * @param $type //0普通消息 1自定义消息
  68. * @return bool
  69. */
  70. public function sendMessageToUser($from_user, $to_user, $message, $type = 0)
  71. {
  72. $data = [
  73. 'SyncOtherMachine' => 1,
  74. 'From_Account' => (string)$from_user,
  75. 'To_Account' => (string)$to_user,
  76. 'MsgRandom' => rand(1000000, 9999999),
  77. 'MsgTimeStamp' => time(),
  78. ];
  79. if ($type == 1) { //自定义消息
  80. $body_message = '{"businessID":"custom_tips_message","receiverShow":true,"senderId":"' . $from_user . '","text":"' . $message . '","tipType":257,"version":0}';
  81. $data["MsgBody"][] = [
  82. "MsgType" => "TIMCustomElem",
  83. "MsgContent" => [
  84. "Data" => $body_message,
  85. "Desc" => $body_message,
  86. "Ext" => 'custom_tips_message',
  87. "Sound" => ''
  88. ],
  89. ];
  90. } elseif ($type == 2) {
  91. // 完全自定义
  92. $data['MsgBody'] = $message['MsgBody'];
  93. $data['CloudCustomData'] = $message['CloudCustomData'];
  94. } elseif ($type == 3) {
  95. // 客服自定义消息
  96. $data["MsgBody"][] = [
  97. "MsgType" => "TIMCustomElem",
  98. "MsgContent" => [
  99. "Data" => json_encode($message,JSON_UNESCAPED_UNICODE),
  100. "Desc" => json_encode($message,JSON_UNESCAPED_UNICODE),
  101. "Ext" => 'custom_tips_message',
  102. "Sound" => ''
  103. ],
  104. ];
  105. } else {
  106. $data["MsgBody"][] = [
  107. "MsgType" => "TIMTextElem",
  108. "MsgContent" => [
  109. "Text" => $message
  110. ],
  111. ];
  112. }
  113. $res = $this->postJson('/v4/openim/sendmsg', $data);
  114. if (empty($res['ActionStatus']) || $res['ActionStatus'] != 'OK') {
  115. return $this->error(!empty($res['ErrorInfo']) ? $res['ErrorInfo'] : 'im error', $res ?? []);
  116. }
  117. return $this->success('操作成功', $res);
  118. }
  119. /**
  120. * 批量发送消息
  121. * @param $from_user
  122. * @param array $to_user
  123. * @param $message
  124. * @param $type //0普通消息 1自定义消息
  125. * @return bool
  126. */
  127. public function sendMessageToUsers($from_user, array $to_user, $message, $type = 0)
  128. {
  129. $data = [
  130. 'SyncOtherMachine' => 2,
  131. 'From_Account' => (string)$from_user,
  132. 'To_Account' => $to_user,
  133. 'MsgRandom' => rand(1000000, 9999999),
  134. 'MsgTimeStamp' => time(),
  135. ];
  136. if ($type == 1) { //自定义消息
  137. $body_message = '{"businessID":"custom_tips_message","receiverShow":true,"senderId":"' . $from_user . '","text":"' . $message . '","tipType":257,"version":0}';
  138. $data["MsgBody"][] = [
  139. "MsgType" => "TIMCustomElem",
  140. "MsgContent" => [
  141. "Data" => $body_message,
  142. "Desc" => $body_message,
  143. "Ext" => 'custom_tips_message',
  144. "Sound" => ''
  145. ],
  146. ];
  147. } elseif ($type == 2) {
  148. // 完全自定义
  149. $data['MsgBody'] = $message['MsgBody'];
  150. $data['CloudCustomData'] = $message['CloudCustomData'];
  151. } else {
  152. $data["MsgBody"][] = [
  153. "MsgType" => "TIMTextElem",
  154. "MsgContent" => [
  155. "Text" => $message
  156. ],
  157. ];
  158. }
  159. $res = $this->postJson('/v4/openim/sendmsg', $data);
  160. if (empty($res['ActionStatus']) || $res['ActionStatus'] != 'OK') {
  161. return $this->error(!empty($res['ErrorInfo']) ? $res['ErrorInfo'] : 'im error', $res ?? []);
  162. }
  163. return $this->success('操作成功', $res);
  164. }
  165. /**
  166. * 创建群组
  167. * @param $user_id
  168. * @param $room_no
  169. * @param $room_name
  170. * @param $type
  171. * @param $params // 其他参数
  172. * @return bool
  173. */
  174. public function create_group($user_id, $room_no, $room_name, $type = 'Public', $params = [])
  175. {
  176. $this->config['identifier'] = (string)$user_id;// 群主 ID
  177. $data = [
  178. 'Owner_Account' => (string)$user_id, // 群主 ID
  179. 'Type' => $type, // 群组形态,包括 Public(陌生人社交群),Private(即 Work,好友工作群),ChatRoom(即 Meeting,会议群),AVChatRoom(直播群),Community(社群)
  180. 'GroupId' => (string)$room_no, // 自定义群组 ID
  181. 'Name' => $room_name,
  182. // 申请加群处理方式。包含 FreeAccess(自由加入),NeedPermission(需要验证),DisableApply(禁止加群),如果不填,具体默认项可参见 加群方式差异;
  183. // 仅当创建支持申请加群的 群组 时,该字段有效。
  184. // 社群目前不支持此字段。
  185. //'ApplyJoinOption' => 'NeedPermission',// 申请加群处理方式。
  186. // 邀请加群处理方式,包含 FreeAccess (直接邀请用户进群,不需要审批等操作), NeedPermission 需要群管理员或者群主审批, DisableInvite 不支持 SDK 邀请进群, 该选项 AVChatRoom 群类型不支持
  187. //'InviteJoinOption' => 'NeedPermission',// 申请加群处理方式。
  188. ];
  189. $res = $this->postJson('/v4/group_open_http_svc/create_group', array_merge($data, $params));
  190. if (empty($res['ActionStatus']) || $res['ActionStatus'] != 'OK') {
  191. return $this->error(!empty($res['ErrorInfo']) ? $res['ErrorInfo'] : 'im error', $res ?? []);
  192. }
  193. return $this->success('创建成功', $res);
  194. }
  195. // 解散群组
  196. public function close_group($room_no)
  197. {
  198. $data = [
  199. 'GroupId' => (string)$room_no, // 自定义群组 ID
  200. ];
  201. $res = $this->postJson('/v4/group_open_http_svc/destroy_group', $data);
  202. if (empty($res['ActionStatus']) || $res['ActionStatus'] != 'OK') {
  203. return $this->error(!empty($res['ErrorInfo']) ? $res['ErrorInfo'] : 'im error', $res ?? []);
  204. }
  205. return $this->success('解散成功', $res);
  206. }
  207. // 发送群系统消息
  208. public function send_group_system_message($room_no,$content)
  209. {
  210. $data = [
  211. 'GroupId' => (string)$room_no, // 自定义群组 ID
  212. 'Content' => $content, // 消息内容
  213. ];
  214. $res = $this->postJson('/v4/group_open_http_svc/send_group_system_notification', $data);
  215. if (empty($res['ActionStatus']) || $res['ActionStatus'] != 'OK') {
  216. return $this->error(!empty($res['ErrorInfo']) ? $res['ErrorInfo'] : 'im error', $res ?? []);
  217. }
  218. return $this->success('创建成功', $res);
  219. }
  220. // 发送群普通消息
  221. public function send_group_message($room_no,$content)
  222. {
  223. $data = [
  224. 'GroupId' => (string)$room_no, // 自定义群组 ID
  225. 'Content' => $content, // 消息内容
  226. ];
  227. $res = $this->postJson('/v4/group_open_http_svc/send_group_system_notification', $data);
  228. if (empty($res['ActionStatus']) || $res['ActionStatus'] != 'OK') {
  229. return $this->error(!empty($res['ErrorInfo']) ? $res['ErrorInfo'] : 'im error', $res ?? []);
  230. }
  231. return $this->success('创建成功', $res);
  232. }
  233. /**
  234. * 转让群主
  235. * @param $group_chat_id
  236. * @param $chat_id
  237. * @return bool
  238. */
  239. public function change_owner($group_chat_id, $chat_id)
  240. {
  241. $data = [
  242. 'GroupId' => (string)$group_chat_id, // 要被转移的群 ID(必填)
  243. 'NewOwner_Account' => (string)$chat_id, // 新群主 ID(必填)
  244. ];
  245. $res = $this->postJson('/v4/group_open_http_svc/change_group_owner', $data);
  246. if (empty($res['ActionStatus']) || $res['ActionStatus'] != 'OK') {
  247. return $this->error(!empty($res['ErrorInfo']) ? $res['ErrorInfo'] : 'im error', $res ?? []);
  248. }
  249. return $this->success('操作成功', $res);
  250. }
  251. /**
  252. * 增加群成员
  253. * @param $group_chat_id
  254. * @param array $chat_ids
  255. * @return bool
  256. */
  257. public function add_group_member($group_chat_id, array $chat_ids)
  258. {
  259. $MemberList = [];
  260. foreach ($chat_ids as $value) {
  261. $MemberList[] = [
  262. 'Member_Account' => $value,// 要添加的群成员ID(必填)
  263. ];
  264. }
  265. $data = [
  266. 'GroupId' => (string)$group_chat_id, // 要被转移的群 ID(必填)
  267. 'MemberList' => $MemberList, // 一次最多添加300个成员
  268. ];
  269. $res = $this->postJson('/v4/group_open_http_svc/add_group_member', $data);
  270. if (empty($res['ActionStatus']) || $res['ActionStatus'] != 'OK') {
  271. return $this->error(!empty($res['ErrorInfo']) ? $res['ErrorInfo'] : 'im error', $res ?? []);
  272. }
  273. return $this->success('操作成功', $res);
  274. }
  275. /**
  276. * 解散群组
  277. * @param $room_no
  278. * @return bool
  279. */
  280. public function destroy_group($room_no)
  281. {
  282. $data = [
  283. 'GroupId' => (string)$room_no
  284. ];
  285. $res = $this->postJson('/v4/group_open_http_svc/destroy_group', $data);
  286. if (empty($res['ActionStatus']) || $res['ActionStatus'] != 'OK') {
  287. return $this->error(!empty($res['ErrorInfo']) ? $res['ErrorInfo'] : 'im error', $res ?? []);
  288. }
  289. return $this->success('获取成功', $res);
  290. }
  291. /**
  292. * 在群组中发送系统通知
  293. * @param $room_no
  294. * @param $type // 雷松:10=点赞通知 20=pk通知
  295. * @param $content
  296. * @return bool
  297. */
  298. public function send_group_system_notification($room_no, $type, $content)
  299. {
  300. $data = [
  301. 'GroupId' => (string)$room_no,
  302. 'Content' => json_encode([
  303. 'type' => $type,
  304. 'content' => $content,
  305. ]),
  306. ];
  307. $res = $this->postJson('/v4/group_open_http_svc/send_group_system_notification', $data);
  308. if (empty($res['ActionStatus']) || $res['ActionStatus'] != 'OK') {
  309. return $this->error(!empty($res['ErrorInfo']) ? $res['ErrorInfo'] : 'im error', $res ?? []);
  310. }
  311. return $this->success('获取成功', $res);
  312. }
  313. /**
  314. * 封禁用户
  315. * @param $room_no
  316. * @param $account
  317. * @param $time
  318. * @param $remark
  319. * @return bool
  320. */
  321. public function ban_group_member($room_no, $account, $time, $remark = '违规操作')
  322. {
  323. $data = [
  324. 'GroupId' => (string)$room_no,
  325. 'Members_Account' => [$account],
  326. 'Duration' => $time, // 封禁时长,单位:秒
  327. 'Description' => $remark// 封禁信息
  328. ];
  329. $res = $this->postJson('/v4/group_open_http_svc/ban_group_member', $data);
  330. if (empty($res['ActionStatus']) || $res['ActionStatus'] != 'OK') {
  331. return $this->error(!empty($res['ErrorInfo']) ? $res['ErrorInfo'] : 'im error', $res ?? []);
  332. }
  333. return $this->success('获取成功', $res);
  334. }
  335. /**
  336. * 解封用户
  337. * @param $room_no
  338. * @param $account
  339. * @return bool
  340. */
  341. public function unban_group_member($room_no, $account)
  342. {
  343. $data = [
  344. 'GroupId' => (string)$room_no,
  345. 'Members_Account' => [$account]
  346. ];
  347. $res = $this->postJson('/v4/group_open_http_svc/unban_group_member', $data);
  348. if (empty($res['ActionStatus']) || $res['ActionStatus'] != 'OK') {
  349. return $this->error(!empty($res['ErrorInfo']) ? $res['ErrorInfo'] : 'im error', $res ?? []);
  350. }
  351. return $this->success('获取成功', $res);
  352. }
  353. // 加入黑名单
  354. public function black_add($from_user, array $to_users = [])
  355. {
  356. $data = [
  357. 'From_Account' => (string)$from_user,
  358. 'To_Account' => $to_users
  359. ];
  360. $res = $this->postJson('/v4/sns/black_list_add', $data);
  361. if (empty($res['ActionStatus']) || $res['ActionStatus'] != 'OK') {
  362. return $this->error(!empty($res['ErrorInfo']) ? $res['ErrorInfo'] : 'im error', $res ?? []);
  363. }
  364. return $this->success('获取成功', $res);
  365. }
  366. // 加入黑名单
  367. public function black_del($from_user, array $to_users = [])
  368. {
  369. $data = [
  370. 'From_Account' => (string)$from_user,
  371. 'To_Account' => $to_users
  372. ];
  373. $res = $this->postJson('/v4/sns/black_list_delete', $data);
  374. if (empty($res['ActionStatus']) || $res['ActionStatus'] != 'OK') {
  375. return $this->error(!empty($res['ErrorInfo']) ? $res['ErrorInfo'] : 'im error', $res ?? []);
  376. }
  377. return $this->success('获取成功', $res);
  378. }
  379. /**
  380. * 移除房间
  381. * @param $room_no
  382. * @param $account
  383. * @return bool
  384. */
  385. public function delete_group_member($room_no, array $accounts)
  386. {
  387. $data = [
  388. 'GroupId' => (string)$room_no,
  389. 'MemberToDel_Account' => $accounts
  390. ];
  391. $res = $this->postJson('/v4/group_open_http_svc/delete_group_member', $data);
  392. if (empty($res['ActionStatus']) || $res['ActionStatus'] != 'OK') {
  393. return $this->error(!empty($res['ErrorInfo']) ? $res['ErrorInfo'] : 'im error', $res ?? []);
  394. }
  395. return $this->success('获取成功', $res);
  396. }
  397. /**
  398. * 禁言 or 解除
  399. * @param $room_no
  400. * @param $account
  401. * @param $time // time = 0 解除
  402. * @return bool
  403. */
  404. public function forbid_send_msg($room_no, $account, $time = 0)
  405. {
  406. $data = [
  407. 'GroupId' => (string)$room_no,
  408. 'Members_Account' => [$account],
  409. 'MuteTime' => $time
  410. ];
  411. $res = $this->postJson('/v4/group_open_http_svc/forbid_send_msg', $data);
  412. if (empty($res['ActionStatus']) || $res['ActionStatus'] != 'OK') {
  413. return $this->error(!empty($res['ErrorInfo']) ? $res['ErrorInfo'] : 'im error', $res ?? []);
  414. }
  415. return $this->success('获取成功', $res);
  416. }
  417. /**
  418. * 获取全部群组
  419. * @return bool
  420. */
  421. public function get_appid_group_list()
  422. {
  423. $data = [
  424. 'Limit' => 1000,// 群主 ID
  425. 'Next' => 0
  426. ];
  427. $res = $this->postJson('/v4/group_open_http_svc/get_appid_group_list', $data);
  428. if (empty($res['ActionStatus']) || $res['ActionStatus'] != 'OK') {
  429. return $this->error(!empty($res['ErrorInfo']) ? $res['ErrorInfo'] : 'im error', $res ?? []);
  430. }
  431. return $this->success('获取成功', $res);
  432. }
  433. /**
  434. * 获取直播推流地址
  435. * @param string $domain 您用来推流的域名
  436. * @param string $streamName 您用来区别不同推流地址的唯一流名称
  437. * @param $key 安全密钥
  438. * @param $time 过期时间 sample 2016-11-12 12:00:00
  439. * @return string
  440. */
  441. public function getLivePushUrl(string $domain,string $streamName,$key = null, $time = null)
  442. {
  443. if($key && $time){
  444. $txTime = strtoupper(base_convert(strtotime($time),10,16));
  445. //txSecret = MD5( KEY + streamName + txTime )
  446. $txSecret = md5($key.$streamName.$txTime);
  447. $ext_str = "?".http_build_query(["txSecret"=> $txSecret, "txTime"=> $txTime]);
  448. }
  449. return "rtmp://".$domain."/live/".$streamName . ($ext_str ?? "");
  450. }
  451. /**
  452. * 获取直播播放地址
  453. * @param string $domain 您用来推流的域名
  454. * @param string $streamName 您用来区别不同推流地址的唯一流名称
  455. * @return string
  456. */
  457. public function getLivePlayUrl(string $domain,string $streamName)
  458. {
  459. return "rtmp://".$domain."/live/".$streamName;
  460. }
  461. // 下载最近消息记录
  462. public function get_history($MsgTime,$ChatType = 1)
  463. {
  464. $data = [
  465. 'ChatType' => $ChatType == 1 ? 'Group' : 'C2C',// 消息类型,C2C 表示单发消息 Group 表示群组消息
  466. 'MsgTime' => $MsgTime
  467. ];
  468. $res = $this->postJson('/v4/open_msg_svc/get_history', $data);
  469. if (empty($res['ActionStatus']) || $res['ActionStatus'] != 'OK') {
  470. return $this->error(!empty($res['ErrorInfo']) ? $res['ErrorInfo'] : 'im error', $res ?? []);
  471. }
  472. return $this->success('获取成功', $res);
  473. }
  474. //下载远程文件 到指定目录
  475. public function downloadFile($file_url, $path = '', $save_file_name = '')
  476. {
  477. $base_path = "uploads/im_file";
  478. if ($path) {
  479. $base_path = "{$base_path}/$path";
  480. }
  481. $dir_path = ROOT_PATH . "/public/{$base_path}/" . date('Ymd');
  482. if (!is_dir($dir_path)) {
  483. mkdir($dir_path, 0777, true);
  484. }
  485. $file = file_get_contents($file_url);
  486. //传入保存文件的名称
  487. $filename = $save_file_name ?: pathinfo($file_url, PATHINFO_BASENAME);
  488. $resource = fopen($dir_path. '/'. $filename, 'w');
  489. fwrite($resource, $file);
  490. fclose($resource);
  491. return $dir_path . '/' . $filename;
  492. }
  493. //解压
  494. public function jieyagz($gz_path = ''){
  495. $json_path = substr($gz_path,0,-3);
  496. if ($zp = gzopen($gz_path, 'r')) { // 打开压缩文件
  497. if ($fp = fopen($json_path, 'w')) { // 打开目标文件
  498. while (!gzeof($zp)) {
  499. fwrite($fp, gzread($zp, 1024 * 512)); // 逐块读取和解压缩后写入
  500. }
  501. fclose($fp);
  502. }
  503. gzclose($zp);
  504. }
  505. return $json_path;
  506. }
  507. //读取json并分析,group
  508. public function readjson_group($json_path = ''){
  509. $json_content = file_get_contents($json_path);
  510. $json_content = json_decode($json_content,true);
  511. $newMsgList = [];
  512. if(isset($json_content['MsgList']) && !empty($json_content['MsgList'])){
  513. $MsgList = $json_content['MsgList'];
  514. foreach($MsgList as $key => $val)
  515. {
  516. $MsgBody = isset($val['MsgBody']) ? json_encode($val['MsgBody'],JSON_UNESCAPED_UNICODE) : '';
  517. $newMsgList[] = [
  518. 'ClientIP' => $val['ClientIP'] ?? '',
  519. 'From_Account' => $val['From_Account'] ?? '',
  520. 'GroupId' => $val['GroupId'] ?? '',
  521. 'MsgBody' => $MsgBody,
  522. 'MsgFromPlatform' => $val['MsgFromPlatform'] ?? '',
  523. 'MsgSeq' => $val['MsgSeq'] ?? '',
  524. 'MsgTimestamp' => $val['MsgTimestamp'] ?? '',
  525. ];
  526. }
  527. }
  528. return $newMsgList;
  529. }
  530. //读取json并分析,group
  531. public function readjson_user($json_path = ''){
  532. $json_content = file_get_contents($json_path);
  533. $json_content = json_decode($json_content,true);
  534. $newMsgList = [];
  535. if(isset($json_content['MsgList']) && !empty($json_content['MsgList'])){
  536. $MsgList = $json_content['MsgList'];
  537. foreach($MsgList as $key => $val)
  538. {
  539. $MsgBody = isset($val['MsgBody']) ? json_encode($val['MsgBody'],JSON_UNESCAPED_UNICODE) : '';
  540. $newMsgList[] = [
  541. 'ClientIP' => $val['ClientIP'] ?? '',
  542. 'From_Account' => $val['From_Account'] ?? '',
  543. 'To_Account' => $val['To_Account'] ?? '',
  544. 'MsgBody' => $MsgBody,
  545. 'MsgFromPlatform' => $val['MsgFromPlatform'] ?? '',
  546. 'MsgRandom' => $val['MsgRandom'] ?? '',
  547. 'MsgSeq' => $val['MsgSeq'] ?? '',
  548. 'MsgTimestamp' => $val['MsgTimestamp'] ?? '',
  549. ];
  550. }
  551. }
  552. return $newMsgList;
  553. }
  554. private function postJson(string $uri, array $params = [], array $header = [])
  555. {
  556. $random = rand(10000000, 99999999);
  557. $userSig = $this->usersig($this->config['identifier']);
  558. return CurlUtil::postJson($this->host . $uri . "?sdkappid={$this->config['appid']}&identifier={$this->config['identifier']}&usersig={$userSig}&random={$random}&contenttype=json", $params, $header);
  559. }
  560. /**
  561. * 获取usersig签名-具体操作
  562. */
  563. private function userSig($user_id)
  564. {
  565. // 获取配置信息
  566. $userSigObj = new GetUserSig($this->config["appid"], $this->config["key"]);
  567. return $userSigObj->genUserSig($user_id);
  568. }
  569. }