imApi.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. // 在线状态
  2. export const getOnlineStateFromSvr = (userID) =>
  3. uni.$u?.http.post(
  4. "/user/get_users_status",
  5. JSON.stringify({
  6. userID,
  7. userIDs: [userID],
  8. }),
  9. {
  10. custom: {
  11. isIMApi: true,
  12. },
  13. header: {
  14. token: uni.getStorageSync("IMToken"),
  15. },
  16. }
  17. );
  18. export const getRtcInvitaion = () =>
  19. uni.$u?.http.post(
  20. "/third/get_rtc_invitation_start_app",
  21. JSON.stringify({
  22. operationID: uuidv4(),
  23. }),
  24. {
  25. custom: {
  26. isIMApi: true,
  27. },
  28. header: {
  29. token: uni.getStorageSync("IMToken"),
  30. },
  31. },
  32. );
  33. export const subUserOnlineStatus = (userID, targetID) =>
  34. uni.$u?.http.post(
  35. "/user/subscribe_users_status",
  36. JSON.stringify({
  37. userID,
  38. userIDs: [targetID],
  39. genre: 1,
  40. }),
  41. {
  42. custom: {
  43. isIMApi: true,
  44. },
  45. header: {
  46. token: uni.getStorageSync("IMToken"),
  47. },
  48. }
  49. );
  50. export const unSubUserOnlineStatus = (userID, targetID) =>
  51. uni.$u?.http.post(
  52. "/user/unsubscribe_users_status",
  53. JSON.stringify({
  54. userID,
  55. userIDs: [targetID],
  56. genre: 2,
  57. }),
  58. {
  59. custom: {
  60. isIMApi: true,
  61. },
  62. header: {
  63. token: uni.getStorageSync("IMToken"),
  64. },
  65. },
  66. );
  67. //获取超级管理员token
  68. export const getImAdminToken = () =>
  69. uni.$u?.http.post(
  70. "/auth/get_admin_token",
  71. JSON.stringify({ secret:"openIM123",userID: "imAdmin"}),
  72. {
  73. custom: {
  74. isIMApi: true,
  75. },
  76. header: {
  77. //operationID: Date.now()
  78. }
  79. }
  80. );
  81. //注册IM用户
  82. export const registerImUser = (data) =>
  83. uni.$u?.http.post(
  84. "/user/user_register",
  85. data,
  86. {
  87. custom: {
  88. isIMApi: true,
  89. },
  90. header: {
  91. //operationID: Date.now(),
  92. token:uni.getStorageSync("IMAdminToken"),
  93. },
  94. }
  95. );
  96. //修改IM用户
  97. export const updateImUser = (data) =>
  98. uni.$u?.http.post(
  99. "/user/update_user_info_ex",
  100. data,
  101. {
  102. custom: {
  103. isIMApi: true,
  104. },
  105. header: {
  106. //operationID: Date.now(),
  107. token:uni.getStorageSync("IMAdminToken"),
  108. },
  109. }
  110. );
  111. //获取用户token
  112. export const getImUserToken = (userID) =>
  113. uni.$u?.http.post(
  114. "/auth/get_user_token",
  115. JSON.stringify(
  116. {"platformID": getRuntimePlatform(),"userID": userID}
  117. ),
  118. {
  119. custom: {
  120. isIMApi: true,
  121. },
  122. header: {
  123. //operationID: Date.now(),
  124. token:uni.getStorageSync("IMAdminToken")
  125. },
  126. }
  127. );
  128. //查询用户是否注册
  129. export const imAccountCheck = (userID) =>
  130. uni.$u?.http.post(
  131. "/user/account_check",
  132. JSON.stringify({
  133. checkUserIDs:[ userID ]
  134. }),
  135. {
  136. custom: {
  137. isIMApi: true,
  138. },
  139. header: {
  140. //operationID: Date.now(),
  141. token:uni.getStorageSync("IMAdminToken")
  142. },
  143. }
  144. );
  145. function getRuntimePlatform() {
  146. const systemInfo = uni.getSystemInfoSync();
  147. const compilePlatform = process.env.UNI_PLATFORM;
  148. //1:iOS,2:Android,3:Windows,4:OSX,5:WEB,6:小程序,7:linux,8:AndroidPad,9:IPad,10:Admin
  149. let platformType=6;
  150. // H5 环境
  151. if (compilePlatform === 'h5') platformType= 5;
  152. // 小程序环境
  153. if (compilePlatform.startsWith('mp-')) {
  154. const mpType = compilePlatform.split('-')[1]; // 如 weixin/alipay
  155. platformType=6;
  156. // return `小程序(${mpType})- ${systemInfo.platform}`;
  157. }
  158. // App 环境
  159. if (compilePlatform === 'app-plus') {
  160. if(systemInfo.platform.toLowerCase() === 'android'){
  161. platformType=2;
  162. }
  163. if(systemInfo.platform.toLowerCase() === 'ios'){
  164. platformType=1;
  165. }
  166. }
  167. return platformType;
  168. }