Commit bee44426 by wnb0128

app注册、注销接口代码--think.wang

1 parent 3692987c
//代码生成配置,具体用法参考:http://enilu.gitee.io/web-flash/ecosystem/code-generator.html
{
"codeConfig": {
"type": "com.glsx.code.CodeConfig",
"type": "com.glsx.shop.CodeConfig",
"fields": {
entityModel: "shop-core",
daoModel: "shop-core",
......
package com.glsx.shop.mobile.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.glsx.shop.bean.entity.shop.PlatformCustomer;
import com.glsx.shop.bean.entity.shop.PlatformUser;
import com.glsx.shop.bean.exception.ApplicationExceptionEnum;
import com.glsx.shop.bean.vo.JwtUser;
import com.glsx.shop.bean.vo.front.Rets;
import com.glsx.shop.security.JwtUtil;
import com.glsx.shop.security.UserService;
import com.glsx.shop.service.shop.PlatformCustomerService;
import com.glsx.shop.service.shop.PlatformUserService;
import com.glsx.shop.utils.HttpUtils;
import com.glsx.shop.utils.StringUtil;
import com.glsx.shop.web.controller.BaseController;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
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;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* @author think.wang
* @version 1.0.0
* @Title AppLoginController
* @Package com.glsx.shop.mobile.controller
* @Description AI精灵app登录controller
* @date 2020/12/19
*/
@RestController
@RequestMapping("/appUser")
public class AppLoginController extends BaseController {
@Value("${tu_ya_sync_interface}")
private String syncUserUrl;
@Autowired
private PlatformUserService platformUserService;
@Autowired
private UserService userService;
@Autowired
private PlatformCustomerService customerService;
@RequestMapping(value = "/loginOrRegister", method = RequestMethod.POST)
public Object loginOrRegister(@RequestParam String mobile, @RequestParam String channel) {
if(StringUtil.isEmpty(mobile) || StringUtil.isEmpty(channel)){
return Rets.failure(ApplicationExceptionEnum.PARAM_IS_EMPTY);
}
Map<String, Object> result = new HashMap<>(4);
PlatformCustomer customer = customerService.findByChannelNumber(channel);
if(customer == null){
return Rets.failure(ApplicationExceptionEnum.PARAM_ERROR);
}
JwtUser jwtUser = new JwtUser(); //JWT用户信息封装
Date now =new Date();
PlatformUser user = platformUserService.findByContactNumber(mobile);
if(user != null){
result.put("tuYaId", user.getTuYaId());
jwtUser.setId(user.getId());
jwtUser.setUserName(user.getNickname());
user.setLastLoginTime(now);
if(user.getStatus().equals(0)){ //注销用户重新注册
user.setStatus(1); //用户正常
user.setUpdateTime(now);
user.setCustomerId(customer.getId().intValue());
}
platformUserService.update(user);
}else{ //用户首次注册
PlatformUser pUser = new PlatformUser();
pUser.setContactNumber(mobile);
pUser.setCustomerId(customer.getId().intValue());
pUser.setCreateTime(now);
pUser.setCreateBy(-1);
pUser.setLastLoginTime(now);
Integer tuYaId = this.syncUser(mobile); //同步用户到涂鸦
pUser.setTuYaId(tuYaId);
PlatformUser returnUser = platformUserService.insert(pUser);
jwtUser.setId(returnUser.getId());
result.put("tuYaId", tuYaId);
}
//JWT信息缓存
jwtUser.setPassword(channel);
String token = userService.loginForToken(jwtUser);
result.put("token", token);
return Rets.success(result);
}
private Integer syncUser(String mobile){
JSONObject object = new JSONObject();
object.put("schema", "glsx");
object.put("country_code", "86");
object.put("username", mobile);
object.put("username_type", "1");
// object.put("nick_name", "wnb");
// object.put("password", "dsadada");
try {
logger.info("请求注册涂鸦平台接口地址:{}", syncUserUrl);
String result = HttpUtils.postJson(syncUserUrl, object.toJSONString());
logger.info("注册涂鸦平台返回结果:{}", result);
if (StringUtils.isNotEmpty(result)) {
JSONObject json = JSON.parseObject(result);
if (json.containsKey("result")) {
JSONObject jsonObject = json.getJSONObject("result");
return jsonObject.getInteger("uid");
}
}
} catch (Exception e) {
logger.error("同步涂鸦平台失败:{}", e);
}
return -1;
}
/**
* 注销用户
*
* @return
*/
@RequestMapping(value = "/logout", method = {RequestMethod.POST, RequestMethod.GET})
public Object logout() {
String token = getToken();
Long userId = JwtUtil.getUserId(token);
logger.info("注销用户id: {}", userId);
PlatformUser user = platformUserService.get(userId);
user.setStatus(0); //设置用户注销状态
platformUserService.update(user);
return Rets.success();
}
}
......@@ -26,3 +26,5 @@ fdfs.pool.max-wait-millis=500
fdfs.tracker-list=192.168.3.222:22122
fdfs_tracker_nginx_domain=http://qcimg01.glsx.net:7060
#fdfs_tracker_nginx_port=80
#\u6D82\u9E26\u540C\u6B65\u7528\u6237\u63A5\u53E3
tu_ya_sync_interface=http://192.168.3.137:8091/smartApi/sync_user
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!