HereWhiteServiceImpl.java 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package com.ym.service.Impl;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.ym.dao.HereWhiteDao;
  4. import com.ym.mec.util.http.HttpUtil;
  5. import com.ym.pojo.HereWhite;
  6. import com.ym.service.HereWhiteService;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.beans.factory.annotation.Value;
  9. import org.springframework.stereotype.Service;
  10. import java.util.HashMap;
  11. import java.util.Map;
  12. @Service
  13. public class HereWhiteServiceImpl implements HereWhiteService {
  14. @Value("${cn.rongcloud.hereWhite.url}")
  15. private String hereWhiteUrl;
  16. @Value("${cn.rongcloud.hereWhite.token}")
  17. private String hereWhiteToken;
  18. @Autowired
  19. private HereWhiteDao hereWhiteDao;
  20. @Override
  21. public String create(String name, Integer userNum) throws Exception {
  22. JSONObject json = new JSONObject();
  23. json.put("name",name);
  24. json.put("limit",userNum);
  25. json.put("mode","transitory");
  26. String url = "/room?token=" + hereWhiteToken;
  27. return requestParam(json,url);
  28. }
  29. private String requestParam(JSONObject json,String url) throws Exception {
  30. Map<String, String> headers = new HashMap<>(1);
  31. headers.put("Content-Type","application/json");
  32. return HttpUtil.postForHttps(hereWhiteUrl + url, json.toJSONString(), headers);
  33. }
  34. @Override
  35. public HereWhite join(Integer courseScheduleId) throws Exception {
  36. return hereWhiteDao.findById(courseScheduleId);
  37. }
  38. }