| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.google.common.util.concurrent.RateLimiter; |
| | | import com.google.gson.Gson; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | |
| | | |
| | | |
| | | @RequestMapping(value = "/getToken",method = RequestMethod.POST) |
| | | public Msg listWithNotStatus(@RequestBody ReqParams reqParams){ |
| | | public Msg getToken(@RequestBody ReqParams reqParams) { |
| | | rateLimiter.acquire(1); |
| | | |
| | | Long userId = accessService.getUserId(reqParams.getAccessToken()); |
| | |
| | | System.out.println(post02); |
| | | JSONObject data = JSON.parseObject(JSON.parseObject(post02).getString("data")); |
| | | |
| | | // System.out.println(data); |
| | | |
| | | // System.out.println(data.get("accessToken")); |
| | | // accessService.setYs7Token((String) data.get("accessToken"), reqParams.getAccessToken()); |
| | | |
| | | return Msg.ok(data); |
| | | } |
| | | |
| | | |
| | | @RequestMapping("/getLiveAddress") |
| | | public Msg getUrl(@RequestBody ReqParams reqParams){ |
| | | System.out.println(reqParams.toString()); |
| | | rateLimiter.acquire(1); |
| | | |
| | | Long userId = accessService.getUserId(reqParams.getAccessToken()); |
| | | |
| | | |
| | | if (userId == null) { |
| | | return Msg.error("accessToken exception!!!"); |
| | | } |
| | | |
| | | Map<String, String> parms = new HashMap<>(2); |
| | | |
| | | parms.put("appKey", "51a534ebadf54c31a0848dc575dfa206"); |
| | | parms.put("appSecret", "8c32c67a73c87b9e461b2e3bdf58967a"); |
| | | String post = HttpUtil.httpRequestToString("https://open.ys7.com/api/lapp/token/get", "post", parms); |
| | | String accessToken = JSON.parseObject(JSON.parseObject(post).getString("data")).getString("accessToken"); |
| | | |
| | | |
| | | //子accesstoken |
| | | |
| | | String ys7AccountId = accessService.getYs7AccountId(reqParams.getAccessToken()); |
| | | |
| | | Map<String, String> parms02 = new HashMap<>(2); |
| | | |
| | | parms02.put("accessToken", accessToken); |
| | | parms02.put("accountId", ys7AccountId); |
| | | String post02 = HttpUtil.httpRequestToString("https://open.ys7.com/api/lapp/ram/token/get", "post", parms02); |
| | | System.out.println(post02); |
| | | JSONObject data = JSON.parseObject(JSON.parseObject(post02).getString("data")); |
| | | |
| | | //可以单独传入http参数,这样参数会自动做URL编码,拼接在URL中 |
| | | HashMap<String, Object> paramMap = new HashMap<>(); |
| | | paramMap.put("accessToken", data.get("accessToken")); |
| | | paramMap.put("deviceSerial", reqParams.getDeviceSerial()); |
| | | paramMap.put("protocol", 2); |
| | | paramMap.put("expireTime", 720 * 60 * 60 * 24); |
| | | paramMap.put("quality", 1); |
| | | |
| | | |
| | | try { |
| | | String result = |
| | | cn.hutool.http.HttpUtil.post |
| | | ("https://open.ys7.com/api/lapp/v2/live/address/get", paramMap); |
| | | |
| | | System.out.println(result); |
| | | JSONObject url = JSON.parseObject(JSON.parseObject(result).getString("data")); |
| | | |
| | | return Msg.ok(url); |
| | | } catch (Exception e) { |
| | | return Msg.error(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |