Commit 5e695942 by 徐高华

企微托管账号

parent 2c87140f
package com.gic.haoban.manage.api.enums;
public enum QwOpenStepEnum {
step1(1, "用户已扫码"),
step2(2,"取消登录"),
step3(3,"超时未扫码") ,
step4(4,"验证码正确") ;
QwOpenStepEnum(Integer step, String desc){
this.step = step;
this.desc = desc;
}
private int step;
private String desc;
public int getStep() {
return step;
}
public void setStep(int step) {
this.step = step;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}
......@@ -35,6 +35,19 @@ public interface OpenStaffApiService {
*/
public ServiceResponse<Void> updateValiFlag(String uuid) ;
/**
* 设置需要二次验证扫码
* @param uuid
* @return
*/
public ServiceResponse<Void> update2QrcodeFlag(String uuid) ;
/**
* 获取二次验证码
* @param id
* @return
*/
public ServiceResponse<OpenStaffDTO> get2Qrcode(long id) ;
/**
* 登录成功
......@@ -57,9 +70,9 @@ public interface OpenStaffApiService {
/**
*
* @param uuid
* @param loginStatus
* @param step
* @return
*/
public ServiceResponse<Void> updateLoginStatus(String uuid , int loginStatus) ;
public ServiceResponse<Void> updateLoginStep(String uuid , int step) ;
}
......@@ -5,6 +5,7 @@ import com.gic.authcenter.commons.util.IgnoreLogin;
import com.gic.commons.util.GlobalVar;
import com.gic.commons.util.HttpClient;
import com.gic.haoban.common.utils.HaobanResponse;
import com.gic.haoban.manage.api.enums.QwOpenStepEnum;
import com.gic.haoban.manage.api.service.OpenStaffApiService;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
......@@ -31,7 +32,7 @@ public class QywxCallbackController extends WebBaseController {
@RequestMapping("qywx-msg-notice")
@IgnoreLogin
public Object callback(HttpServletRequest request , HttpServletResponse response) throws IOException {
public Object callback(HttpServletRequest request , HttpServletResponse response) {
try {
String body = IOUtils.toString(request.getInputStream()) ;
logger.info("企微消息下发={}",body);
......@@ -82,13 +83,15 @@ public class QywxCallbackController extends WebBaseController {
}
private void v100012(String uuid , JSONObject json) {
logger.info("需要二次扫码");
this.openStaffApiService.update2QrcodeFlag(uuid) ;
}
private void v100009(String uuid , JSONObject json) {
logger.info("超时未扫码关闭");
this.openStaffApiService.updateLoginStep(uuid, QwOpenStepEnum.step3.getStep()) ;
}
private void v100001(String uuid , JSONObject json) {
logger.info("用户扫码={}",uuid);
this.openStaffApiService.updateLoginStep(uuid,QwOpenStepEnum.step1.getStep()) ;
}
private void v100004(String uuid , JSONObject json) {
logger.info("需要输入验证码校验={}",uuid);
......@@ -96,6 +99,7 @@ public class QywxCallbackController extends WebBaseController {
}
private void v100002(String uuid , JSONObject json) {
logger.info("验证码校验成功返回={}",uuid);
this.openStaffApiService.updateLoginStep(uuid,QwOpenStepEnum.step4.getStep()) ;
}
private void loginSuccess(String uuid , JSONObject json) {
logger.info("登录成功={}",uuid);
......@@ -110,6 +114,7 @@ public class QywxCallbackController extends WebBaseController {
}
private void v100003(String uuid , JSONObject json) {
logger.info("取消登录={}",uuid);
this.openStaffApiService.updateLoginStep(uuid,QwOpenStepEnum.step2.getStep()) ;
}
}
......@@ -25,4 +25,10 @@ public interface OpenStaffMapper {
void updateValiFlag(@Param("uuid")String uuid);
TabOpenStaff getById(Long openStaffId);
void update2QrcodeFlag(@Param("id") Long openStaffId);
void update2Qrcode(@Param("id") Long id , @Param("qrcode")String qrcode , @Param("key")String key) ;
void updateLoginStep(@Param("id")Long openStaffId, @Param("step")int step);
}
\ No newline at end of file
......@@ -51,7 +51,44 @@ public class OpenStaffApiServiceImpl implements OpenStaffApiService {
}
@Override
public ServiceResponse<Void> updateLoginStatus(String uuid, int loginStatus) {
public ServiceResponse<Void> update2QrcodeFlag(String uuid) {
TabOpenStaff openStaff = this.openStaffMapper.getByUUID(uuid) ;
if(null == openStaff) {
log.info("通过uuid查不到={}",uuid);
return ServiceResponse.failure("9999","登录错误") ;
}
this.openStaffMapper.update2QrcodeFlag(openStaff.getOpenStaffId());
return ServiceResponse.success();
}
@Override
public ServiceResponse<OpenStaffDTO> get2Qrcode(long id) {
TabOpenStaff openStaff = this.openStaffMapper.getById(id) ;
if(null == openStaff) {
return ServiceResponse.failure("9999","登录错误") ;
}
ServiceResponse<QwOpenResultInitBO> resp = OpenUtils.getQrcode(openStaff.getUuid(),null,2) ;
if(resp.isSuccess()) {
String qrcode= resp.getResult().getQrcode() ;
String key = resp.getResult().getKey() ;
this.openStaffMapper.update2Qrcode(openStaff.getOpenStaffId(),qrcode,key);
openStaff.setQrCode2(qrcode);
}else {
return ServiceResponse.failure("9999",resp.getMessage()) ;
}
OpenStaffDTO dto = EntityUtil.changeEntityByJSON(OpenStaffDTO.class,openStaff) ;
return ServiceResponse.success(dto);
}
@Override
public ServiceResponse<Void> updateLoginStep(String uuid, int step) {
TabOpenStaff openStaff = this.openStaffMapper.getByUUID(uuid) ;
if(null == openStaff) {
log.info("通过uuid查不到={}",uuid);
OpenUtils.logout(uuid);
return ServiceResponse.failure("9999","登录错误") ;
}
this.openStaffMapper.updateLoginStep(openStaff.getOpenStaffId(),step) ;
return ServiceResponse.success();
}
......@@ -83,6 +120,15 @@ public class OpenStaffApiServiceImpl implements OpenStaffApiService {
@Override
public ServiceResponse<Void> logout(String uuid) {
TabOpenStaff openStaff = this.openStaffMapper.getByUUID(uuid) ;
if(null == openStaff) {
log.info("通过uuid查不到={}",uuid);
OpenUtils.logout(uuid);
return ServiceResponse.failure("9999","登录错误") ;
}
openStaff.setStep(0);
openStaff.setStatusFlag(2);
this.openStaffMapper.update(openStaff) ;
return ServiceResponse.success();
}
......@@ -116,22 +162,25 @@ public class OpenStaffApiServiceImpl implements OpenStaffApiService {
try {
RedisUtil.lock(lockKey , 3L);
TabOpenStaff openStaff = this.openStaffMapper.getByStaffId(staffId) ;
Long qwUserId = null ;
if(null != openStaff) {
qwUserId = openStaff.getQwUserId() ;
log.info("重新初始化,退出登录");
OpenUtils.logout(openStaff.getUuid());
}
if(null == openStaff) {
openStaff = new TabOpenStaff() ;
openStaff.setStaffId(staffId);
openStaff.setWxEnterpriseId(qdto.getWxEnterpriseId());
openStaff.setEnterpriseId(qdto.getEnterpriseId());
}
Long qwUserId = null ;
if(null != openStaff) {
qwUserId = openStaff.getQwUserId() ;
}
ServiceResponse<QwOpenResultInitBO> resp = OpenUtils.init(qwUserId) ;
log.info("resp={}", JSONObject.toJSONString(resp));
QwOpenResultInitBO init = resp.getResult() ;
openStaff.setUuid(init.getUuid());
openStaff.setQrCode1(init.getQrcode());
openStaff.setKey1(init.getKey());
openStaff.setStep(0);
openStaff = this.openStaffService.save(openStaff);
return ServiceResponse.success(openStaff.getOpenStaffId()) ;
}catch (Exception e) {
......
......@@ -36,7 +36,7 @@ public class OpenUtils {
// 设置回调
setCallback(uuid);
// 获取二维码
ServiceResponse<QwOpenResultInitBO> response = getQrcode(uuid,initBO) ;
ServiceResponse<QwOpenResultInitBO> response = getQrcode(uuid,initBO,1) ;
if(!response.isSuccess()) {
return response ;
}
......@@ -72,19 +72,26 @@ public class OpenUtils {
logger.info("设置回调={},uuid={}",backJson,uuid);
}
private static ServiceResponse<QwOpenResultInitBO> getQrcode(String uuid , QwOpenResultInitBO initBO) {
public static ServiceResponse<QwOpenResultInitBO> getQrcode(String uuid , QwOpenResultInitBO initBO , int times) {
String req = "getQrCode" ;
if(times==2) {
req = "SecondaryValidation" ;
}
JSONObject json = new JSONObject() ;
json.put("uuid",uuid) ;
String backJson = HttpClient.sendPostJSON(String.format(openHost,"getQrCode"),json.toJSONString(),"utf-8") ;
logger.info("获取qrcode={},uuid={}",backJson,uuid);
String backJson = HttpClient.sendPostJSON(String.format(openHost,req),json.toJSONString(),"utf-8") ;
logger.info("获取qrcode={},uuid={},times={}",backJson,uuid,times);
QwOpenResultBO initResult = result(backJson) ;
if(!initResult.isOk()) {
return ServiceResponse.failure("9999",initResult.getErrmsg()) ;
}
QwOpenResultInitBO backBO = JSONObject.parseObject(initResult.getData().toString(), QwOpenResultInitBO.class) ;
if(null == initBO) {
return ServiceResponse.success(backBO) ;
}
initBO.setQrcode(backBO.getQrcode());
initBO.setKey(backBO.getKey());
return ServiceResponse.success() ;
return ServiceResponse.success(initBO) ;
}
private static QwOpenResultBO result(String json) {
......
......@@ -66,6 +66,17 @@
update tab_haoban_open_staff set valid_flag = 1 where uuid = #{uuid}
</update>
<update id="update2QrcodeFlag">
update tab_haoban_open_staff set valid_qrcode_flag = 1 where id = #{id}
</update>
<update id="update2Qrcode">
update tab_haoban_open_staff set qr_code_2 = #{qrCode} , key_2 = #{key} where id = #{id}
</update>
<update id="updateLoginStep">
update tab_haoban_open_staff set step = #{step} where open_staff_id = #{id}
</update>
<delete id="deleteByPrimaryKey">
update tab_haoban_open_staff set delete_flag = 1 , update_time =now() where open_staff_id = #{id}
</delete>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment