wangqifan 3 vuotta sitten
vanhempi
commit
147c556e62

+ 25 - 0
src/main/java/com/izouma/nineth/service/netease/TeamService.java

@@ -12,7 +12,9 @@ import lombok.AllArgsConstructor;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Page;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
+import java.lang.reflect.Member;
 import java.util.HashMap;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Map;
 
 
 @Service
 @Service
@@ -45,4 +47,27 @@ public class TeamService {
         team.setTid(id);
         team.setTid(id);
         return teamRepo.save(team);
         return teamRepo.save(team);
     }
     }
+
+    public Team invite(List<String> invitedIds, String tid) {
+        Team team = teamRepo.findById(Long.valueOf(tid)).orElseThrow(new BusinessException("未找到群聊"));
+        Map<String, String> params = new HashMap<>();
+        params.put("tid", tid);
+        params.put("owner", team.getOwnerid());
+        params.put("members", JSONObject.toJSONString(invitedIds));
+        params.put("magree", "0");
+        params.put("custom", team.getCustom().toString());
+        params.put("msg", "欢迎加入大厅测试群~~");
+        String result = neteaseUserService
+                .httpPost("team/add.action", "application/x-www-form-urlencoded;charset=utf-8", params);
+        JSONObject jsonObject = JSON.parseObject(result);
+        Integer code = jsonObject.getInteger("code");
+        if (code != 200) {
+            throw new BusinessException("注册出错,请核查后重新注册");
+        }
+        Long id = jsonObject.getLong("tid");
+        team.setTid(id);
+        List<String> members = team.getMembers();
+        members.addAll(invitedIds);
+        return teamRepo.save(team);
+    }
 }
 }

+ 7 - 0
src/main/java/com/izouma/nineth/web/Netease/TeamController.java

@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.*;
 
 
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.io.IOException;
+import java.util.Collections;
 import java.util.List;
 import java.util.List;
 
 
 @RestController
 @RestController
@@ -40,6 +41,12 @@ public class TeamController extends BaseController {
         return teamService.create(team);
         return teamService.create(team);
     }
     }
 
 
+    @PostMapping("/invite")
+    public Team inviteSolo(@RequestParam String userId, @RequestParam String tid) {
+        return teamService.invite(Collections.singletonList(userId), tid);
+    }
+
+
     //@PreAuthorize("hasRole('ADMIN')")
     //@PreAuthorize("hasRole('ADMIN')")
     @PostMapping("/all")
     @PostMapping("/all")
     public Page<Team> all(@RequestBody PageQuery pageQuery) {
     public Page<Team> all(@RequestBody PageQuery pageQuery) {