|
|
@@ -10,6 +10,7 @@ import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.shiro.crypto.hash.SimpleHash;
|
|
|
import org.springframework.http.HttpMethod;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
@@ -361,4 +362,27 @@ public class AppUserController extends BaseApiController {
|
|
|
res.setData(demandService.selectDemandDetail( id));
|
|
|
return res;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取环信登录账号,如果未注册则先注册
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/easemob", method = RequestMethod.GET)
|
|
|
+ public Result getEasemob() {
|
|
|
+ User u = TokenManager.getUserToken();
|
|
|
+ if (u != null) {
|
|
|
+ JSONObject res = easemobUtils.send(new EasemobInfo().uri("/users/" + u.getNumber()).method(HttpMethod.GET));
|
|
|
+ JSONObject resultObj = new JSONObject();
|
|
|
+ resultObj.put("easemobPass", new SimpleHash("md5", u.getId(), null, 1).toHex());
|
|
|
+ resultObj.put("easemobName", String.valueOf(u.getNumber()));
|
|
|
+ resultObj.put("nickname", StringUtils.isBlank(u.getNickname()) ? "技淘用户" + u.getNumber() : u.getNickname());
|
|
|
+ if (res == null || StringUtils.equals("service_resource_not_found", (CharSequence) res.get("error"))) {
|
|
|
+ easemobUtils.sendLater(
|
|
|
+ new EasemobInfo().uri("/users/").data(resultObj.toJSONString()).method(HttpMethod.POST));
|
|
|
+ }
|
|
|
+ return res().data(resultObj);
|
|
|
+ } else {
|
|
|
+ return res().error(buildError("user only", "必须是登录会员才能访问。"));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|