| | |
| | | import com.stylefeng.guns.modular.system.model.*; |
| | | import com.stylefeng.guns.modular.system.service.*; |
| | | import com.stylefeng.guns.modular.system.util.*; |
| | | import com.stylefeng.guns.modular.system.util.qianyuntong.SMSUtil; |
| | | import com.stylefeng.guns.modular.system.warpper.LoginWarpper; |
| | | import com.stylefeng.guns.modular.taxi.model.PaymentRecord; |
| | | import com.stylefeng.guns.modular.taxi.service.IPaymentRecordService; |
| | |
| | | import org.apache.shiro.util.ByteSource; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.crypto.Cipher; |
| | |
| | | import java.security.spec.AlgorithmParameterSpec; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.concurrent.locks.Lock; |
| | | import java.util.concurrent.locks.ReentrantLock; |
| | | |
| | |
| | | private UserActivityInviteMapper userActivityInviteMapper; |
| | | |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | private RedisTemplate redisTemplate; |
| | | |
| | | @Autowired |
| | | private ALiSendSms aLiSendSms; |
| | |
| | | templateCode = "SMS_154775431";//修改密码 |
| | | break; |
| | | } |
| | | String sData = aLiSendSms.sendSms(phone, "SMS_229715276", "{\"code\":\"" + authCode + "\"}"); |
| | | JSONObject jsonObject = JSON.parseObject(sData); |
| | | String message = jsonObject.getString("Message"); |
| | | if(!"OK".equals(message)){ |
| | | System.err.println(message); |
| | | return ResultUtil.error(message); |
| | | } |
| | | // String sData = aLiSendSms.sendSms(phone, "SMS_229715276", "{\"code\":\"" + authCode + "\"}"); |
| | | // JSONObject jsonObject = JSON.parseObject(sData); |
| | | // String message = jsonObject.getString("Message"); |
| | | // if(!"OK".equals(message)){ |
| | | // System.err.println(message); |
| | | // return ResultUtil.error(message); |
| | | // } |
| | | SMSUtil.sendVerifyCode(phone); |
| | | String sms = "短信验证码【" + authCode + "】已发到您的手机,验证码将在5分钟后失效,请及时登录!"; |
| | | //发送验证码短信 |
| | | redisUtil.setStrValue(phone, authCode, 5 * 60);//设置五分钟过期 |
| | | redisTemplate.opsForValue().set(phone, authCode, 5, TimeUnit.MINUTES);//设置五分钟过期 |
| | | System.out.println("【" + phone + "】" + sms); |
| | | return ResultUtil.success(); |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | public boolean checkCaptcha(String phone, String code) throws Exception { |
| | | Object value = redisUtil.getValue(phone); |
| | | Object value = redisTemplate.opsForValue().get(phone); |
| | | if("1234".equals(code)){ |
| | | return true; |
| | | } |
| | |
| | | } |
| | | |
| | | if(type == 2){//小程序登录 |
| | | String value = redisUtil.getValue("appletOpenId"); |
| | | String value = (String) redisTemplate.opsForValue().get("appletOpenId"); |
| | | JSONObject jsonObject = null; |
| | | if(ToolUtil.isNotEmpty(value)){ |
| | | jsonObject = JSON.parseObject(value); |
| | |
| | | jsonObject = new JSONObject(); |
| | | } |
| | | jsonObject.put(userInfo.getId().toString(), userInfo.getAppletsOpenId()); |
| | | redisUtil.setStrValue("appletOpenId", jsonObject.toJSONString()); |
| | | redisTemplate.opsForValue().set("appletOpenId", jsonObject.toJSONString()); |
| | | } |
| | | |
| | | //调用单点登录的逻辑 |
| | |
| | | } |
| | | |
| | | if(type == 2){//小程序登录 |
| | | String value = redisUtil.getValue("appletOpenId"); |
| | | String value = (String) redisTemplate.opsForValue().get("appletOpenId"); |
| | | JSONObject jsonObject = null; |
| | | if(ToolUtil.isNotEmpty(value)){ |
| | | jsonObject = JSON.parseObject(value); |
| | |
| | | jsonObject = new JSONObject(); |
| | | } |
| | | jsonObject.put(userInfo.getId().toString(), userInfo.getAppletsOpenId()); |
| | | redisUtil.setStrValue("appletOpenId", jsonObject.toJSONString()); |
| | | redisTemplate.opsForValue().set("appletOpenId", jsonObject.toJSONString()); |
| | | } |
| | | |
| | | //调用单点登录的逻辑 |
| | |
| | | this.updateById(userInfo1); |
| | | |
| | | if(ToolUtil.isNotEmpty(loginType) && loginType.equals("Applets")){//小程序登录后绑定手机号码 |
| | | String value = redisUtil.getValue("appletOpenId"); |
| | | String value = (String) redisTemplate.opsForValue().get("appletOpenId"); |
| | | JSONObject jsonObject = null; |
| | | if(ToolUtil.isNotEmpty(value)){ |
| | | jsonObject = JSON.parseObject(value); |
| | |
| | | jsonObject = new JSONObject(); |
| | | } |
| | | jsonObject.put(userInfo1.getId().toString(), userInfo.getAppletsOpenId()); |
| | | redisUtil.setStrValue("appletOpenId", jsonObject.toJSONString()); |
| | | redisTemplate.opsForValue().set("appletOpenId", jsonObject.toJSONString()); |
| | | } |
| | | |
| | | |
| | |
| | | }else{ |
| | | key = requestHeader; |
| | | } |
| | | String value = redisUtil.getValue(key); |
| | | String value = (String) redisTemplate.opsForValue().get(key); |
| | | return null != value ? Integer.valueOf(value) : null; |
| | | }else{ |
| | | return null; |
| | |
| | | return ResultUtil.error("支付金额必须大于0元"); |
| | | } |
| | | if(payType == 1){//微信支付 |
| | | String value = redisUtil.getValue("appletOpenId"); |
| | | String value = (String) redisTemplate.opsForValue().get("appletOpenId"); |
| | | String appletsOpenId = null; |
| | | if(ToolUtil.isNotEmpty(value)){ |
| | | JSONObject jsonObject = JSON.parseObject(value); |
| | |
| | | String openid = map.get("openid"); |
| | | String unionid = map.get("unionid"); |
| | | //将当前小程序openid存储到缓存中用后面的支付时使用 |
| | | String value = redisUtil.getValue("appletOpenId"); |
| | | String value = (String) redisTemplate.opsForValue().get("appletOpenId"); |
| | | JSONObject jsonObject = null; |
| | | if(ToolUtil.isNotEmpty(value)){ |
| | | jsonObject = JSON.parseObject(value); |
| | |
| | | jsonObject = new JSONObject(); |
| | | } |
| | | jsonObject.put(userId.toString(), openid); |
| | | redisUtil.setStrValue("appletOpenId", jsonObject.toJSONString()); |
| | | redisTemplate.opsForValue().set("appletOpenId", jsonObject.toJSONString()); |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | |
| | | return "JYX" + String.valueOf(num).substring(1); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取token |
| | | * @param userInfo |
| | | * @param password |
| | | * @return |
| | | * 单点登录 |
| | | * @param id |
| | | */ |
| | | private String getToken(UserInfo userInfo, String password,String type) throws Exception{ |
| | | private void singlePointLogin(Integer id,String type) throws Exception{ |
| | | if(ToolUtil.isEmpty(type))type="APP"; |
| | | //封装请求账号密码为shiro可验证的token |
| | | UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(userInfo.getPhone(), password.toCharArray()); |
| | | String credentials = userInfo.getPassWord(); |
| | | ByteSource credentialsSalt = new Md5Hash(salt); |
| | | SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo( |
| | | new ShiroUser(), credentials, credentialsSalt, ""); |
| | | |
| | | //校验用户账号密码 |
| | | HashedCredentialsMatcher md5CredentialsMatcher = new HashedCredentialsMatcher(); |
| | | md5CredentialsMatcher.setHashAlgorithmName(ShiroKit.hashAlgorithmName); |
| | | md5CredentialsMatcher.setHashIterations(ShiroKit.hashIterations); |
| | | boolean passwordTrueFlag = md5CredentialsMatcher.doCredentialsMatch( |
| | | usernamePasswordToken, simpleAuthenticationInfo); |
| | | String s = JwtTokenUtil.generateToken(String.valueOf(userInfo.getId())); |
| | | redisUtil.setStrValue(s.substring(s.length() - 32), String.valueOf(userInfo.getId()), 180 * 24 * 60 * 60); |
| | | redisUtil.setStrValue("USER_"+type+"_" + userInfo.getPhone(), s.substring(s.length() - 32)); |
| | | redisUtil.setStrValue("USER_"+type +"_"+ userInfo.getId(), s); |
| | | return s; |
| | | //开始验证当前账号是否在别处登录 |
| | | String value = (String) redisTemplate.opsForValue().get("USER_" + type + "_" + id); |
| | | if(ToolUtil.isNotEmpty(value)) {//将另外设备上的强迫下线 |
| | | //开始清除redis中无效的数据 |
| | | UserInfo userInfo = userInfoMapper.selectById(id); |
| | | String key = (String) redisTemplate.opsForValue().get("USER_" + type + "_" + userInfo.getPhone()); |
| | | redisTemplate.delete(key);//删除个人信息数据 |
| | | redisTemplate.delete("USER_" + type + "_" + userInfo.getPhone());//删除后台冻结相关缓存 |
| | | redisTemplate.delete("USER_" + type + "_" + id);//清除存储的token |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 单点登录 |
| | | * @param id |
| | | * 获取token |
| | | * @param userInfo |
| | | * @param password |
| | | * @return |
| | | */ |
| | | private void singlePointLogin(Integer id,String type) throws Exception{ |
| | | private String getToken(UserInfo userInfo, String password,String type) throws Exception{ |
| | | if(ToolUtil.isEmpty(type))type="APP"; |
| | | //开始验证当前账号是否在别处登录 |
| | | String value = redisUtil.getValue("USER_"+type+"_" + id); |
| | | if(ToolUtil.isNotEmpty(value)){//将另外设备上的强迫下线 |
| | | //开始清除redis中无效的数据 |
| | | UserInfo userInfo = userInfoMapper.selectById(id); |
| | | String key = redisUtil.getValue("USER_"+type+"_" + userInfo.getPhone()); |
| | | redisUtil.remove(key);//删除个人信息数据 |
| | | redisUtil.remove("USER_"+type+"_" + userInfo.getPhone());//删除后台冻结相关缓存 |
| | | redisUtil.remove("USER_"+type+"_" + id);//清除存储的token |
| | | } |
| | | //封装请求账号密码为shiro可验证的token |
| | | UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(userInfo.getPhone(), password.toCharArray()); |
| | | String credentials = userInfo.getPassWord(); |
| | | ByteSource credentialsSalt = new Md5Hash(salt); |
| | | SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo( |
| | | new ShiroUser(), credentials, credentialsSalt, ""); |
| | | |
| | | //校验用户账号密码 |
| | | HashedCredentialsMatcher md5CredentialsMatcher = new HashedCredentialsMatcher(); |
| | | md5CredentialsMatcher.setHashAlgorithmName(ShiroKit.hashAlgorithmName); |
| | | md5CredentialsMatcher.setHashIterations(ShiroKit.hashIterations); |
| | | boolean passwordTrueFlag = md5CredentialsMatcher.doCredentialsMatch( |
| | | usernamePasswordToken, simpleAuthenticationInfo); |
| | | String s = JwtTokenUtil.generateToken(String.valueOf(userInfo.getId())); |
| | | redisTemplate.opsForValue().set(s.substring(s.length() - 32), String.valueOf(userInfo.getId()), 180, TimeUnit.DAYS); |
| | | redisTemplate.opsForValue().set("USER_" + type + "_" + userInfo.getPhone(), s.substring(s.length() - 32)); |
| | | redisTemplate.opsForValue().set("USER_" + type + "_" + userInfo.getId(), s); |
| | | return s; |
| | | } |
| | | |
| | | @Override |