Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/target/
.settings/org.eclipse.m2e.core.prefs
.settings/org.eclipse.jdt.core.prefs
.settings/org.eclipse.core.resources.prefs
.project
.classpath
17 changes: 17 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,23 @@
<version>1.18.4</version>
</dependency>

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>3.2.8.RELEASE</version>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.4.1</version>
</dependency>

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.56</version>
</dependency>
</dependencies>

<build>
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/haiyu/manager/ManagerApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

import tk.mybatis.spring.annotation.MapperScan;

@SpringBootApplication
@MapperScan(basePackages = "com.haiyu.manager.dao")
@EnableScheduling
public class ManagerApplication {

public static void main(String[] args) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/haiyu/manager/common/IStatusMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public enum SystemStatus implements IStatusMessage{

SUCCESS("200","SUCCESS"), //请求成功
ERROR("404","ERROR"), //请求失败
PARAM_ERROR("1002","PARAM_ERROR"), //请求参数有误
PARAM_ERROR("1002","参数错误"), //请求参数有误
SUCCESS_MATCH("1003","SUCCESS_MATCH"), //表示成功匹配
NO_LOGIN("1100","NO_LOGIN"), //未登录
MANY_LOGINS("1101","MANY_LOGINS"), //多用户在线(踢出用户)
Expand Down
104 changes: 104 additions & 0 deletions src/main/java/com/haiyu/manager/common/utils/AuthorizationUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.haiyu.manager.common.utils;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

import org.springframework.security.authentication.encoding.Md5PasswordEncoder;

public class AuthorizationUtils {

private static final int SPLITLENGTH = 4;

public static void main(String args[]) throws Exception {
String code = getMachineCode();
String authCode = getAuthCode(code,"2213");
System.out.println("机器码:" + code);
System.out.println("注册码:" + authCode);
}

public static String getMachineCode() {
Set<String> result = new HashSet<>();
result.add(getCpuMachineCode());
String code = new Md5PasswordEncoder().encodePassword(result.toString(), "1234");
return getSplitString(code, "-", 4);

}

/**
* 根据机器码和私盐得到授权码
* @param machineCode
* @return
*/
public static String getAuthCode(String machineCode,String salt) {
String newCode = "(yunshouhuxxx@gmail.com)[" + machineCode.toUpperCase() + "](xxx应用级产品开发平台)";
String code1 = new Md5PasswordEncoder().encodePassword(newCode, salt).toUpperCase() ;
return getSplitString(code1);
}

private static String getSplitString(String str) {
return getSplitString(str, "-", SPLITLENGTH);
}

private static String getSplitString(String str, String split, int length) {
int len = str.length();
StringBuilder temp = new StringBuilder();
for (int i = 0; i < len; i++) {
if (i % length == 0 && i > 0) {
temp.append(split);
}
temp.append(str.charAt(i));
}
String[] attrs = temp.toString().split(split);
StringBuilder finalMachineCode = new StringBuilder();
for (String attr : attrs) {
if (attr.length() == length) {
finalMachineCode.append(attr).append(split);
}
}
return finalMachineCode.toString().substring(0, finalMachineCode.toString().length() - 1);
}


/**
* 获取CPU机器码
* @return
*/
@SuppressWarnings("resource")
private static String getCpuMachineCode() {
String serial = "";
try {
Process process = Runtime.getRuntime().exec(
new String[]{"wmic", "cpu", "get", "ProcessorId"});
process.getOutputStream().close();
Scanner sc = new Scanner(process.getInputStream());
sc.next();
serial = sc.next();
} catch (Exception e) {
e.printStackTrace();
}
return serial;
}

/**
* 随机得到6位数用来作为用户私盐
* @return
*/
public static String getSalt(){
Double d = new Double((Math.random()*9+1)*100000);
int i = d.intValue();
return i+"";
}

/**
* 根据手机号和私盐得到注册码
* @param phone
* @param salt
* @return
*/
public static String getRegisterCode(String phone, String salt) {
String code = new Md5PasswordEncoder().encodePassword(phone, salt).toUpperCase() ;
return getSplitString(code, "-", 4);
}

}
Loading