chenweida 7 vuotta sitten
vanhempi
commit
86a43642b6

+ 75 - 68
common/common-entity/src/main/java/com/yihu/wlyy/entity/gateway/GcToken.java

@ -5,7 +5,9 @@ import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;
@ -17,73 +19,78 @@ import java.util.Date;
@Table(name = "gc_token")
public class GcToken extends IdEntity implements java.io.Serializable {
	// Fields
	private String appid;
	private String token;
	private Date createTime;
	private Date outTime;
	private Integer del;
	// Constructors
	/** default constructor */
	public GcToken() {
	}
	/** full constructor */
	public GcToken(String appid, String token, Date createTime,
			Date outTime, Integer del) {
		this.appid = appid;
		this.token = token;
		this.createTime = createTime;
		this.outTime = outTime;
		this.del = del;
	}
	@Column(name = "appid", length = 200)
	public String getAppid() {
		return this.appid;
	}
	public void setAppid(String appid) {
		this.appid = appid;
	}
	@Column(name = "token")
	public String getToken() {
		return this.token;
	}
	public void setToken(String token) {
		this.token = token;
	}
	@Column(name = "create_time", length = 0)
	public Date getCreateTime() {
		return this.createTime;
	}
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	@Column(name = "out_time", length = 0)
	public Date getOutTime() {
		return this.outTime;
	}
	public void setOutTime(Date outTime) {
		this.outTime = outTime;
	}
	@Column(name = "del")
	public Integer getDel() {
		return this.del;
	}
	public void setDel(Integer del) {
		this.del = del;
	}
    // Fields
    private String appid;
    private String accesstoken;
    private Date createTime;
    private Date outTime;
    private Integer del;
    // Constructors
    /**
     * default constructor
     */
    public GcToken() {
    }
    /**
     * full constructor
     */
    public GcToken(String appid, String accesstoken, Date createTime,
                   Date outTime, Integer del) {
        this.appid = appid;
        this.accesstoken = accesstoken;
        this.createTime = createTime;
        this.outTime = outTime;
        this.del = del;
    }
    @Column(name = "appid", length = 200)
    public String getAppid() {
        return this.appid;
    }
    public void setAppid(String appid) {
        this.appid = appid;
    }
    @Column(name = "accesstoken")
    public String getAccesstoken() {
        return accesstoken;
    }
    public void setAccesstoken(String accesstoken) {
        this.accesstoken = accesstoken;
    }
    @Column(name = "create_time", length = 0)
    public Date getCreateTime() {
        return this.createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    @Column(name = "out_time", length = 0)
    public Date getOutTime() {
        return this.outTime;
    }
    public void setOutTime(Date outTime) {
        this.outTime = outTime;
    }
    @Column(name = "del")
    public Integer getDel() {
        return this.del;
    }
    public void setDel(Integer del) {
        this.del = del;
    }
}

+ 7 - 6
common/common-entity/src/main/java/com/yihu/wlyy/entity/gateway/GcTokenLog.java

@ -24,7 +24,7 @@ public class GcTokenLog extends IdEntity implements java.io.Serializable {
    private String ip;
    private String appIp;
    private String token;
    private String accesstoken;
    private Integer flag; //获取1 成功 0失败
    private String message;
    private Date createTime;
@ -67,13 +67,14 @@ public class GcTokenLog extends IdEntity implements java.io.Serializable {
        this.appIp = appIp;
    }
    @Column(name = "token")
    public String getToken() {
        return token;
    @Column(name = "accesstoken")
    public String getAccesstoken() {
        return accesstoken;
    }
    public void setToken(String token) {
        this.token = token;
    public void setAccesstoken(String accesstoken) {
        this.accesstoken = accesstoken;
    }

+ 19 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/config/SwaggerConfig.java

@ -27,10 +27,12 @@ public class SwaggerConfig {
    private static final String Other_API = "other";
    private static final String GateWay_API = "gateway";
     final String userAgent="{\"id\":用户id,\"uid\":\"用户code\",\"openid\":\"openid\",\"token\":\"token表\",\"lastUid\":\"\",\"platform\":\"1患者APP,2医生APP,3患者微信公众号\"}";
    final String userAgentJson="{\"id\":int,\"uid\":string,\"openid\":string,\"token\":string,\"lastUid\":string,\"platform\":int}";
    final String userAgent = "{\"id\":用户id,\"uid\":\"用户code\",\"openid\":\"openid\",\"token\":\"token表\",\"lastUid\":\"\",\"platform\":\"1患者APP,2医生APP,3患者微信公众号\"}";
    final String userAgentJson = "{\"id\":int,\"uid\":string,\"openid\":string,\"token\":string,\"lastUid\":string,\"platform\":int}";
    @Bean
    public Docket gatewayAPI() {
        List<Parameter> pars = addToken();
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName(GateWay_API)
                .genericModelSubstitutes(DeferredResult.class)
@ -38,8 +40,12 @@ public class SwaggerConfig {
                .forCodeGeneration(true)
                .pathMapping("/")
                .select()
                .paths(or(regex("/wlyygc/.*")))
                .paths(or(
                        regex("/wlyygc/.*"),
                        regex("/gc/.*")
                ))
                .build()
                .globalOperationParameters(pars)
                .apiInfo(gatewayApiInfo());
    }
@ -55,6 +61,16 @@ public class SwaggerConfig {
        return apiInfo;
    }
    private List<Parameter> addToken() {
        ParameterBuilder tokenPar = new ParameterBuilder();
        List<Parameter> pars = new ArrayList<Parameter>();
        tokenPar.name("accesstoken").description("accesstoken").modelRef(new ModelRef("string")).parameterType("header").required(false).defaultValue("").build();
        pars.add(tokenPar.build());
        return pars;
    }
    @Bean
    public Docket publicAPI() {
        List<Parameter> pars = addUseragent();

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/interceptors/GateWayInterceptor.java

@ -47,7 +47,7 @@ public class GateWayInterceptor extends BaseInterceptor {
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String token = request.getParameter("token");
        String token = request.getParameter("accesstoken");
        String ip = NetworkUtil.getIpAddress(request);
        try {
            GcToken gcToken = tokenDao.findByToken(token);

+ 7 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/common/account/TokenService.java

@ -125,5 +125,11 @@ public class TokenService extends BaseService {
	public Token findWxToken(String patient) {
		return tokenDao.findByPatient(patient, 3);
	}
	/**
	 * 查询doctor的微信token标识
	 * @param user
	 */
	public Token findDoctorToken(String user) {
		return tokenDao.findByPatient(user, 2);
	}
}

+ 2 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/gateway/GcTokenService.java

@ -45,7 +45,7 @@ public class GcTokenService {
            gc.setCreateTime(date);
            //2小时过期
            gc.setOutTime(DateUtil.getNextMin(date, 120));
            gc.setToken(token);
            gc.setAccesstoken(token);
            gc.setDel(1);
            tokenDao.save(gc);
@ -55,7 +55,7 @@ public class GcTokenService {
            gcTokenLog.setCreateTime(new Date());
            gcTokenLog.setAppIp(ip);
            gcTokenLog.setMessage("创建token");
            gcTokenLog.setToken(token);
            gcTokenLog.setAccesstoken(token);
            gcTokenLog.setFlag(1);
            tokenLogDao.save(gcTokenLog);
            return gc;

+ 3 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/gateway/controller/GcTokenController.java

@ -27,7 +27,7 @@ import java.io.IOException;
 * 对外的网关
 */
@RestController
@RequestMapping("/wlyygc")
@RequestMapping("/gc")
@Api(description = "token相关服务")
public class GcTokenController {
    @Autowired
@ -35,8 +35,8 @@ public class GcTokenController {
    @Autowired
    private GcClientDetailsService clientDetailsService;
    @ApiOperation("获取token")
    @RequestMapping(value = "token", method = RequestMethod.GET)
    @ApiOperation("获取accesstoken")
    @RequestMapping(value = "accesstoken", method = RequestMethod.GET)
    public ResultOneModel<GcTokenModel> getToken(
            @ApiParam(name = "appid", value = "appid", required = true) @RequestParam(required = true, value = "appid") String appid,
            @ApiParam(name = "appSecret", value = "appSecret", required = true) @RequestParam(required = true, value = "appSecret") String appSecret,

+ 54 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/gateway/controller/GcUserController.java

@ -1,19 +1,33 @@
package com.yihu.wlyy.web.gateway.controller;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.login.LoginLog;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.security.Token;
import com.yihu.wlyy.service.common.account.DoctorService;
import com.yihu.wlyy.service.common.account.PatientService;
import com.yihu.wlyy.service.common.account.RoleService;
import com.yihu.wlyy.service.common.account.TokenService;
import com.yihu.wlyy.service.common.login.LoginLogService;
import com.yihu.wlyy.util.MD5;
import com.yihu.wlyy.util.RSAUtils;
import com.yihu.wlyy.web.gateway.vo.DoctorModel;
import com.yihu.wlyy.web.gateway.vo.PatientModel;
import com.yihu.wlyy.web.gateway.vo.base.BaseResultModel;
import com.yihu.wlyy.web.gateway.vo.base.ResultOneModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * Created by chenweida on 2017/8/17.
 */
@ -25,6 +39,13 @@ public class GcUserController {
    private DoctorService doctorService;
    @Autowired
    private PatientService patientService;
    @Autowired
    private TokenService tokenService;
    @Autowired
    private LoginLogService loginLogService;
    @Autowired
    private RoleService roleService;
    @RequestMapping(value = "/doctor", method = RequestMethod.GET)
    @ApiOperation("根据医生code查询医生信息")
@ -48,5 +69,38 @@ public class GcUserController {
        return new ResultOneModel(patientModel);
    }
    /**
     * 医生登录接口
     *
     * @param account  手机号或者身份证号
     * @param password 密码
     * @return
     */
    @RequestMapping(value = "doctorLogin", method = RequestMethod.POST)
    @ApiOperation("医生端登陆")
    public BaseResultModel doctor(
            @ApiParam(name = "password", value = "密码", required = true) @RequestParam(required = true, value = "password") String password,
            @ApiParam(name = "account", value = "账号", required = true) @RequestParam(required = true, value = "account") String account) {
        Doctor doctor = doctorService.findbyIdCard(account);
        if (doctor == null) {
            doctor = doctorService.findDoctorByMobile(account);
        }
        //账号不存在
        if (doctor == null) {
            return new BaseResultModel(BaseResultModel.codeEm.login_account_error.getCode(), BaseResultModel.codeEm.login_account_error.getMessage());
        }
        //密码错误
        if (!doctor.getPassword().equals(MD5.GetMD5Code(password + doctor.getSalt()))) {
            return new BaseResultModel(BaseResultModel.codeEm.login_password_error.getCode(), BaseResultModel.codeEm.login_password_error.getMessage());
        }
        Token token = tokenService.findDoctorToken(doctor.getCode());
        //判断是否存在token
        if (token!=null){
            //如果token存在直接返回现有的token
        }
        return null;
    }
}

+ 5 - 5
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/gateway/vo/GcTokenModel.java

@ -11,18 +11,18 @@ import java.util.Date;
@ApiModel(description = "")
public class GcTokenModel {
    @ApiModelProperty(value = "请求凭证", required = false, access = "response")
    private String token;
    private String accesstoken;
    @ApiModelProperty(value = "创建时间", required = false, access = "response")
    private Date createTime;
    @ApiModelProperty(value = "过期时间", required = false, access = "response")
    private Date outTime;
    public String getToken() {
        return token;
    public String getAccesstoken() {
        return accesstoken;
    }
    public void setToken(String token) {
        this.token = token;
    public void setAccesstoken(String accesstoken) {
        this.accesstoken = accesstoken;
    }
    public Date getCreateTime() {

+ 9 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/gateway/vo/base/BaseResultModel.java

@ -33,11 +33,17 @@ public class BaseResultModel {
        success(10000, "请求成功"),//请求成功
        error_Appid(-9000, "appid不存在"),//appid不存在
        error_AppSecret(-9001, "AppSecret不存在"),//AppSecret不存在
        error_params(-10000, "请求失败 参数错误"),//请求失败 参数错误
        error_no_ip(-10010, "请求失败,获取IP失败"),//请求失败,获取IP失败
        token_out_effect(-9002, "无效的token"),//token无效
        token_no_power(-9003, "用户没权限"),// 没权限 包括未授权 或者uri错误
        token_out_time(-9004, "oken已过期")//token无效
        token_out_time(-9004, "oken已过期"),//token无效
        error_params(-10000, "请求失败 参数错误"),//请求失败 参数错误
        error_no_ip(-10010, "请求失败,获取IP失败"),//请求失败,获取IP失败
        login_account_error(-20010, "账号不存在"),
        login_password_error(-20020, "密码错误");
        ;
        codeEm(Integer code, String message) {