mirror of
https://gitee.com/elegant_wings/dbd-meeting.git
synced 2025-06-21 17:09:36 +08:00
公众号解绑;修改token有效期
This commit is contained in:
parent
1efc36e6dc
commit
20ef56dd8a
@ -79,6 +79,10 @@ public interface IcsCustomerStaffMapper extends BaseMapper<IcsCustomerStaff> {
|
||||
|
||||
IcsCustomerStaff selectUserByMobileAndParkId(@Param("mobile") String phoneNumber, @Param("parkId") String parkId);
|
||||
|
||||
/**
|
||||
* 清空绑定信息
|
||||
*/
|
||||
int clearGzhOpenid(@Param("openid") String openid);
|
||||
/**
|
||||
* 绑定用户的微信公众号openid
|
||||
* @param mobile 手机号
|
||||
@ -86,4 +90,13 @@ public interface IcsCustomerStaffMapper extends BaseMapper<IcsCustomerStaff> {
|
||||
* @return
|
||||
*/
|
||||
int updateGzhOpenid(@Param("mobile") String mobile,@Param("openid") String openid);
|
||||
|
||||
/**
|
||||
* 根据公众号的openid获取用户
|
||||
* @param openid
|
||||
* @return
|
||||
*/
|
||||
List<IcsCustomerStaff> getUserByGzhOpenid(String openid);
|
||||
|
||||
|
||||
}
|
||||
|
@ -102,5 +102,14 @@ public interface IIcsCustomerStaffService extends IService<IcsCustomerStaff> {
|
||||
*/
|
||||
int updateGzhOpenid(String mobile, String openid);
|
||||
|
||||
// IcsCustomerStaff selectUserByMobileAndParkId(String phoneNumber, String parkId);
|
||||
/**
|
||||
* 解绑
|
||||
*/
|
||||
int clearGzhOpenid(String openid);
|
||||
|
||||
/**
|
||||
* 根据公众号的openid获取用户
|
||||
*/
|
||||
List<IcsCustomerStaff> getUserByGzhOpenid(String openid);
|
||||
|
||||
}
|
||||
|
@ -181,7 +181,6 @@ public class IcsCustomerStaffServiceImpl extends ServiceImpl<IcsCustomerStaffMap
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int updateByCustomer(IcsCustomerStaff customerStaff) {
|
||||
|
||||
@ -195,7 +194,7 @@ public class IcsCustomerStaffServiceImpl extends ServiceImpl<IcsCustomerStaffMap
|
||||
}
|
||||
|
||||
@Override
|
||||
public String importCustomerStaff(List<IcsCustomerStaff> userList,Long customerId) {
|
||||
public String importCustomerStaff(List<IcsCustomerStaff> userList, Long customerId) {
|
||||
|
||||
if (StringUtils.isNull(userList) || userList.size() == 0) {
|
||||
throw new ServiceException("导入用户数据不能为空!");
|
||||
@ -214,13 +213,13 @@ public class IcsCustomerStaffServiceImpl extends ServiceImpl<IcsCustomerStaffMap
|
||||
user.setGender(user.getGender().equals("男") ? "0" : "1");
|
||||
int insert = icsCustomerStaffMapper.insert(user);
|
||||
if (insert > 0) {
|
||||
StaffCustomer staffCustomer =new StaffCustomer();
|
||||
StaffCustomer staffCustomer = new StaffCustomer();
|
||||
staffCustomer.setStaffId(user.getId());
|
||||
staffCustomer.setIcsCustomerId(customerId);
|
||||
StaffCustomer staffCustomer1 = staffCustomerService.selectStaffIdAndCustomerId(customerId, user.getId());
|
||||
if (staffCustomer1 == null) {
|
||||
Customer customer = customerService.selectCustomerById(customerId);
|
||||
if (customer != null){
|
||||
if (customer != null) {
|
||||
staffCustomer.setParkId(customer.getParkId());
|
||||
staffCustomer.setTenantId(customer.getTenantId());
|
||||
}
|
||||
@ -228,7 +227,7 @@ public class IcsCustomerStaffServiceImpl extends ServiceImpl<IcsCustomerStaffMap
|
||||
staffCustomerService.insertStaffCustomer(staffCustomer);
|
||||
}
|
||||
//根据用户添加对应企业设备
|
||||
queryDeviceByCustomerId(customerId,user.getId());
|
||||
queryDeviceByCustomerId(customerId, user.getId());
|
||||
}
|
||||
successNum++;
|
||||
successMsg.append("<br/>" + successNum + "、账号 " + user.getName() + " 导入成功");
|
||||
@ -243,7 +242,7 @@ public class IcsCustomerStaffServiceImpl extends ServiceImpl<IcsCustomerStaffMap
|
||||
u.setDegree(user.getDegree());
|
||||
u.setUrgent(user.getUrgent());
|
||||
int insert = updateByCustomer(u);
|
||||
StaffCustomer staffCustomer =new StaffCustomer();
|
||||
StaffCustomer staffCustomer = new StaffCustomer();
|
||||
staffCustomer.setStaffId(u.getId());
|
||||
staffCustomer.setIcsCustomerId(customerId);
|
||||
|
||||
@ -251,10 +250,10 @@ public class IcsCustomerStaffServiceImpl extends ServiceImpl<IcsCustomerStaffMap
|
||||
if (staffCustomer1 == null) {
|
||||
staffCustomerService.insertStaffCustomer(staffCustomer);
|
||||
//根据用户添加对应企业设备
|
||||
queryDeviceByCustomerId(customerId,u.getId());
|
||||
queryDeviceByCustomerId(customerId, u.getId());
|
||||
successNum++;
|
||||
successMsg.append("<br/>" + successNum + "、账号 " + user.getName() + " 已更新");
|
||||
}else {
|
||||
} else {
|
||||
failureNum++;
|
||||
failureMsg.append("<br/>" + successNum + "、账号 " + user.getName() + "已经存在");
|
||||
}
|
||||
@ -303,14 +302,14 @@ public class IcsCustomerStaffServiceImpl extends ServiceImpl<IcsCustomerStaffMap
|
||||
public List<IcsCustomerStaff> selectUserListByType(String phone) {
|
||||
|
||||
QueryWrapper<IcsCustomerStaff> wrapper = new QueryWrapper<>();
|
||||
wrapper.like(phone != null,"mobile",phone);
|
||||
wrapper.like(phone != null, "mobile", phone);
|
||||
|
||||
return icsCustomerStaffMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
|
||||
//根据企业查询对应的设备
|
||||
public void queryDeviceByCustomerId(Long customerId,Long userId){
|
||||
public void queryDeviceByCustomerId(Long customerId, Long userId) {
|
||||
ArrayList<Long> ids = new ArrayList<>();
|
||||
|
||||
Customer customer = customerService.selectCustomerById(customerId);
|
||||
@ -355,4 +354,14 @@ public class IcsCustomerStaffServiceImpl extends ServiceImpl<IcsCustomerStaffMap
|
||||
public int updateGzhOpenid(String mobile, String openid) {
|
||||
return icsCustomerStaffMapper.updateGzhOpenid(mobile, openid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int clearGzhOpenid(String openid) {
|
||||
return icsCustomerStaffMapper.clearGzhOpenid(openid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IcsCustomerStaff> getUserByGzhOpenid(String openid) {
|
||||
return icsCustomerStaffMapper.getUserByGzhOpenid(openid);
|
||||
}
|
||||
}
|
||||
|
@ -223,10 +223,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</select>
|
||||
|
||||
<!-- 绑定用户的微信公众号openid -->
|
||||
<update id="clearGzhOpenid">
|
||||
<![CDATA[
|
||||
update ics_customer_staff set gzh_openid = null where gzh_openid = #{openid} and delete_flag=0 and data_type is not null and data_type<>'1'
|
||||
]]>
|
||||
</update>
|
||||
<update id="updateGzhOpenid">
|
||||
<![CDATA[
|
||||
update ics_customer_staff set gzh_openid= #{openid} where mobile = #{mobile} and delete_flag=0 and data_type is not null and data_type<>'1'
|
||||
update ics_customer_staff set gzh_openid = #{openid} where mobile = #{mobile} and delete_flag=0 and gzh_openid is null and data_type is not null and data_type<>'1'
|
||||
]]>
|
||||
</update>
|
||||
|
||||
<select id="getUserByGzhOpenid" resultType="com.ics.common.core.domain.IcsCustomerStaff">
|
||||
<include refid="selectIcsCustomerStaffVo"/>
|
||||
WHERE gzh_openid=#{openId} and delete_flag=0
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
@ -28,7 +28,7 @@ public class RedisUtils {
|
||||
/**
|
||||
* 默认过期时长,单位:秒
|
||||
*/
|
||||
public final static long DEFAULT_EXPIRE = 60 * 60 * 24;
|
||||
public final static long DEFAULT_EXPIRE = 60 * 60 * 12;
|
||||
|
||||
/**
|
||||
* 不设置过期时长
|
||||
|
@ -91,11 +91,11 @@ public class LoginController {
|
||||
|
||||
// 签发token
|
||||
Long userId = user.getId();
|
||||
Token token = tokenStore.createNewToken(userId.toString(), menuService.selectPermsStrArray(userId), roleService.selectRoleStrArray(userId), TokenUtil.DEFAULT_EXPIRE_REFRESH_TOKEN);
|
||||
Token token = tokenStore.createNewToken(userId.toString(), menuService.selectPermsStrArray(userId), roleService.selectRoleStrArray(userId), RedisUtils.DEFAULT_EXPIRE);
|
||||
Map<String, Object> map = Maps.newHashMap();
|
||||
map.put("userId", userId);
|
||||
map.put("token", token.getAccessToken());
|
||||
map.put("expire", TokenUtil.DEFAULT_EXPIRE_REFRESH_TOKEN);
|
||||
map.put("expire", RedisUtils.DEFAULT_EXPIRE);
|
||||
|
||||
// 登记在线信息
|
||||
PublishFactory.recordUserOnlineInfo(user, token.getAccessToken());
|
||||
|
@ -61,7 +61,7 @@ public class AccessTokenServiceImpl implements IAccessTokenService {
|
||||
|
||||
// 签发token
|
||||
Long userId = user.getId();
|
||||
Token token = tokenStore.createNewToken(userId.toString(), new String[]{"member:center:view"}, new String[]{"appUser"}, TokenUtil.DEFAULT_EXPIRE_REFRESH_TOKEN);
|
||||
Token token = tokenStore.createNewToken(userId.toString(), new String[]{"member:center:view"}, new String[]{"appUser"}, RedisUtils.DEFAULT_EXPIRE);
|
||||
Map<String, Object> map = Maps.newHashMap();
|
||||
map.put("userId", userId);
|
||||
map.put("token", token.getAccessToken());
|
||||
@ -79,7 +79,7 @@ public class AccessTokenServiceImpl implements IAccessTokenService {
|
||||
public Map<String, Object> createStaffToken(IcsCustomerStaff icsCustomerStaff) {
|
||||
// 签发token
|
||||
Long userId = icsCustomerStaff.getId();
|
||||
Token token = tokenStore.createNewToken(userId.toString(), new String[]{"member:center:view"}, new String[]{"appUser"}, TokenUtil.DEFAULT_EXPIRE_REFRESH_TOKEN);
|
||||
Token token = tokenStore.createNewToken(userId.toString(), new String[]{"member:center:view"}, new String[]{"appUser"}, RedisUtils.DEFAULT_EXPIRE);
|
||||
Map<String, Object> map = Maps.newHashMap();
|
||||
map.put("userId", userId);
|
||||
map.put("token", token.getAccessToken());
|
||||
|
@ -2,6 +2,7 @@ package com.ics.controller.mobile;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ics.admin.service.IIcsCustomerStaffService;
|
||||
import com.ics.common.core.domain.IcsCustomerStaff;
|
||||
import com.ics.common.utils.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@ -17,6 +18,7 @@ import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 微信公众号openid 绑定手机号
|
||||
@ -39,7 +41,9 @@ public class WxBindController {
|
||||
@Value("${webchatGZH.access}")
|
||||
private String access;
|
||||
|
||||
private static String html;
|
||||
private static String removehtml;
|
||||
|
||||
private static String bindhtml;
|
||||
|
||||
@Autowired
|
||||
private IIcsCustomerStaffService customerStaffService;
|
||||
@ -72,9 +76,21 @@ public class WxBindController {
|
||||
String url = String.format(OAUTH2_TOKEN, appid, secret, code);
|
||||
JSONObject result = SmallWxOkHttp.sendGet(url, null);
|
||||
String openid = result.getString("openid");
|
||||
String page = readHtml();
|
||||
List<IcsCustomerStaff> list = customerStaffService.getUserByGzhOpenid(openid);
|
||||
if (list.size() > 0) {//已经绑定的用户
|
||||
String mobile = list.get(0).getMobile();
|
||||
if (StringUtils.isNotBlank(mobile) && mobile.length() == 11) {
|
||||
mobile = mobile.substring(0, 3) + "****" + mobile.substring(7);
|
||||
} else {
|
||||
mobile = "****";
|
||||
}
|
||||
if (StringUtils.isBlank(removehtml)) removehtml = readHtml("removeBind.html");
|
||||
String removeUrl = access + "/wxbind/removeBind";//绑定按钮的提交地址
|
||||
return String.format(removehtml, mobile, removeUrl, openid);
|
||||
}
|
||||
if (StringUtils.isBlank(bindhtml)) bindhtml = readHtml("phoneBind.html");
|
||||
String submitUrl = access + "/wxbind/bind";//绑定按钮的提交地址
|
||||
return String.format(page, submitUrl, openid);
|
||||
return String.format(bindhtml, submitUrl, openid);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -93,13 +109,21 @@ public class WxBindController {
|
||||
return String.format(resultHtml, row > 0 ? "绑定成功" : "绑定失败");
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/removeBind", produces = "text/html;charset=utf-8")
|
||||
public String removeBind(String openid) {
|
||||
String resultHtml = "<html><body><h1>%s</h1></body></html>";
|
||||
int row = customerStaffService.clearGzhOpenid(openid);
|
||||
return String.format(resultHtml, row > 0 ? "解绑成功" : "解绑失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取绑定页面
|
||||
*/
|
||||
private static String readHtml() {
|
||||
if (StringUtils.isNotBlank(html)) return html;
|
||||
private static String readHtml(String fileName) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
ClassPathResource resource = new ClassPathResource("phoneBind.html");
|
||||
ClassPathResource resource = new ClassPathResource(fileName);
|
||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(resource.getInputStream()))) {
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
@ -108,8 +132,7 @@ public class WxBindController {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
html = sb.toString();
|
||||
return html;
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ public class RepairRemindPushServiceImpl implements RepairRemindPushService {
|
||||
data.put("thing37", msg);
|
||||
param.put("data", data);
|
||||
JSONObject result = send(url, JSON.toJSONString(param));
|
||||
System.out.println(result.toString());
|
||||
//System.out.println(result.toString());
|
||||
if (result == null || result.getInteger("errcode") == null || result.getInteger("errcode") != 0) {
|
||||
failed.add(repairRemind.getId());
|
||||
} else {
|
||||
|
79
shoot-hand/ics-web/src/main/resources/removeBind.html
Normal file
79
shoot-hand/ics-web/src/main/resources/removeBind.html
Normal file
@ -0,0 +1,79 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh_CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>工作人员解绑</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.login {
|
||||
|
||||
height: 30.5rem;
|
||||
background-color: white;
|
||||
margin: 0rem;
|
||||
}
|
||||
|
||||
.login_top {
|
||||
color: white;
|
||||
border-radius: 0.5rem 0.5rem 0 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.login_top {
|
||||
color: dodgerblue;
|
||||
}
|
||||
|
||||
.login_bottom {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.login_bottom button {
|
||||
width: 18rem;
|
||||
height: 2.8rem;
|
||||
color: white;
|
||||
margin-top: 2rem;
|
||||
border-radius: 0.6rem;
|
||||
border: none;
|
||||
background: #3490bf;
|
||||
margin-top: 3.6rem;
|
||||
}
|
||||
.login_bottom p span {
|
||||
margin-top: 2rem;
|
||||
color: red;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="box">
|
||||
<div class="login">
|
||||
<div class="login_top">
|
||||
<br/>
|
||||
<h2>解除绑定</h2>
|
||||
</div>
|
||||
<div class="login_bottom">
|
||||
<p style="margin-top: 5rem">
|
||||
<span id="info">您已经绑定手机号:%s</span>
|
||||
</p>
|
||||
<form action="%s" method="post" id="frm">
|
||||
<input type="hidden" name="openid" value="%s">
|
||||
</form>
|
||||
<button onclick="remove()">解绑</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
function remove() {
|
||||
if(confirm("确定要解绑吗?")){
|
||||
document.getElementById("frm").submit();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user