Commit 1224e427 by tyfanchz

获取用户 bindKey

1 parent df111acf
......@@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
......@@ -72,4 +73,17 @@ public class UserDeviceController {
boolean success = userDeviceService.deleteDevice(userDevice) > 0;
return R.ok().data(success);
}
/**
* 获取用户 bindKey
*
* @param username 用户名
* @return 结果
*/
@RequestMapping(value = "/getUserBindKey", method = {RequestMethod.GET, RequestMethod.POST})
public R getUserBindKey(@RequestParam String username) {
log.info("$$$$ /userDevice/getUserBindKey param: {}", username);
String userBindKey = userDeviceService.getUserBindKey(username);
return R.ok().data(userBindKey);
}
}
......@@ -17,4 +17,6 @@ public interface SmartUserDeviceService {
int save(SmartUserDevice userDevice);
int deleteDevice(SmartUserDevice userDevice);
String getUserBindKey(String username);
}
......@@ -4,6 +4,9 @@ import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.Date;
import java.util.List;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.common.utils.HttpUtils;
import com.glsx.plat.common.utils.StringUtils;
import com.glsx.smart.dao.entity.SmartUserDevice;
import com.glsx.smart.dao.mapper.SmartUserDeviceMapper;
......@@ -12,6 +15,7 @@ import com.glsx.smart.exception.ResultEnum;
import com.glsx.smart.service.BaseService;
import com.glsx.smart.service.SmartUserDeviceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
......@@ -24,6 +28,12 @@ import org.springframework.stereotype.Service;
@Slf4j
@Service
public class SmartUserDeviceServiceImpl extends BaseService implements SmartUserDeviceService {
@Value("${device_remote_url}")
private String remoteUrl;
@Value("${user_bind_key}")
private String userBindKeyApi;
@Resource
private SmartUserDeviceMapper userDeviceMapper;
......@@ -62,4 +72,18 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
rows = userDeviceMapper.deleteDevice(userDevice);
return rows;
}
@Override
public String getUserBindKey(String username) {
JSONObject reqObj = new JSONObject();
reqObj.put("username", username);
String url = remoteUrl + userBindKeyApi;
log.info("$$$$ getUserBindKey url = {}, req = {}", url, JSON.toJSONString(reqObj));
String respJson = HttpUtils.get(url, reqObj);
log.info("$$$$ getUserBindKey resp = {}", respJson);
JSONObject respObj = JSON.parseObject(respJson);
String bindKey = "200".equals(respObj.getString("code"))
? respObj.getJSONObject("message").getString("bindKey") : null;
return bindKey;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!