| | |
| | | } |
| | | |
| | | if (type == 2) {//小程序登录 |
| | | String value = (String) redisTemplate.opsForValue().get("appletOpenId"); |
| | | JSONObject jsonObject = null; |
| | | if (ToolUtil.isNotEmpty(value)) { |
| | | jsonObject = JSON.parseObject(value); |
| | | } else { |
| | | jsonObject = new JSONObject(); |
| | | } |
| | | jsonObject.put(userInfo.getId().toString(), userInfo.getAppletsOpenId()); |
| | | redisTemplate.opsForValue().set("appletOpenId", jsonObject.toJSONString()); |
| | | //调用单点登录的逻辑 |
| | | this.singlePointLogin(userInfo.getId(), loginType); |
| | | String token = this.getToken(userInfo, "", loginType); |
| | |
| | | */ |
| | | @Override |
| | | public ResultUtil<LoginWarpper> wxLogins(Integer type, String openid, String unionid, String jscode, String registIp, |
| | | String registAreaCode, Integer sex, String nickName, String avatar,String loginType,String phone,String encryptedData, String iv) throws Exception { |
| | | String registAreaCode, Integer sex, String nickName, String avatar,String loginType, |
| | | String phone,String encryptedData, String iv) throws Exception { |
| | | UserInfo userInfo = null; |
| | | String sessionKey=null; |
| | | if(type == 2){//小程序 |
| | |
| | | }else { |
| | | userInfo.setCompanyId(1); |
| | | } |
| | | if(null == userInfo.getId()){ |
| | | if(null != userInfo.getId()){ |
| | | userInfoMapper.updateById(userInfo); |
| | | }else{ |
| | | this.insert(userInfo); |
| | |
| | | } |
| | | |
| | | if (type == 2) {//小程序登录 |
| | | String value = (String) redisTemplate.opsForValue().get("appletOpenId"); |
| | | JSONObject jsonObject = null; |
| | | if (ToolUtil.isNotEmpty(value)) { |
| | | jsonObject = JSON.parseObject(value); |
| | | } else { |
| | | jsonObject = new JSONObject(); |
| | | } |
| | | jsonObject.put(userInfo.getId().toString(), userInfo.getAppletsOpenId()); |
| | | redisTemplate.opsForValue().set("appletOpenId", jsonObject.toJSONString()); |
| | | //调用单点登录的逻辑 |
| | | this.singlePointLogin(userInfo.getId(), loginType); |
| | | String token = this.getToken(userInfo, "", loginType); |
| | |
| | | return null; |
| | | } |
| | | |
| | | public static String sendGet(String url, String param) { |
| | | String result = ""; |
| | | BufferedReader in = null; |
| | | try { |
| | | String urlNameString = url + "?" + param; |
| | | URL realUrl = new URL(urlNameString); |
| | | // 打开和URL之间的连接 |
| | | URLConnection connection = realUrl.openConnection(); |
| | | |
| | | // 设置通用的请求属性 |
| | | connection.setRequestProperty("accept", "*/*"); |
| | | connection.setRequestProperty("connection", "Keep-Alive"); |
| | | connection.setRequestProperty("User-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"); |
| | | connection.setRequestProperty("Authorization", "Token iVXSeqMEhdYvAj2bgA8tiWdE"); |
| | | // 建立实际的连接 |
| | | connection.connect(); |
| | | // 获取所有响应头字段 |
| | | Map<String, List<String>> map = connection.getHeaderFields(); |
| | | // 遍历所有的响应头字段 |
| | | for (String key : map.keySet()) { |
| | | System.out.println(key + "--->" + map.get(key)); |
| | | } |
| | | // 定义 BufferedReader输入流来读取URL的响应 |
| | | in = new BufferedReader(new InputStreamReader( |
| | | connection.getInputStream())); |
| | | String line; |
| | | while ((line = in.readLine()) != null) { |
| | | result += line; |
| | | } |
| | | } catch (Exception e) { |
| | | System.out.println("发送GET请求出现异常!" + e); |
| | | e.printStackTrace(); |
| | | } |
| | | // 使用finally块来关闭输入流 |
| | | finally { |
| | | try { |
| | | if (in != null) { |
| | | in.close(); |
| | | } |
| | | } catch (Exception e2) { |
| | | e2.printStackTrace(); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 忘记密码操作 |
| | |
| | | userInfo1.setNickName(userInfo.getNickName()); |
| | | userInfo1.setOnconUUID(onconUUID); |
| | | this.updateById(userInfo1); |
| | | |
| | | if (ToolUtil.isNotEmpty(loginType) && loginType.equals("Applets")) {//小程序登录后绑定手机号码 |
| | | String value = (String) redisTemplate.opsForValue().get("appletOpenId"); |
| | | JSONObject jsonObject = null; |
| | | if (ToolUtil.isNotEmpty(value)) { |
| | | jsonObject = JSON.parseObject(value); |
| | | jsonObject.remove(userInfo.getId().toString());//删除原有账号缓存的数据 |
| | | } else { |
| | | jsonObject = new JSONObject(); |
| | | } |
| | | jsonObject.put(userInfo1.getId().toString(), userInfo.getAppletsOpenId()); |
| | | redisTemplate.opsForValue().set("appletOpenId", jsonObject.toJSONString()); |
| | | } |
| | | |
| | | |
| | | |
| | | this.deleteById(userInfo.getId());//删除原有数据 |
| | | //还原之前账号领取的注册优惠券 |
| | |
| | | }else{ |
| | | key = requestHeader; |
| | | } |
| | | String value = (String) redisTemplate.opsForValue().get(key); |
| | | return null != value ? Integer.valueOf(value) : null; |
| | | Object o = redisTemplate.opsForValue().get(key); |
| | | if(null == o || "null".equals(o.toString())){ |
| | | return null; |
| | | } |
| | | return Integer.valueOf(o.toString()); |
| | | }else{ |
| | | return null; |
| | | } |
| | |
| | | return ResultUtil.error("支付金额必须大于0元"); |
| | | } |
| | | if(payType == 1){//微信支付 |
| | | String value = (String) redisTemplate.opsForValue().get("appletOpenId"); |
| | | String appletsOpenId = null; |
| | | if(ToolUtil.isNotEmpty(value)){ |
| | | JSONObject jsonObject = JSON.parseObject(value); |
| | | appletsOpenId = jsonObject.getString(uid.toString()); |
| | | }else{ |
| | | appletsOpenId = userInfo.getAppletsOpenId(); |
| | | } |
| | | Integer integer = paymentRecordService.saveData(2, uid, 1, null, null, 1, money, "", 1);//添加预支付数据 |
| | | String app = type == 1 ? "APP" : "JSAPI"; |
| | | return payMoneyUtil.weixinpay("余额充值", uid.toString(), integer.toString(), money.toString(), "/base/wxCancelUserBalance", app, userInfo.getAppletsOpenId()); |
| | |
| | | Map<String, String> map = weChatUtil.code2Session(jscode); |
| | | String openid = map.get("openid"); |
| | | String unionid = map.get("unionid"); |
| | | //将当前小程序openid存储到缓存中用后面的支付时使用 |
| | | String value = (String) redisTemplate.opsForValue().get("appletOpenId"); |
| | | JSONObject jsonObject = null; |
| | | if(ToolUtil.isNotEmpty(value)){ |
| | | jsonObject = JSON.parseObject(value); |
| | | }else{ |
| | | jsonObject = new JSONObject(); |
| | | } |
| | | jsonObject.put(userId.toString(), openid); |
| | | redisTemplate.opsForValue().set("appletOpenId", jsonObject.toJSONString()); |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | |
| | | * @return |
| | | */ |
| | | private String getToken(UserInfo userInfo, String password,String type) throws Exception{ |
| | | if(ToolUtil.isEmpty(type))type="APP"; |
| | | // 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, ""); |
| | | // 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); |
| | | // 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()), 30, TimeUnit.DAYS); |
| | | redisTemplate.opsForValue().set("USER_" + type + "_" + userInfo.getPhone(), s.substring(s.length() - 32)); |