admin
2020-06-17 87b391b8a81ee2abdaa4131d245784ecc7a54e9a
用户系统与卡密系统完善
7个文件已修改
37个文件已添加
3799 ■■■■■ 已修改文件
pom.xml 71 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/controller/ParseController.java 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/controller/SDLJGoodsController.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/controller/UserController.java 141 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/dao/BaseMapper.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/dao/mybatis/user/CardPwdInfoMapper.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/dao/mybatis/user/SDLJShareOpenHistoryMapper.java 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/dao/mybatis/user/UserInfoMapper.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/entity/user/CardPwdInfo.java 93 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/entity/user/CardPwdTypeEnum.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/entity/user/SDLJShareOpenHistory.java 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/entity/user/UserInfo.java 107 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/exception/BaseException.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/exception/CardPwdException.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/exception/SDLJShareOpenHistoryException.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/exception/TBCookieException.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/exception/UserException.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/service/impl/user/CardPwdImpl.java 54 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/service/impl/user/SDLJShareOpenHistoryServiceImpl.java 44 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/service/impl/user/UserServiceImpl.java 80 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/service/impl/user/UserUpgradeServiceImpl.java 58 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/service/user/CardPwdService.java 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/service/user/SDLJShareOpenHistoryService.java 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/service/user/UserService.java 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/service/user/UserUpgradeService.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/util/AESUtil.java 193 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/util/CardPwdUtil.java 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/util/FirstOrderSubDataUtil.java 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/util/HttpUtil.java 470 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/util/StringUtil.java 525 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/util/TBCookieUtil.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/util/TimeUtil.java 384 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/util/UserUtil.java 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/util/VerifyCodeUtil.java 273 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/util/email/MailSendInfo.java 105 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/util/email/MailSenderUtil.java 109 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/util/email/MyAuthenticator.java 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ks/tool/bkz/vo/sdlj/SDLJGoodsInfoVO.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application.yml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/generatorConfig.xml 81 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/CardPwdInfoMapper.xml 149 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/SDLJShareOpenHistoryMapper.xml 108 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/UserInfoMapper.xml 162 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/test/java/com/ks/tool/bkz/UserTest.java 61 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pom.xml
@@ -108,6 +108,50 @@
            <version>2.1.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/javax.mail/mail -->
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.7</version>
        </dependency>
        <dependency>
            <groupId>commons-httpclient</groupId>
            <artifactId>commons-httpclient</artifactId>
            <version>3.1</version>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.10</version>
        </dependency>
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.1</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>net.sf.json-lib</groupId>
            <artifactId>json-lib</artifactId>
            <version>2.4</version>
            <classifier>jdk15</classifier>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.4.1</version>
        </dependency>
    </dependencies>
@@ -117,6 +161,33 @@
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>
                <configuration>
                    <configurationFile>${basedir}/src/main/resources/generatorConfig.xml</configurationFile>
                    <overwrite>true</overwrite>
                    <verbose>true</verbose>
                </configuration>
                <executions>
                    <execution>
                        <id>Generate MyBatis Artifacts</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.mybatis.generator</groupId>
                        <artifactId>mybatis-generator-core</artifactId>
                        <version>1.3.2</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
src/main/java/com/ks/tool/bkz/controller/ParseController.java
@@ -3,11 +3,10 @@
import com.alibaba.fastjson.JSONObject;
import com.ks.tool.bkz.dto.FirstOrderSubParseResult;
import com.ks.tool.bkz.entity.FirstOrderSubInfo;
import com.ks.tool.bkz.exception.TBCookieException;
import com.ks.tool.bkz.service.FirstOrderSubInfoService;
import com.ks.tool.bkz.service.manager.RedisManager;
import com.ks.tool.bkz.util.FirstOrderSubDataUtil;
import com.ks.tool.bkz.util.JsonUtil;
import com.ks.tool.bkz.util.UrlUtil;
import com.ks.tool.bkz.util.*;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -24,20 +23,24 @@
@Controller
@RequestMapping("parse")
public class ParseController {
    String cookie = null;
    @Resource
    private RedisManager redisManager;
    @Resource
    private FirstOrderSubInfoService firstOrderSubInfoService;
    private String getCookieKey(String tbUid) {
        return "tbcookie-" + tbUid;
    }
    @RequestMapping("getRequestUrl")
    @ResponseBody
    public String getRequestUrl(String baseUrl) {
    public String getRequestUrl(String baseUrl, String tbUid) {
        String host = UrlUtil.getHost(baseUrl);
        Map<String, String> params = UrlUtil.getParamsMap(baseUrl);
        params.put("t", System.currentTimeMillis() + "");
        cookie = redisManager.get("cookie");
        String cookie = redisManager.get(getCookieKey(tbUid));
        String token = FirstOrderSubDataUtil.getTokenFromCookie(cookie);
        String data = params.get("data");
        try {
@@ -78,9 +81,11 @@
    @RequestMapping("uploadCookies")
    @ResponseBody
    public String uploadCookie(String cookies) {
        this.cookie = cookies;
        redisManager.save("cookie", cookies, 60 * 60);
        return cookies;
        String tbUid = TBCookieUtil.getTBUid(cookies);
        if (!StringUtil.isNullOrEmpty(tbUid)) {
            redisManager.save(getCookieKey(tbUid), cookies, 60 * 60);
        }
        return "";
    }
    @RequestMapping("getLoginUrl")
@@ -100,17 +105,21 @@
    @RequestMapping("uploadContent")
    @ResponseBody
    public String uploadContent(String content) {
        FirstOrderSubParseResult result = FirstOrderSubDataUtil.parseOrderSubData(content);
        if (result != null && result.isHasNextPage()) {
            if (result.getGoodsList() != null)
                for (FirstOrderSubInfo info : result.getGoodsList()) {
                    firstOrderSubInfoService.add(info);
                    System.out.println(info.getId() + "-" + info.getTitle());
                }
            System.out.println("----------------------------");
            return JsonUtil.loadTrueResult(null);
        } else {
            return JsonUtil.loadFalseResult(1, "无更多数据");
        try {
            FirstOrderSubParseResult result = FirstOrderSubDataUtil.parseOrderSubData(content);
            if (result != null && result.isHasNextPage()) {
                if (result.getGoodsList() != null)
                    for (FirstOrderSubInfo info : result.getGoodsList()) {
                        firstOrderSubInfoService.add(info);
                        System.out.println(info.getId() + "-" + info.getTitle());
                    }
                System.out.println("----------------------------");
                return JsonUtil.loadTrueResult(null);
            } else {
                return JsonUtil.loadFalseResult(1, "无更多数据");
            }
        } catch (TBCookieException e) {
            return JsonUtil.loadFalseResult(1001, "淘宝授权出错");
        }
    }
src/main/java/com/ks/tool/bkz/controller/SDLJGoodsController.java
@@ -29,13 +29,17 @@
    @RequestMapping("searchGoods")
    @ResponseBody
    public String searchGoods(int page, String searchInfo) {
    public String searchGoods(int page,int classType, String searchInfo) {
        SearchFilter sf = new Gson().fromJson(searchInfo, SearchFilter.class);
        int pageSize=30;
        List<FirstOrderSubInfo> list=    firstOrderSubInfoService.listAll(page,20);
        List<FirstOrderSubInfo> list=    firstOrderSubInfoService.listAll(page,pageSize);
        List<SDLJGoodsInfoVO> goodsList = new ArrayList<>();
        int index=(page-1)*pageSize;
        for (FirstOrderSubInfo info:list) {
            index++;
            SDLJGoodsInfoVO vo=new SDLJGoodsInfoVO();
            vo.setIndex(index);
            vo.setActualPrice("12.00");
            vo.setCommission("2.00");
            vo.setCommissionRate("20%");
src/main/java/com/ks/tool/bkz/controller/UserController.java
New file
@@ -0,0 +1,141 @@
package com.ks.tool.bkz.controller;
import com.alibaba.fastjson.JSONObject;
import com.ks.tool.bkz.entity.user.UserInfo;
import com.ks.tool.bkz.exception.UserException;
import com.ks.tool.bkz.service.manager.RedisManager;
import com.ks.tool.bkz.service.user.UserService;
import com.ks.tool.bkz.util.*;
import com.ks.tool.bkz.util.email.MailSenderUtil;
import io.netty.util.Constant;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
@Controller
@RequestMapping("user")
public class UserController {
    private final static String RANDKEY = "LoginImageCode";
    @Resource
    private RedisManager redisManager;
    @Resource
    private UserService userService;
    private String getVCodeKey(String account) {
        return "login-vcode-" + StringUtil.Md5(account);
    }
    /**
     * 登录
     *
     * @param account
     * @param vcode
     * @return
     */
    @RequestMapping("login")
    @ResponseBody
    public String login(String account, String vcode, HttpServletRequest request) {
        if (StringUtil.isNullOrEmpty(account))
            return JsonUtil.loadFalseResult(1, "账号不能为空");
        if (StringUtil.isNullOrEmpty(vcode))
            return JsonUtil.loadFalseResult(1, "验证码不能为空");
        String key = getVCodeKey(account);
        String oldVcode = redisManager.get(key);
        if (oldVcode == null || !oldVcode.equalsIgnoreCase(vcode))
            return JsonUtil.loadFalseResult(1, "验证码错误");
        redisManager.delete(key);
        account = account.trim();
        UserInfo user = userService.selectByAccount(account);
        if (user == null) {
            try {
                user = new UserInfo();
                user.setAccount(account);
                user.setState(UserInfo.STATE_NORMAL);
                userService.addUser(user);
                userService.login(account, request.getRemoteHost() + ":" + request.getRemotePort());
            } catch (UserException e) {
                return JsonUtil.loadFalseResult(e.getCode(), e.getMsg());
            } catch (Exception e) {
                return JsonUtil.loadFalseResult(1000, "服务器内部出错,请稍后再试!");
            }
        } else {
            userService.login(account, request.getRemoteHost() + ":" + request.getRemotePort());
        }
        String token = UserUtil.getToken(account, System.currentTimeMillis());
        JSONObject data = new JSONObject();
        data.put("token", token);
        return JsonUtil.loadTrueResult(data);
    }
    /**
     * 获取邮箱验证码
     *
     * @param email
     * @param request
     * @return
     */
    @RequestMapping("getVerifyCode")
    @ResponseBody
    public String getVerifyCode(String email, String vcode, HttpServletRequest request) {
        if(!StringUtil.isEmail(email)){
            return JsonUtil.loadFalseResult(1, "邮箱格式不正确");
        }
        HttpSession session = request.getSession(true);
        if (session.getAttribute(RANDKEY) == null || !session.getAttribute(RANDKEY).toString().equalsIgnoreCase(vcode))
            return JsonUtil.loadFalseResult(1, "图片验证码错误");
        session.removeAttribute(RANDKEY);
        String source = "0123456789";
        String code = "";
        for (int i = 0; i < 6; i++) {
            code += source.charAt((int) (Math.random() * source.length()));
        }
        MailSenderUtil.sendEmail(email, "爆款猪登录验证", "登录验证码为:" + code);
        redisManager.save(getVCodeKey(email), code, 5 * 60);
        return JsonUtil.loadTrueResult(null);
    }
    /**
     * 图片验证码
     *
     * @param request
     * @param response
     */
    @RequestMapping(value = "/imgcode", method = RequestMethod.GET)
    public void imgCode(HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        response.setContentType("image/jpeg");
        // 生成随机字串
        String verifyCode = VerifyCodeUtil.generateVerifyCode(4);
        // 存入会话session
        HttpSession session = request.getSession(true);
        session.setAttribute(RANDKEY, verifyCode.toLowerCase());
        // 生成图片
        int w = 200, h = 80;
        try {
            VerifyCodeUtil.outputImage(w, h, response.getOutputStream(), verifyCode);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
src/main/java/com/ks/tool/bkz/dao/BaseMapper.java
New file
@@ -0,0 +1,17 @@
package com.ks.tool.bkz.dao;
public interface BaseMapper<T> {
    int deleteByPrimaryKey(Long id);
    int insert(T record);
    int insertSelective(T record);
    T selectByPrimaryKey(Long id);
    int updateByPrimaryKeySelective(T record);
    int updateByPrimaryKey(T record);
}
src/main/java/com/ks/tool/bkz/dao/mybatis/user/CardPwdInfoMapper.java
New file
@@ -0,0 +1,11 @@
package com.ks.tool.bkz.dao.mybatis.user;
import com.ks.tool.bkz.dao.BaseMapper;
import com.ks.tool.bkz.entity.user.CardPwdInfo;
import org.springframework.stereotype.Repository;
@Repository
public interface CardPwdInfoMapper extends BaseMapper<CardPwdInfo> {
    CardPwdInfo   selectByCard(String card);
}
src/main/java/com/ks/tool/bkz/dao/mybatis/user/SDLJShareOpenHistoryMapper.java
New file
@@ -0,0 +1,27 @@
package com.ks.tool.bkz.dao.mybatis.user;
import com.ks.tool.bkz.dao.BaseMapper;
import com.ks.tool.bkz.entity.user.SDLJShareOpenHistory;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.Date;
@Repository
public interface SDLJShareOpenHistoryMapper extends BaseMapper<SDLJShareOpenHistory> {
    /**
     *获取最近的开通记录
     * @param uid
     * @return
     */
     SDLJShareOpenHistory selectLatestOpenHistory(Long uid);
    /**
     * 根据用户ID和时间匹配开通记录
     * @param uid
     * @param time
     * @return
     */
     SDLJShareOpenHistory selectByUidAndTime(@Param("uid") Long uid,@Param("time") Date time);
}
src/main/java/com/ks/tool/bkz/dao/mybatis/user/UserInfoMapper.java
New file
@@ -0,0 +1,10 @@
package com.ks.tool.bkz.dao.mybatis.user;
import com.ks.tool.bkz.dao.BaseMapper;
import com.ks.tool.bkz.entity.user.UserInfo;
import org.springframework.stereotype.Repository;
@Repository
public interface UserInfoMapper extends BaseMapper<UserInfo> {
    UserInfo selectByAccount(String account);
}
src/main/java/com/ks/tool/bkz/entity/user/CardPwdInfo.java
New file
@@ -0,0 +1,93 @@
package com.ks.tool.bkz.entity.user;
import java.util.Date;
/**
 * 卡密
 */
public class CardPwdInfo {
    public final static int STATE_NOT_CONSUME=0;//未被消费
    public final static int STATE_CONSUMED=1;//已被消费
    private Long id;
    private String card;//卡号
    private String pwd;//密码
    private Integer type;//类型
    private Integer consumeState;//消费状态
    private Date consumeTime;//消费时间
    private Long consumeUid;//消费用户ID
    private Date createTime;//创建时间
    private Date updateTime;//更新时间
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getCard() {
        return card;
    }
    public void setCard(String card) {
        this.card = card;
    }
    public String getPwd() {
        return pwd;
    }
    public void setPwd(String pwd) {
        this.pwd = pwd;
    }
    public Integer getType() {
        return type;
    }
    public void setType(Integer type) {
        this.type = type;
    }
    public Integer getConsumeState() {
        return consumeState;
    }
    public void setConsumeState(Integer consumeState) {
        this.consumeState = consumeState;
    }
    public Date getConsumeTime() {
        return consumeTime;
    }
    public void setConsumeTime(Date consumeTime) {
        this.consumeTime = consumeTime;
    }
    public Long getConsumeUid() {
        return consumeUid;
    }
    public void setConsumeUid(Long consumeUid) {
        this.consumeUid = consumeUid;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}
src/main/java/com/ks/tool/bkz/entity/user/CardPwdTypeEnum.java
New file
@@ -0,0 +1,31 @@
package com.ks.tool.bkz.entity.user;
import java.math.BigDecimal;
public enum CardPwdTypeEnum {
    sdljShort(10, "首单优惠共享版试用", new BigDecimal(0)),
    sdljMonth(11, "首单优惠共享版月卡", new BigDecimal(99)),
    sdljSeason(12, "首单优惠共享版季卡", new BigDecimal(149)),
    sdljYear(13, "首单优惠共享版年卡", new BigDecimal(499));
    private int type;
    private String name;
    private BigDecimal price;
    private CardPwdTypeEnum(int type, String name, BigDecimal price) {
        this.type = type;
        this.name = name;
        this.price = price;
    }
    public int getType() {
        return type;
    }
    public String getName() {
        return name;
    }
    public BigDecimal getPrice() {
        return price;
    }
}
src/main/java/com/ks/tool/bkz/entity/user/SDLJShareOpenHistory.java
New file
@@ -0,0 +1,52 @@
package com.ks.tool.bkz.entity.user;
import java.util.Date;
public class SDLJShareOpenHistory {
    private Long id;
    private Long uid;//用户ID
    private Date startTime;//开始时间
    private Date expireTime;//结束时间
    private Date createTime;//创建时间
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public Long getUid() {
        return uid;
    }
    public void setUid(Long uid) {
        this.uid = uid;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getExpireTime() {
        return expireTime;
    }
    public void setExpireTime(Date expireTime) {
        this.expireTime = expireTime;
    }
    public Date getStartTime() {
        return startTime;
    }
    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }
}
src/main/java/com/ks/tool/bkz/entity/user/UserInfo.java
New file
@@ -0,0 +1,107 @@
package com.ks.tool.bkz.entity.user;
import java.util.Date;
public class UserInfo {
    public final static int LEVEL_GENERAL = 1;//普通用户
    public static int LEVEL_SUPER = 2;//超级用户
    public  final static int STATE_NORMAL=0;//正常
    public  final static int STATE_FORBIDDEN=1;//被封禁
    private Long id;//用户ID
    private String account;//账号
    private Integer level;//用户等级
    private Date loginTime;//登录时间
    private Date superTime;//成为会员的时间
    private Date createTime;//创建时间
    private Date updateTime;//更新时间
    private Integer state;
    private String stateDesc;
    private String loginIpInfo;//登录信息
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getAccount() {
        return account;
    }
    public void setAccount(String account) {
        this.account = account;
    }
    public Integer getLevel() {
        return level;
    }
    public void setLevel(Integer level) {
        this.level = level;
    }
    public Date getLoginTime() {
        return loginTime;
    }
    public void setLoginTime(Date loginTime) {
        this.loginTime = loginTime;
    }
    public Date getSuperTime() {
        return superTime;
    }
    public void setSuperTime(Date superTime) {
        this.superTime = superTime;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
    public String getLoginIpInfo() {
        return loginIpInfo;
    }
    public void setLoginIpInfo(String loginIpInfo) {
        this.loginIpInfo = loginIpInfo;
    }
    public Integer getState() {
        return state;
    }
    public void setState(Integer state) {
        this.state = state;
    }
    public String getStateDesc() {
        return stateDesc;
    }
    public void setStateDesc(String stateDesc) {
        this.stateDesc = stateDesc == null ? null : stateDesc.trim();
    }
}
src/main/java/com/ks/tool/bkz/exception/BaseException.java
New file
@@ -0,0 +1,22 @@
package com.ks.tool.bkz.exception;
public class BaseException extends Exception {
    private int code;
    private String msg;
    public BaseException(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    public int getCode() {
        return code;
    }
    public String getMsg() {
        return msg;
    }
}
src/main/java/com/ks/tool/bkz/exception/CardPwdException.java
New file
@@ -0,0 +1,9 @@
package com.ks.tool.bkz.exception;
public class CardPwdException extends BaseException{
    public CardPwdException(int code, String msg) {
        super(code, msg);
    }
}
src/main/java/com/ks/tool/bkz/exception/SDLJShareOpenHistoryException.java
New file
@@ -0,0 +1,9 @@
package com.ks.tool.bkz.exception;
public class SDLJShareOpenHistoryException extends BaseException{
    public SDLJShareOpenHistoryException(int code, String msg) {
        super(code, msg);
    }
}
src/main/java/com/ks/tool/bkz/exception/TBCookieException.java
New file
@@ -0,0 +1,7 @@
package com.ks.tool.bkz.exception;
public class TBCookieException extends BaseException{
    public TBCookieException(int code, String msg) {
        super(code, msg);
    }
}
src/main/java/com/ks/tool/bkz/exception/UserException.java
New file
@@ -0,0 +1,9 @@
package com.ks.tool.bkz.exception;
public class UserException extends BaseException{
    public UserException(int code, String msg) {
        super(code, msg);
    }
}
src/main/java/com/ks/tool/bkz/service/impl/user/CardPwdImpl.java
New file
@@ -0,0 +1,54 @@
package com.ks.tool.bkz.service.impl.user;
import com.ks.tool.bkz.dao.mybatis.user.CardPwdInfoMapper;
import com.ks.tool.bkz.entity.user.CardPwdInfo;
import com.ks.tool.bkz.exception.CardPwdException;
import com.ks.tool.bkz.service.user.CardPwdService;
import com.ks.tool.bkz.util.StringUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Date;
@Service
public class CardPwdImpl implements CardPwdService {
    @Resource
    private CardPwdInfoMapper cardPwdInfoMapper;
    @Override
    public void addCardPwd(CardPwdInfo info) throws CardPwdException {
    }
    @Override
    public CardPwdInfo selectByCard(String card) {
        return cardPwdInfoMapper.selectByCard(card);
    }
    @Transactional
    @Override
    public void consumeCardPwd(Long uid, String card, String pwd) throws CardPwdException {
        if(uid==null)
            throw new CardPwdException(10, "用户不能为空");
        if(StringUtil.isNullOrEmpty(card)||StringUtil.isNullOrEmpty(pwd))
            throw new CardPwdException(10, "卡密不能为空");
        CardPwdInfo info = selectByCard(card);
        if (info == null)
            throw new CardPwdException(1, "卡号不存在");
        if (info.getPwd().equalsIgnoreCase(pwd))
            throw new CardPwdException(2, "卡密不匹配");
        if (info.getConsumeState() == CardPwdInfo.STATE_CONSUMED)
            throw new CardPwdException(3, "卡密已被使用");
        CardPwdInfo update = new CardPwdInfo();
        update.setId(info.getId());
        update.setConsumeState(CardPwdInfo.STATE_CONSUMED);
        update.setConsumeTime(new Date());
        update.setConsumeUid(uid);
        update.setUpdateTime(new Date());
        cardPwdInfoMapper.updateByPrimaryKeySelective(update);
    }
}
src/main/java/com/ks/tool/bkz/service/impl/user/SDLJShareOpenHistoryServiceImpl.java
New file
@@ -0,0 +1,44 @@
package com.ks.tool.bkz.service.impl.user;
import com.ks.tool.bkz.dao.mybatis.user.SDLJShareOpenHistoryMapper;
import com.ks.tool.bkz.entity.user.SDLJShareOpenHistory;
import com.ks.tool.bkz.exception.SDLJShareOpenHistoryException;
import com.ks.tool.bkz.service.user.SDLJShareOpenHistoryService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
@Service
public class SDLJShareOpenHistoryServiceImpl implements SDLJShareOpenHistoryService {
    @Resource
    private SDLJShareOpenHistoryMapper sdljShareOpenHistoryMapper;
    @Override
    public boolean isOpen(Long uid) {
        SDLJShareOpenHistory history = sdljShareOpenHistoryMapper.selectByUidAndTime(uid, new Date());
        if (history == null)
            return false;
        return true;
    }
    @Override
    public Date getExpireTime(Long uid) {
        SDLJShareOpenHistory history = sdljShareOpenHistoryMapper.selectLatestOpenHistory(uid);
        if (history == null)
            return null;
        return history.getExpireTime();
    }
    @Override
    public void addHistory(SDLJShareOpenHistory history) throws SDLJShareOpenHistoryException {
        if (history == null || history.getUid() == null || history.getCreateTime() == null || history.getExpireTime() == null)
            throw new SDLJShareOpenHistoryException(1, "参数不完整");
        sdljShareOpenHistoryMapper.insertSelective(history);
    }
    @Override
    public SDLJShareOpenHistory selectLatestHistory(Long uid) {
        return sdljShareOpenHistoryMapper.selectLatestOpenHistory(uid);
    }
}
src/main/java/com/ks/tool/bkz/service/impl/user/UserServiceImpl.java
New file
@@ -0,0 +1,80 @@
package com.ks.tool.bkz.service.impl.user;
import com.ks.tool.bkz.dao.mybatis.user.UserInfoMapper;
import com.ks.tool.bkz.entity.user.UserInfo;
import com.ks.tool.bkz.exception.UserException;
import com.ks.tool.bkz.service.user.UserService;
import com.ks.tool.bkz.util.StringUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Date;
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserInfoMapper userInfoMapper;
    @Transactional
    @Override
    public void addUser(UserInfo user) throws UserException {
        //账户为空
        if (StringUtil.isNullOrEmpty(user.getAccount()))
            throw new UserException(1, "账号为空");
        UserInfo old = selectByAccount(user.getAccount());
        if (old != null) {
            throw new UserException(2, "账号已存在");
        }
        if (user.getCreateTime() == null)
            user.setCreateTime(new Date());
        user.setLevel(UserInfo.LEVEL_GENERAL);
        userInfoMapper.insertSelective(user);
    }
    @Override
    public UserInfo selectByAccount(String account) {
        return userInfoMapper.selectByAccount(account);
    }
    @Override
    public UserInfo selectValidByPrimaryKey(Long id) {
        UserInfo user = userInfoMapper.selectByPrimaryKey(id);
        if (user.getState() == UserInfo.STATE_NORMAL)
            return user;
        return null;
    }
    @Override
    public void login(String account, String ipInfo) {
        UserInfo user = selectByAccount(account);
        if (user != null) {
            UserInfo updateUser = new UserInfo();
            updateUser.setId(user.getId());
            updateUser.setLoginTime(new Date());
            updateUser.setUpdateTime(new Date());
            updateUser.setLoginIpInfo(ipInfo);
            userInfoMapper.updateByPrimaryKeySelective(updateUser);
        }
    }
    @Transactional
    @Override
    public void upgradeSuper(Long id)  throws  UserException{
        UserInfo user = selectValidByPrimaryKey(id);
        if (user == null)
           throw new UserException(1,"用户不存在");
        if(user.getLevel()==UserInfo.LEVEL_SUPER)
            throw new UserException(2,"已经是共享版");
        UserInfo update = new UserInfo();
        update.setId(id);
        update.setUpdateTime(new Date());
        update.setSuperTime(new Date());
        update.setLevel(UserInfo.LEVEL_SUPER);
        userInfoMapper.updateByPrimaryKeySelective(update);
    }
}
src/main/java/com/ks/tool/bkz/service/impl/user/UserUpgradeServiceImpl.java
New file
@@ -0,0 +1,58 @@
package com.ks.tool.bkz.service.impl.user;
import com.ks.tool.bkz.entity.user.CardPwdInfo;
import com.ks.tool.bkz.entity.user.CardPwdTypeEnum;
import com.ks.tool.bkz.entity.user.SDLJShareOpenHistory;
import com.ks.tool.bkz.entity.user.UserInfo;
import com.ks.tool.bkz.exception.CardPwdException;
import com.ks.tool.bkz.exception.SDLJShareOpenHistoryException;
import com.ks.tool.bkz.exception.UserException;
import com.ks.tool.bkz.service.user.CardPwdService;
import com.ks.tool.bkz.service.user.SDLJShareOpenHistoryService;
import com.ks.tool.bkz.service.user.UserService;
import com.ks.tool.bkz.service.user.UserUpgradeService;
import com.ks.tool.bkz.util.CardPwdUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Date;
@Service
public class UserUpgradeServiceImpl implements UserUpgradeService {
    @Resource
    private CardPwdService cardPwdService;
    @Resource
    private UserService userService;
    @Resource
    private SDLJShareOpenHistoryService sdljShareOpenHistoryService;
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void upgradeSDLJShare(Long uid, String card, String pwd) throws UserException, CardPwdException, SDLJShareOpenHistoryException {
        UserInfo user = userService.selectValidByPrimaryKey(uid);
        if (user == null)
            throw new UserException(1, "用户不存在");
        cardPwdService.consumeCardPwd(uid, card, pwd);
        //查询卡密类型
        CardPwdInfo info = cardPwdService.selectByCard(card);
        CardPwdTypeEnum type = CardPwdUtil.getTypeEnumByType(info.getType());
        if (type == null)
            throw new CardPwdException(20, "未找到卡密对应的类型");
        SDLJShareOpenHistory latestHistory = sdljShareOpenHistoryService.selectLatestHistory(uid);
        Date startTime = null;
        if (latestHistory != null)
            startTime = latestHistory.getExpireTime();
        else
            startTime = new Date();
        Date expireTime = CardPwdUtil.getExpireTime(startTime, type);
        SDLJShareOpenHistory history = new SDLJShareOpenHistory();
        history.setExpireTime(expireTime);
        history.setCreateTime(new Date());
        history.setStartTime(startTime);
        sdljShareOpenHistoryService.addHistory(history);
    }
}
src/main/java/com/ks/tool/bkz/service/user/CardPwdService.java
New file
@@ -0,0 +1,36 @@
package com.ks.tool.bkz.service.user;
import com.ks.tool.bkz.entity.user.CardPwdInfo;
import com.ks.tool.bkz.exception.CardPwdException;
/**
 * 卡密服务
 */
public interface CardPwdService {
    /**
     * 添加卡密
     * @param info
     * @throws CardPwdException
     */
    public void addCardPwd(CardPwdInfo info) throws CardPwdException;
    /**
     * 根据卡号查询
     * @param card
     * @return
     */
    public CardPwdInfo selectByCard(String card);
    /**
     * 卡密消费
     * @param  uid
     * @param card
     * @param pwd
     * @throws CardPwdException
     */
    public void consumeCardPwd(Long uid,String card,String pwd) throws CardPwdException;
}
src/main/java/com/ks/tool/bkz/service/user/SDLJShareOpenHistoryService.java
New file
@@ -0,0 +1,41 @@
package com.ks.tool.bkz.service.user;
import com.ks.tool.bkz.entity.user.SDLJShareOpenHistory;
import com.ks.tool.bkz.exception.SDLJShareOpenHistoryException;
import java.util.Date;
/**
 * 首单礼金共享版开通记录
 */
public interface SDLJShareOpenHistoryService {
    /**
     * 是否已经开通
     * @param uid
     * @return
     */
    public boolean isOpen(Long uid);
    /**
     * 获取过期时间
     * @param uid
     * @return
     */
    public Date getExpireTime(Long uid);
    /**
     * 添加开通记录
     * @param history
     */
    public void addHistory(SDLJShareOpenHistory history) throws SDLJShareOpenHistoryException;
    /**
     * 获取最近的一条开通记录
     * @param uid
     * @return
     */
    public SDLJShareOpenHistory selectLatestHistory(Long uid);
}
src/main/java/com/ks/tool/bkz/service/user/UserService.java
New file
@@ -0,0 +1,43 @@
package com.ks.tool.bkz.service.user;
import com.ks.tool.bkz.entity.user.UserInfo;
import com.ks.tool.bkz.exception.UserException;
public interface UserService {
    /**
     * 添加用户
     * @param user
     * @throws UserException
     */
    public void addUser(UserInfo user) throws UserException;
    /**
     * 根据账户查询
     * @param account
     */
    public UserInfo selectByAccount(String account);
    /**
     * 查询有效的用户
     * @param id
     * @return
     */
    public UserInfo selectValidByPrimaryKey(Long id);
    /**
     * 用户登录
     * @param account
     */
    public void login(String account,String ipInfo);
    /**
     * 升级为会员
     * @param id
     */
    public void upgradeSuper(Long id) throws  UserException;
}
src/main/java/com/ks/tool/bkz/service/user/UserUpgradeService.java
New file
@@ -0,0 +1,18 @@
package com.ks.tool.bkz.service.user;
import com.ks.tool.bkz.exception.CardPwdException;
import com.ks.tool.bkz.exception.SDLJShareOpenHistoryException;
import com.ks.tool.bkz.exception.UserException;
/**
 * 用户升级服务
 */
public interface UserUpgradeService {
    /**
     * 用卡密升级共享版首单立减
     * @param uid
     * @param card
     * @param pwd
     */
    public void upgradeSDLJShare(Long uid,String card,String pwd) throws UserException, CardPwdException, SDLJShareOpenHistoryException;
}
src/main/java/com/ks/tool/bkz/util/AESUtil.java
New file
@@ -0,0 +1,193 @@
package com.ks.tool.bkz.util;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
/**
 * AES加解密
 *
 * @author Administrator
 *
 */
public class AESUtil {
    private final static String KEY = "BakuZhU2020&*@88";
    public static String encrypt(String content) {
        try {
            KeyGenerator kgen = KeyGenerator.getInstance("AES");
            SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
            secureRandom.setSeed(KEY.getBytes());
            kgen.init(128, secureRandom);
            SecretKeySpec key = new SecretKeySpec(KEY.getBytes(), "AES");
            Cipher cipher = Cipher.getInstance("AES");
            byte[] byteContent = content.getBytes("utf-8");
            cipher.init(Cipher.ENCRYPT_MODE, key);
            byte[] result = cipher.doFinal(byteContent);
            return (new sun.misc.BASE64Encoder()).encode(result);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (NoSuchPaddingException e) {
            e.printStackTrace();
        } catch (InvalidKeyException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IllegalBlockSizeException e) {
            e.printStackTrace();
        } catch (BadPaddingException e) {
            e.printStackTrace();
        }
        return new String();
    }
    public static String encrypt(String content,String keyStr) {
        try {
            KeyGenerator kgen = KeyGenerator.getInstance("AES");
            SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
            secureRandom.setSeed(keyStr.getBytes());
            kgen.init(128, secureRandom);
            SecretKeySpec key = new SecretKeySpec(keyStr.getBytes(), "AES");
            Cipher cipher = Cipher.getInstance("AES");
            byte[] byteContent = content.getBytes("utf-8");
            cipher.init(Cipher.ENCRYPT_MODE, key);
            byte[] result = cipher.doFinal(byteContent);
            return (new sun.misc.BASE64Encoder()).encode(result);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (NoSuchPaddingException e) {
            e.printStackTrace();
        } catch (InvalidKeyException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IllegalBlockSizeException e) {
            e.printStackTrace();
        } catch (BadPaddingException e) {
            e.printStackTrace();
        }
        return new String();
    }
    public static String decrypt(String contentStr) {
        try {
            byte[] content = (new sun.misc.BASE64Decoder()).decodeBuffer(contentStr);
            KeyGenerator kgen = KeyGenerator.getInstance("AES");
            SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
            secureRandom.setSeed(KEY.getBytes());
            kgen.init(128, secureRandom);
            SecretKeySpec key = new SecretKeySpec(KEY.getBytes(), "AES");
            Cipher cipher = Cipher.getInstance("AES");
            cipher.init(Cipher.DECRYPT_MODE, key);
            byte[] result = cipher.doFinal(content);
            return new String(result);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (NoSuchPaddingException e) {
            e.printStackTrace();
        } catch (InvalidKeyException e) {
            e.printStackTrace();
        } catch (IllegalBlockSizeException e) {
            e.printStackTrace();
        } catch (BadPaddingException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new String();
    }
    public static String decrypt(String contentStr,String keyStr) {
        try {
            byte[] content = (new sun.misc.BASE64Decoder()).decodeBuffer(contentStr);
            KeyGenerator kgen = KeyGenerator.getInstance("AES");
            SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
            secureRandom.setSeed(keyStr.getBytes());
            kgen.init(128, secureRandom);
            SecretKeySpec key = new SecretKeySpec(keyStr.getBytes(), "AES");
            Cipher cipher = Cipher.getInstance("AES");
            cipher.init(Cipher.DECRYPT_MODE, key);
            byte[] result = cipher.doFinal(content);
            return new String(result);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (NoSuchPaddingException e) {
            e.printStackTrace();
        } catch (InvalidKeyException e) {
            e.printStackTrace();
        } catch (IllegalBlockSizeException e) {
            e.printStackTrace();
        } catch (BadPaddingException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new String();
    }
    public static String decrypt(String contentStr, String keyBase64, String ivBase64) {
        try {
            byte[] content = (new sun.misc.BASE64Decoder()).decodeBuffer(contentStr);
            IvParameterSpec iv = new IvParameterSpec((new sun.misc.BASE64Decoder()).decodeBuffer(ivBase64));
            SecretKeySpec skeySpec = new SecretKeySpec((new sun.misc.BASE64Decoder()).decodeBuffer(keyBase64), "AES");
            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7PADDING");
            cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
            byte[] original = cipher.doFinal(content);
            return new String(original);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }
    public static String decrypt(byte[] contentStr, String k) {
        try {
            byte[] content = contentStr;
            KeyGenerator kgen = KeyGenerator.getInstance("AES");
            SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
            secureRandom.setSeed(k.getBytes());
            kgen.init(128, secureRandom);
            SecretKeySpec key = new SecretKeySpec(k.getBytes(), "AES");
            Cipher cipher = Cipher.getInstance("AES");
            cipher.init(Cipher.DECRYPT_MODE, key);
            byte[] result = cipher.doFinal(content);
            return new String(result, "utf-8");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (NoSuchPaddingException e) {
            e.printStackTrace();
        } catch (InvalidKeyException e) {
            e.printStackTrace();
        } catch (IllegalBlockSizeException e) {
            e.printStackTrace();
        } catch (BadPaddingException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new String();
    }
}
src/main/java/com/ks/tool/bkz/util/CardPwdUtil.java
New file
@@ -0,0 +1,39 @@
package com.ks.tool.bkz.util;
import com.ks.tool.bkz.entity.user.CardPwdTypeEnum;
import java.util.Calendar;
import java.util.Date;
public class CardPwdUtil {
    /**
     * 获取卡密的结束时间
     * @param startTime
     * @param type
     * @return
     */
    public static Date getExpireTime(Date startTime, CardPwdTypeEnum type) {
        Calendar ca = Calendar.getInstance();
        ca.setTimeInMillis(startTime.getTime());
        if (type == CardPwdTypeEnum.sdljShort) {//试用
            ca.setTimeInMillis(ca.getTimeInMillis() + 1000 * 60 * 60 * 24 * 3L);
        } else if (type == CardPwdTypeEnum.sdljMonth) {//月卡
            ca.add(Calendar.MONTH, 1);
        } else if (type == CardPwdTypeEnum.sdljSeason) {//季卡
            ca.add(Calendar.MONTH, 3);
        } else if (type == CardPwdTypeEnum.sdljYear) {//年卡
            ca.add(Calendar.YEAR, 1);
        }
        return new Date(ca.getTimeInMillis());
    }
    public static CardPwdTypeEnum getTypeEnumByType(int type){
        for(CardPwdTypeEnum typeEnum:CardPwdTypeEnum.values()){
            if(typeEnum.getType()==type)
                return typeEnum;
        }
        return null;
    }
}
src/main/java/com/ks/tool/bkz/util/FirstOrderSubDataUtil.java
@@ -6,6 +6,7 @@
import com.google.gson.reflect.TypeToken;
import com.ks.tool.bkz.dto.FirstOrderSubParseResult;
import com.ks.tool.bkz.entity.FirstOrderSubInfo;
import com.ks.tool.bkz.exception.TBCookieException;
import java.lang.reflect.Type;
import java.util.HashMap;
@@ -21,12 +22,16 @@
     * @param data
     * @return
     */
    public static FirstOrderSubParseResult parseOrderSubData(String data) {
    public static FirstOrderSubParseResult parseOrderSubData(String data) throws TBCookieException {
        data = data.trim().substring(data.indexOf("("));
        if (data.endsWith(")"))
            data = data.substring(0, data.length() - 1);
        //Cookie过期
        JSONObject dataJSON = JSONObject.parseObject(data);
        if (dataJSON.getJSONArray("ret") != null && dataJSON.getJSONArray("ret").toString().contains("令牌"))
            throw new TBCookieException(1,"cookie失效");
        JSONObject resultValue = dataJSON.getJSONObject("data").getJSONObject("resultValue");
        for (Iterator<String> its = resultValue.keySet().iterator(); its.hasNext(); ) {
src/main/java/com/ks/tool/bkz/util/HttpUtil.java
New file
@@ -0,0 +1,470 @@
package com.ks.tool.bkz.util;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.StringPart;
import org.apache.commons.io.FileUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLContexts;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import javax.net.ssl.SSLContext;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.security.KeyStore;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class HttpUtil {
    public static List<String> getUrlListFromText(String text) {
        List<String> urlList = new ArrayList<String>();
        // 链接
        String URL_REGEX = "(((http|https)://)|(www\\.))[a-zA-Z0-9\\._-]+\\.[a-zA-Z]{2,6}(:[0-9]{1,4})?(/[a-zA-Z0-9\\&%_\\./-~-]*)?";
        Pattern p = Pattern.compile(URL_REGEX);
        Matcher matcher = p.matcher(text);
        while (matcher.find()) {
            String url = matcher.group();
            if (!StringUtil.isNullOrEmpty(url)) {
                urlList.add(url);
            }
        }
        return urlList;
    }
    public static String getHost(String host) {
        try {
            URL url = new URL(host);
            return url.getHost();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        return "";
    }
    public static String get(String url) {
        return get(url, null);
    }
    /**
     * get请求
     *
     * @param url
     * @param timeoutMS-请求超时时间
     * @return
     */
    public static String get(String url, int timeoutMS) {
        HttpClient client = new HttpClient();
        client.getHttpConnectionManager().getParams().setConnectionTimeout(timeoutMS);
        try {
            GetMethod method = new GetMethod(url);
            client.executeMethod(method);
            return method.getResponseBodyAsString();
        } catch (Exception e) {
        }
        return null;
    }
    public static String get(String url, Map<String, String> headers) {
        HttpClient client = new HttpClient();
        try {
            GetMethod method = new GetMethod(url);
            if (headers != null) {
                Iterator<String> keys = headers.keySet().iterator();
                while (keys.hasNext()) {
                    String key = keys.next();
                    method.addRequestHeader(key, headers.get(key));
                }
            }
            client.executeMethod(method);
            return method.getResponseBodyAsString();
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
    public static String getAsString(String url, String fromCharset, String toCharset) {
        HttpClient client = new HttpClient();
        GetMethod method = new GetMethod(url);
        try {
            client.executeMethod(method);
            String response = method.getResponseBodyAsString();
            String s1 = new String(response.getBytes(fromCharset), toCharset);
            return s1;
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
    public static String get(String url, Map<String, String> params, Map<String, String> headers) {
        HttpClient client = new HttpClient();
        try {
            Iterator<String> keys = params.keySet().iterator();
            url += "?";
            while (keys.hasNext()) {
                String key = keys.next();
                url += String.format("%s=%s&", key, URLEncoder.encode(params.get(key), "UTF-8"));
            }
            GetMethod method = new GetMethod(url);
            if (headers != null) {
                keys = headers.keySet().iterator();
                while (keys.hasNext()) {
                    String key = keys.next();
                    headers.get(key);
                    method.setRequestHeader(key, headers.get(key));
                }
            }
            client.executeMethod(method);
            System.out.println(method.getResponseHeader("cookies"));
            String result = method.getResponseBodyAsString();
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
    public static InputStream getAsInputStream(String url) {
        HttpClient client = new HttpClient();
        GetMethod method = new GetMethod(url);
        try {
            client.executeMethod(method);
            return method.getResponseBodyAsStream();
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static InputStream getAsInputStream(String url, Map<String, String> headers) {
        HttpClient client = new HttpClient();
        GetMethod method = new GetMethod(url);
        Iterator<String> keys = headers.keySet().iterator();
        while (keys.hasNext()) {
            String key = keys.next();
            method.setRequestHeader(key, headers.get(key));
        }
        try {
            client.executeMethod(method);
            return method.getResponseBodyAsStream();
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static InputStream getImage(String url) {
        HttpClient client = new HttpClient();
        GetMethod method = new GetMethod(url);
        try {
            method.setRequestHeader("Content-Type", "image/jpeg");
            client.executeMethod(method);
            return method.getResponseBodyAsStream();
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static String postSimple(String url) {
        HttpClient client = new HttpClient();
        PostMethod method = new PostMethod(url);
        try {
            client.executeMethod(method);
            return method.getResponseBodyAsString();
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
    public static String post(String url) {
        HttpClient client = new HttpClient();
        PostMethod method = new PostMethod(url);
        method.addRequestHeader("Content-Type", "text/html;charset=UTF-8");
        method.setRequestHeader("Content-Type", "text/html;charset=UTF-8");
        try {
            client.executeMethod(method);
            return convertInputStreamToString(method.getResponseBodyAsStream());
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
    public static String post(String url, Map<String, String> map) {
        Iterator<String> its = map.keySet().iterator();
        NameValuePair[] params = new NameValuePair[map.keySet().size()];
        int p = 0;
        while (its.hasNext()) {
            String key = its.next();
            NameValuePair np = new NameValuePair(key, map.get(key));
            params[p] = np;
            p++;
        }
        HttpClient client = new HttpClient();
        PostMethod method = new PostMethod(url);
        method.addRequestHeader("Content-Type", "text/html;charset=UTF-8");
        method.setRequestHeader("Content-Type", "text/html;charset=UTF-8");
        method.setRequestBody(params);
        try {
            client.executeMethod(method);
            return convertInputStreamToString(method.getResponseBodyAsStream());
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
    public static String post(String url, Map<String, String> map, Map<String, String> headers) {
        HttpClient client = new HttpClient();
        // client.getHostConfiguration().setProxy("192.168.1.122", 8888);
        PostMethod pm = new PostMethod(url);// 创建HttpPost对象
        NameValuePair[] ns = new NameValuePair[map.keySet().size()];
        Iterator<String> its = map.keySet().iterator();
        int index = 0;
        while (its.hasNext()) {
            String key = its.next();
            ns[index++] = (new NameValuePair(key, map.get(key)));
        }
        if (headers != null) {
            its = headers.keySet().iterator();
            while (its.hasNext()) {
                String key = its.next();
                pm.setRequestHeader(key, headers.get(key));
            }
        }
        try {
            pm.setRequestBody(ns);
            client.executeMethod(pm);
            return pm.getResponseBodyAsString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
    private static String convertInputStreamToString(InputStream inputStream) {
        BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
        StringBuffer stringBuffer = new StringBuffer();
        String str = "";
        try {
            while ((str = br.readLine()) != null) {
                stringBuffer.append(str);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return stringBuffer.toString();
    }
    @SuppressWarnings("deprecation")
    public static String post(String url, String entity) {
        HttpClient client = new HttpClient();
        PostMethod method = new PostMethod(url);
        method.addRequestHeader("Content-Type", "text/html;charset=UTF-8");
        method.setRequestHeader("Content-Type", "text/html;charset=UTF-8");
        method.setRequestBody(entity);
        try {
            client.executeMethod(method);
            return convertInputStreamToString(method.getResponseBodyAsStream());
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
    @SuppressWarnings("deprecation")
    public static String post(String url, String entity, String charset) {
        HttpClient client = new HttpClient();
        PostMethod method = new PostMethod(url);
        method.addRequestHeader("Content-Type", "text/html;charset=" + charset);
        method.setRequestHeader("Content-Type", "text/html;charset=" + charset);
        method.setRequestBody(entity);
        try {
            client.executeMethod(method);
            return convertInputStreamToString(method.getResponseBodyAsStream());
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
    public static String postInputStream(String url, File file) throws FileNotFoundException {
        HttpClient client = new HttpClient();
        PostMethod postMethod = new PostMethod(url);
        Part[] parts = { new StringPart("filename", file.getName()), new StringPart("filelength", file.length() + ""),
                new StringPart("content-type", "image/jpg"), new FilePart("file", file) };
        postMethod.setRequestEntity(new MultipartRequestEntity(parts, postMethod.getParams()));
        try {
            client.executeMethod(postMethod);
            return convertInputStreamToString(postMethod.getResponseBodyAsStream());
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
    public static File downloadFile(String url, String targetPath) {
        try {
            URL httpurl = new URL(url);
            FileUtils.copyURLToFile(httpurl, new File(targetPath));
        } catch (Exception e) {
            e.printStackTrace();
        }
        File f = new File(targetPath);
        if (!f.exists() || f.length() <= 0)
            return null;
        return f;
    }
    @SuppressWarnings("deprecation")
    public static InputStream postForInputstream(String url, String entity) {
        HttpClient client = new HttpClient();
        PostMethod method = new PostMethod(url);
        method.addRequestHeader("Content-Type", "text/html;charset=UTF-8");
        method.setRequestHeader("Content-Type", "text/html;charset=UTF-8");
        method.setRequestBody(entity);
        try {
            client.executeMethod(method);
            return method.getResponseBodyAsStream();
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static String post(String url, String fileKey, File f) {
        PostMethod filePost = new PostMethod(url);
        HttpClient client = new HttpClient();
        try {
            Part[] parts = { new FilePart(fileKey, f) };
            filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams()));
            client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
            int status = client.executeMethod(filePost);
            if (status == HttpStatus.SC_OK) {
                return filePost.getResponseBodyAsString();
            } else {
                System.out.println("上传失败");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            filePost.releaseConnection();
        }
        return null;
    }
    @SuppressWarnings("deprecation")
    public static String httpsPost(String url, String body, String pwd, InputStream cert) throws Exception {
        String result = "";
        KeyStore keyStore = KeyStore.getInstance("PKCS12");
        InputStream instream = cert;
        try {
            keyStore.load(instream, pwd.toCharArray());
        } finally {
            instream.close();
        }
        // Trust own CA and all self-signed certs
        SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, pwd.toCharArray()).build();
        // Allow TLSv1 protocol only
        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null,
                SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
        CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
        try {
            HttpPost httppost = new HttpPost(url);
            httppost.setHeader("Content-Type", "text/html;charset=UTF-8");
            System.out.println("executing request" + httppost.getRequestLine());
            httppost.setEntity(new StringEntity(body, "UTF-8"));
            CloseableHttpResponse response = httpclient.execute(httppost);
            try {
                HttpEntity entity = response.getEntity();
                if (entity != null) {
                    result = convertInputStreamToString(entity.getContent());
                }
                EntityUtils.consume(entity);
            } finally {
                response.close();
            }
        } finally {
            httpclient.close();
        }
        return result;
    }
    /**
     * 获取post返回location
     *
     * @param url
     * @return
     */
    public static String getLocation(String url) {
        HttpClient client = new HttpClient();
        PostMethod method = new PostMethod(url);
        try {
            client.executeMethod(method);
            return method.getResponseHeader("location").getValue();
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
src/main/java/com/ks/tool/bkz/util/StringUtil.java
@@ -14,287 +14,298 @@
public class StringUtil {
    // 判断是否为手机号码
    public static boolean isMobile(String mobile) {
    public static boolean isEmail(String email) {
        String mailName = "^[0-9a-z]+\\w*";       //^表明一行以什么开头;^[0-9a-z]表明要以数字或小写字母开头;\\w*表明匹配任意个大写小写字母或数字或下划线
        String mailDomain = "([0-9a-z]+\\.)+[0-9a-z]+$";
        String mailRegex = mailName + "@" + mailDomain;
        if (email != null && email.matches(mailRegex)) {
            return true;
        } else {
            return false;
        }
    }
        String regex = "^((13[0-9])|(17[0-9])|(15[^4,\\D])|(18[0-9]))\\d{8}$";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(mobile);
    // 判断是否为手机号码
    public static boolean isMobile(String mobile) {
        if (mobile == null || mobile.equals("") || mobile.length() != 11) {
        String regex = "^((13[0-9])|(17[0-9])|(15[^4,\\D])|(18[0-9]))\\d{8}$";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(mobile);
            return false;
        if (mobile == null || mobile.equals("") || mobile.length() != 11) {
        } else {
            return m.find();
        }
    }
            return false;
    /**
     * 获取数字和字母的随机码
     *
     * @param count
     * @return
     */
    public static String getRandomCode(int count) {
        String sts = "0123456789abcdefghijklmnopqrsduvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String code = "";
        for (int i = 0; i < count; i++) {
            int p = (int) (Math.random() * 62);
            code += sts.charAt(p);
        }
        return code;
    }
        } else {
            return m.find();
        }
    }
    /**
     * 获取6位数字验证码
     *
     * @return
     */
    public static String getVerifyCode() {
        String sts = "0123456789";
        String code = "";
        for (int i = 0; i < 6; i++) {
            int p = (int) (Math.random() * 10);
            code += sts.charAt(p);
        }
        return code;
    }
    /**
     * 获取数字和字母的随机码
     *
     * @param count
     * @return
     */
    public static String getRandomCode(int count) {
        String sts = "0123456789abcdefghijklmnopqrsduvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String code = "";
        for (int i = 0; i < count; i++) {
            int p = (int) (Math.random() * 62);
            code += sts.charAt(p);
        }
        return code;
    }
    /**
     * 判断字符串是否为空
     *
     * @param text
     * @return
     */
    public static boolean isNullOrEmpty(String text) {
        if (text == null || text.trim().length() == 0 || text.equalsIgnoreCase("null")) {
            return true;
        }
        return false;
    }
    /**
     * 获取6位数字验证码
     *
     * @return
     */
    public static String getVerifyCode() {
        String sts = "0123456789";
        String code = "";
        for (int i = 0; i < 6; i++) {
            int p = (int) (Math.random() * 10);
            code += sts.charAt(p);
        }
        return code;
    }
    /**
     * 32为MD5小写加密
     *
     * @param st
     * @return
     */
    public static String Md5(String st) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            try {
                md.update(st.getBytes("UTF-8"));
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            byte b[] = md.digest();
    /**
     * 判断字符串是否为空
     *
     * @param text
     * @return
     */
    public static boolean isNullOrEmpty(String text) {
        if (text == null || text.trim().length() == 0 || text.equalsIgnoreCase("null")) {
            return true;
        }
        return false;
    }
            int i;
    /**
     * 32为MD5小写加密
     *
     * @param st
     * @return
     */
    public static String Md5(String st) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            try {
                md.update(st.getBytes("UTF-8"));
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            byte b[] = md.digest();
            StringBuffer buf = new StringBuffer("");
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0)
                    i += 256;
                if (i < 16)
                    buf.append("0");
                buf.append(Integer.toHexString(i));
            }
            return buf.toString();
            // LogUtil.i("result: " + buf.toString());// 32λ�ļ���
            // LogUtil.i("result: " + buf.toString().substring(8,
            // 24));// 16λ�ļ���
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }
            int i;
    public static String MD5Hmac(String st, String key) {
        try {
            return HmacUtils.byte2hex(HmacUtils.encryptHMAC(st, key));
        } catch (InvalidKeyException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
            StringBuffer buf = new StringBuffer("");
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0)
                    i += 256;
                if (i < 16)
                    buf.append("0");
                buf.append(Integer.toHexString(i));
            }
            return buf.toString();
            // LogUtil.i("result: " + buf.toString());// 32λ�ļ���
            // LogUtil.i("result: " + buf.toString().substring(8,
            // 24));// 16λ�ļ���
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
     * 将null转为空字符串
     *
     * @param st
     * @return
     */
    public static String getString(String st) {
        return isNullOrEmpty(st) ? "" : st;
    }
    public static String MD5Hmac(String st, String key) {
        try {
            return HmacUtils.byte2hex(HmacUtils.encryptHMAC(st, key));
        } catch (InvalidKeyException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
     * 将整数转为字符串
     *
     * @param i
     * @return
     */
    public static String getString(int i) {
        return getString(i + "");
    }
    /**
     * 将null转为空字符串
     *
     * @param st
     * @return
     */
    public static String getString(String st) {
        return isNullOrEmpty(st) ? "" : st;
    }
    /**
     * 将长整形转为字符串
     *
     * @param i
     * @return
     */
    public static String getString(long i) {
        return getString(i + "");
    }
    /**
     * 将整数转为字符串
     *
     * @param i
     * @return
     */
    public static String getString(int i) {
        return getString(i + "");
    }
    /**
     * 获取电话号码的隐藏格式
     *
     * @param mobile
     * @return
     */
    public static String getSubMobile(String mobile) {
        if (!StringUtil.isNullOrEmpty(mobile) && mobile.length() > 10) {
            return mobile.subSequence(0, 3).toString() + "****" + mobile.subSequence(7, mobile.length()).toString();
        } else
            return mobile;
    }
    /**
     * 将长整形转为字符串
     *
     * @param i
     * @return
     */
    public static String getString(long i) {
        return getString(i + "");
    }
    /**
     * BASE64加密
     *
     * @param b
     * @return
     */
    @SuppressWarnings("restriction")
    public static String getBase64FromByte(byte[] b) {
    /**
     * 获取电话号码的隐藏格式
     *
     * @param mobile
     * @return
     */
    public static String getSubMobile(String mobile) {
        if (!StringUtil.isNullOrEmpty(mobile) && mobile.length() > 10) {
            return mobile.subSequence(0, 3).toString() + "****" + mobile.subSequence(7, mobile.length()).toString();
        } else
            return mobile;
    }
        String s = null;
        if (b != null) {
            s = new BASE64Encoder().encode(b);
        }
        return s;
    }
    /**
     * BASE64加密
     *
     * @param b
     * @return
     */
    @SuppressWarnings("restriction")
    public static String getBase64FromByte(byte[] b) {
    /**
     * 提取字符串中的所有数字
     *
     * @param st
     * @return
     */
    public static String getNumberFromString(String st) {
        String number = "";
        Pattern p = Pattern.compile("[0-9\\.]+");
        Matcher m = p.matcher(st);
        String s = null;
        if (b != null) {
            s = new BASE64Encoder().encode(b);
        }
        return s;
    }
        while (m.find()) {
            number += (m.group() + ",");
        }
        return number;
    }
    /**
     * 提取字符串中的所有数字
     *
     * @param st
     * @return
     */
    public static String getNumberFromString(String st) {
        String number = "";
        Pattern p = Pattern.compile("[0-9\\.]+");
        Matcher m = p.matcher(st);
    /**
     * 将字符串转为UTF-8编码
     *
     * @param resource
     * @param chactor
     * @return
     */
    public static String getUTF8String(String resource, String chactor) {
        if (!isNullOrEmpty(resource)) {
            try {
                return new String(resource.getBytes(chactor), "UTF-8");
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return "";
    }
        while (m.find()) {
            number += (m.group() + ",");
        }
        return number;
    }
    /**
     * Base64加密
     *
     * @param str
     * @return
     * @throws Exception
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public static String getBase64String(String str) throws Exception {
        byte[] input = str.getBytes("UTF-8");
        Class clazz = Class.forName("com.sun.org.apache.xerces.internal.impl.dv.util.Base64");
        Method mainMethod = clazz.getMethod("encode", byte[].class);
        mainMethod.setAccessible(true);
        Object retObj = mainMethod.invoke(null, new Object[] { input });
        return (String) retObj;
    }
    /**
     * 将字符串转为UTF-8编码
     *
     * @param resource
     * @param chactor
     * @return
     */
    public static String getUTF8String(String resource, String chactor) {
        if (!isNullOrEmpty(resource)) {
            try {
                return new String(resource.getBytes(chactor), "UTF-8");
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return "";
    }
    /**
     * BASE64解密
     *
     * @param s
     * @return
     */
    public static String getFromBase64(String s) {
        byte[] b = null;
        String result = null;
        if (s != null) {
            final Base64 base64 = new Base64();
            try {
                b = base64.decode(s.getBytes("UTF-8"));
                result = new String(b, "utf-8");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return result;
    }
    /**
     * Base64加密
     *
     * @param str
     * @return
     * @throws Exception
     */
    @SuppressWarnings({"unchecked", "rawtypes"})
    public static String getBase64String(String str) throws Exception {
        byte[] input = str.getBytes("UTF-8");
        Class clazz = Class.forName("com.sun.org.apache.xerces.internal.impl.dv.util.Base64");
        Method mainMethod = clazz.getMethod("encode", byte[].class);
        mainMethod.setAccessible(true);
        Object retObj = mainMethod.invoke(null, new Object[]{input});
        return (String) retObj;
    }
    /**
     * SHA1加密
     *
     * @param decript
     * @return
     */
    public static String SHA1(String decript) {
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA-1");
            digest.update(decript.getBytes());
            byte messageDigest[] = digest.digest();
            // Create Hex String
            StringBuffer hexString = new StringBuffer();
            // 字节数组转换�?十六进制 �?
            for (int i = 0; i < messageDigest.length; i++) {
                String shaHex = Integer.toHexString(messageDigest[i] & 0xFF);
                if (shaHex.length() < 2) {
                    hexString.append(0);
                }
                hexString.append(shaHex);
            }
            return hexString.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }
    /**
     * BASE64解密
     *
     * @param s
     * @return
     */
    public static String getFromBase64(String s) {
        byte[] b = null;
        String result = null;
        if (s != null) {
            final Base64 base64 = new Base64();
            try {
                b = base64.decode(s.getBytes("UTF-8"));
                result = new String(b, "utf-8");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return result;
    }
    public static long[] parseLong(String[] arr) {
        long[] lArr = new long[arr.length];
        int ii = 0;
        for (String str : arr) {
            lArr[ii] = Long.parseLong(str);
            ii++;
        }
        return lArr;
    }
    /**
     * SHA1加密
     *
     * @param decript
     * @return
     */
    public static String SHA1(String decript) {
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA-1");
            digest.update(decript.getBytes());
            byte messageDigest[] = digest.digest();
            // Create Hex String
            StringBuffer hexString = new StringBuffer();
            // 字节数组转换�?十六进制 �?
            for (int i = 0; i < messageDigest.length; i++) {
                String shaHex = Integer.toHexString(messageDigest[i] & 0xFF);
                if (shaHex.length() < 2) {
                    hexString.append(0);
                }
                hexString.append(shaHex);
            }
            return hexString.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }
    public static long[] parseLong(String[] arr) {
        long[] lArr = new long[arr.length];
        int ii = 0;
        for (String str : arr) {
            lArr[ii] = Long.parseLong(str);
            ii++;
        }
        return lArr;
    }
}
src/main/java/com/ks/tool/bkz/util/TBCookieUtil.java
New file
@@ -0,0 +1,22 @@
package com.ks.tool.bkz.util;
import java.util.HashMap;
import java.util.Map;
public class TBCookieUtil {
    public static Map<String, String> parseCookie(String cookie) {
        String[] cookies = cookie.split(";");
        Map<String, String> cookiesMap = new HashMap<>();
        for (String c : cookies) {
            cookiesMap.put(c.split("=")[0], c.split("=")[1]);
        }
        return cookiesMap;
    }
    public static String getTBUid(String cookies) {
        Map<String, String> cookiesMap = parseCookie(cookies);
        return cookiesMap.get("unb");
    }
}
src/main/java/com/ks/tool/bkz/util/TimeUtil.java
New file
@@ -0,0 +1,384 @@
package com.ks.tool.bkz.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
public class TimeUtil {
    private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    public static String getMonthDay(long time) {
        SimpleDateFormat sdf = new SimpleDateFormat("MM.dd");
        String date = sdf.format(new Date(time));
        return date;
    }
    public static String getHistoryTime(long time) {
        SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm");
        String date = sdf.format(new Date(time));
        return date;
    }
    public static String getAllTime(long time) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String date = sdf.format(new Date(time));
        return date;
    }
    public static String getWholeTime(long time) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String date = sdf.format(new Date(time));
        return date;
    }
    public static String getAllNoTime(long time) {
        // yyyy-MM-dd HH:mm:ss
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmm");
        String date = sdf.format(new Date(time));
        return date;
    }
    public static String getyyyyMMdd(long time) {
        // yyyy-MM-dd HH:mm:ss
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String date = sdf.format(new Date(time));
        return date;
    }
    public static String getCommonTime(long time) {
        // yyyy-MM-dd HH:mm:ss
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String date = sdf.format(new Date(time));
        sdf = new SimpleDateFormat("HH:mm");
        String hm = sdf.format(new Date(time));
        return date + "\n" + hm;
    }
    public static String getGernalTime(long time) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String date = sdf.format(new Date(time));
        return date;
    }
    public static String getGernalTime(long time, String format) {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        String date = sdf.format(new Date(time));
        return date;
    }
    public static String getExchangeAdTime(long time) {
        // yyyy-MM-dd HH:mm:ss
        SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm");
        String date = sdf.format(new Date(time));
        return date;
    }
    public static long convertDateToTemp(String st) {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            date = sdf.parse(st);
            return date.getTime();
        } catch (Exception e) {
             e.printStackTrace();
            return 0;
        }
    }
    public static Date parseYYYYMM(String st) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        try {
            return sdf.parse(st);
        } catch (Exception e) {
             e.printStackTrace();
            return null;
        }
    }
    public static Date parseYYYYMMDD_HHMMSS(String st) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            return sdf.parse(st);
        } catch (Exception e) {
             e.printStackTrace();
            return null;
        }
    }
    public static Date parseYYYYMMDD_HHMM(String st) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        try {
            return sdf.parse(st);
        } catch (Exception e) {
             e.printStackTrace();
            return null;
        }
    }
    public static Date parseYYYYMMDD(String st) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            return sdf.parse(st);
        } catch (Exception e) {
             e.printStackTrace();
            return null;
        }
    }
    public static Date parseDotYYYYMMDD(String st) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
        try {
            return sdf.parse(st);
        } catch (Exception e) {
             e.printStackTrace();
            return null;
        }
    }
    public static Date parseDotCommon(String st) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
        try {
            return sdf.parse(st);
        } catch (Exception e) {
             e.printStackTrace();
            return null;
        }
    }
    public static Date parseDotCommon2(String st) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm");
        try {
            return sdf.parse(st);
        } catch (Exception e) {
             e.printStackTrace();
            return null;
        }
    }
    public static long convertAllTimeToTemp(String st) {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        try {
            date = sdf.parse(st);
            return date.getTime();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }
    public static String formatDate(long time) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm");
        String date = sdf.format(new Date(time));
        return date;
    }
    public static String formatDate(Date time) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm");
        String date = sdf.format(time);
        return date;
    }
    public static String formatDateDot(Date time) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
        String date = sdf.format(time);
        return date;
    }
    public static String formatHHMM_12H(Date time) {
        SimpleDateFormat sdf = new SimpleDateFormat("hh:mm");
        String date = sdf.format(time);
        return date;
    }
    public static String formatYMDHHMM(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        try {
            return sdf.format(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    public static String formatDateAddT(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
        try {
            return sdf.format(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    public static long convertToTimeTemp(String st, String format) {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        try {
            date = sdf.parse(st);
            return date.getTime();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }
    public static long convertDateToTemp1(String st) {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
        try {
            date = sdf.parse(st);
            return date.getTime();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }
    public static long convertDateToTemp2(String st) {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            date = sdf.parse(st);
            return date.getTime();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }
    public static boolean isSameDay(String time1, String time2) {
        if (getGernalTime(Long.parseLong(time1)).equalsIgnoreCase(getGernalTime(Long.parseLong(time2))))
            return true;
        else
            return false;
    }
    public static Date getNextDay(int day) {
        long current = System.currentTimeMillis();
        long date = current / 86400000 * 86400000 - TimeZone.getDefault().getRawOffset();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date(date));
        calendar.add(Calendar.DATE, day);
        int y = calendar.get(Calendar.YEAR);
        int m = calendar.get(Calendar.MONTH);
        int d = calendar.get(Calendar.DAY_OF_MONTH);
        calendar.set(y, m, d);
        return calendar.getTime();
    }
    public static Date getNextDay(int day, long curtime) {
        long current = curtime;
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date(current));
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.add(Calendar.DATE, day);
        int y = calendar.get(Calendar.YEAR);
        int m = calendar.get(Calendar.MONTH);
        int d = calendar.get(Calendar.DAY_OF_MONTH);
        calendar.set(y, m, d);
        return calendar.getTime();
    }
    public static List<String> getEmupDate(int days) {
        days = -days + 1;
        List<String> list = new ArrayList<String>();
        for (int ii = days; ii <= 0; ii++) {
            list.add(dateFormat.format(getNextDay(ii)));
        }
        return list;
    }
    public static List<String> getEmupDate(int days, long endtime) {
        days = -days;
        List<String> list = new ArrayList<String>();
        for (int ii = days; ii <= 0; ii++) {
            list.add(dateFormat.format(getNextDay(ii, endtime)));
        }
        return list;
    }
    public static String getSimpleDate(Date date) {
        String format = dateFormat.format(date);
        return format;
    }
    public static String getSimpleDateMonth(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        String format = sdf.format(date);
        return format;
    }
    public static String getMonthOnlyMM(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("MM");
        String format = sdf.format(date);
        return format;
    }
    public static String getYearOnlyYYYY(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        String format = sdf.format(date);
        return format;
    }
    public static int getDayOfMonth() {
        Calendar aCalendar = Calendar.getInstance(Locale.CHINA);
        int day = aCalendar.getActualMaximum(Calendar.DATE);
        return day;
    }
    public static Date parse(String time) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.parse(time);
    }
    public static String yyyyMMddHHmmss(long time) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String date = sdf.format(new Date(time));
        return date;
    }
    /**
     * 获取两个时间的天数差值
     *
     * @param from
     * @param to
     * @return
     */
    public static int getDayDifferenceCount(Date from, Date to) {
        Calendar cal1 = Calendar.getInstance();
        cal1.setTime(from);
        Calendar cal2 = Calendar.getInstance();
        cal2.setTime(to);
        int day1 = cal1.get(Calendar.DAY_OF_YEAR);
        int day2 = cal2.get(Calendar.DAY_OF_YEAR);
        int year1 = cal1.get(Calendar.YEAR);
        int year2 = cal2.get(Calendar.YEAR);
        if (year1 != year2) { // 同一年
            int timeDistance = 0;
            for (int i = year1; i < year2; i++) {
                if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) { // 闰年
                    timeDistance += 366;
                } else { // 不是闰年
                    timeDistance += 365;
                }
            }
            return timeDistance + (day2 - day1);
        } else { // 不同年
            return day2 - day1;
        }
    }
}
src/main/java/com/ks/tool/bkz/util/UserUtil.java
New file
@@ -0,0 +1,30 @@
package com.ks.tool.bkz.util;
public class UserUtil {
    /**
     * 获取用户的token
     *
     * @param account
     * @return
     */
    public static String getToken(String account, long time) {
        return AESUtil.encrypt(account + "#" + time);
    }
    /**
     * 获取账号
     *
     * @param token
     * @return
     */
    public static String getAccountFromToken(String token) {
        String d = AESUtil.decrypt(token);
        return d.substring(0, d.lastIndexOf("#"));
    }
    public static long getTokenTime(String token){
        String d = AESUtil.decrypt(token);
        return Long.parseLong(d.substring( d.lastIndexOf("#")+1,d.length()));
    }
}
src/main/java/com/ks/tool/bkz/util/VerifyCodeUtil.java
New file
@@ -0,0 +1,273 @@
package com.ks.tool.bkz.util;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Random;
import javax.imageio.ImageIO;
public class VerifyCodeUtil {
    // 使用到Algerian字体,系统里没有的话安装字体,字体只显示大写,去掉了1,0,i,o几个容易混淆的字
    public static final String VERIFY_CODES = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ";
    private static Random random = new Random();
    /**
     * 使用系统默认字符源生成验证码
     *
     * @param verifySize
     *            验证码长度
     * @return
     */
    public static String generateVerifyCode(int verifySize) {
        return generateVerifyCode(verifySize, VERIFY_CODES);
    }
    /**
     * 使用指定源生成验证码
     *
     * @param verifySize
     *            验证码长度
     * @param sources
     *            验证码字符源
     * @return
     */
    public static String generateVerifyCode(int verifySize, String sources) {
        if (sources == null || sources.length() == 0) {
            sources = VERIFY_CODES;
        }
        int codesLen = sources.length();
        Random rand = new Random(System.currentTimeMillis());
        StringBuilder verifyCode = new StringBuilder(verifySize);
        for (int i = 0; i < verifySize; i++) {
            verifyCode.append(sources.charAt(rand.nextInt(codesLen - 1)));
        }
        return verifyCode.toString();
    }
    /**
     * 生成随机验证码文并返回验证码
     *
     * @param w
     * @param h
     * @param outputFile
     * @param verifySize
     * @return
     * @throws IOException
     */
    public static String outputVerifyImage(int w, int h, File outputFile, int verifySize) throws IOException {
        String verifyCode = generateVerifyCode(verifySize);
        outputImage(w, h, outputFile, verifyCode);
        return verifyCode;
    }
    /**
     * 输出随机验证码图片流,并返回验证码
     *
     * @param w
     * @param h
     * @param os
     * @param verifySize
     * @return
     * @throws IOException
     */
    public static String outputVerifyImage(int w, int h, OutputStream os, int verifySize) throws IOException {
        String verifyCode = generateVerifyCode(verifySize);
        outputImage(w, h, os, verifyCode);
        return verifyCode;
    }
    /**
     * 生成指定验证码图像文
     *
     * @param w
     * @param h
     * @param outputFile
     * @param code
     * @throws IOException
     */
    public static void outputImage(int w, int h, File outputFile, String code) throws IOException {
        if (outputFile == null) {
            return;
        }
        File dir = outputFile.getParentFile();
        if (!dir.exists()) {
            dir.mkdirs();
        }
        try {
            outputFile.createNewFile();
            FileOutputStream fos = new FileOutputStream(outputFile);
            outputImage(w, h, fos, code);
            fos.close();
        } catch (IOException e) {
            throw e;
        }
    }
    /**
     * 输出指定验证码图片流
     *
     * @param w
     * @param h
     * @param os
     * @param code
     * @throws IOException
     */
    public static void outputImage(int w, int h, OutputStream os, String code) throws IOException {
        int verifySize = code.length();
        BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
        Random rand = new Random();
        Graphics2D g2 = image.createGraphics();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        Color[] colors = new Color[5];
        Color[] colorSpaces = new Color[] { Color.WHITE, Color.CYAN, Color.GRAY, Color.LIGHT_GRAY, Color.MAGENTA,
                Color.ORANGE, Color.PINK, Color.YELLOW };
        float[] fractions = new float[colors.length];
        for (int i = 0; i < colors.length; i++) {
            colors[i] = colorSpaces[rand.nextInt(colorSpaces.length)];
            fractions[i] = rand.nextFloat();
        }
        Arrays.sort(fractions);
        g2.setColor(Color.GRAY);// 设置边框
        g2.fillRect(0, 0, w, h);
        Color c = getRandColor(200, 250);
        g2.setColor(c);// 设置背景
        g2.fillRect(0, 2, w, h - 4);
        // 绘制干扰
        Random random = new Random();
        g2.setColor(getRandColor(160, 200));// 设置线条的颜色
        for (int i = 0; i < 20; i++) {
            int x = random.nextInt(w - 1);
            int y = random.nextInt(h - 1);
            int xl = random.nextInt(6) + 1;
            int yl = random.nextInt(12) + 1;
            g2.drawLine(x, y, x + xl + 40, y + yl + 20);
        }
        // 添加噪点
        float yawpRate = 0.05f;// 噪声
        int area = (int) (yawpRate * w * h);
        for (int i = 0; i < area; i++) {
            int x = random.nextInt(w);
            int y = random.nextInt(h);
            int rgb = getRandomIntColor();
            image.setRGB(x, y, rgb);
        }
        shear(g2, w, h, c);// 使图片扭
        g2.setColor(getRandColor(100, 160));
        int fontSize = h - 4;
        Font font = new Font("Algerian", Font.ITALIC, fontSize);
        g2.setFont(font);
        char[] chars = code.toCharArray();
        for (int i = 0; i < verifySize; i++) {
            AffineTransform affine = new AffineTransform();
            affine.setToRotation(Math.PI / 4 * rand.nextDouble() * (rand.nextBoolean() ? 1 : -1),
                    (w / verifySize) * i + fontSize / 2, h / 2);
            g2.setTransform(affine);
            g2.drawChars(chars, i, 1, ((w - 10) / verifySize) * i + 5, h / 2 + fontSize / 2 - 10);
        }
        g2.dispose();
        ImageIO.write(image, "JPEG", os);
    }
    private static Color getRandColor(int fc, int bc) {
        if (fc > 255)
            fc = 255;
        if (bc > 255)
            bc = 255;
        int r = fc + random.nextInt(bc - fc);
        int g = fc + random.nextInt(bc - fc);
        int b = fc + random.nextInt(bc - fc);
        return new Color(r, g, b);
    }
    private static int getRandomIntColor() {
        int[] rgb = getRandomRgb();
        int color = 0;
        for (int c : rgb) {
            color = color << 8;
            color = color | c;
        }
        return color;
    }
    private static int[] getRandomRgb() {
        int[] rgb = new int[3];
        for (int i = 0; i < 3; i++) {
            rgb[i] = random.nextInt(255);
        }
        return rgb;
    }
    private static void shear(Graphics g, int w1, int h1, Color color) {
        shearX(g, w1, h1, color);
        shearY(g, w1, h1, color);
    }
    private static void shearX(Graphics g, int w1, int h1, Color color) {
        int period = random.nextInt(2);
        boolean borderGap = true;
        int frames = 1;
        int phase = random.nextInt(2);
        for (int i = 0; i < h1; i++) {
            double d = (double) (period >> 1)
                    * Math.sin((double) i / (double) period + (6.2831853071795862D * (double) phase) / (double) frames);
            g.copyArea(0, i, w1, 1, (int) d, 0);
            if (borderGap) {
                g.setColor(color);
                g.drawLine((int) d, i, 0, i);
                g.drawLine((int) d + w1, i, w1, i);
            }
        }
    }
    private static void shearY(Graphics g, int w1, int h1, Color color) {
        int period = random.nextInt(40) + 10; // 50;
        boolean borderGap = true;
        int frames = 20;
        int phase = 7;
        for (int i = 0; i < w1; i++) {
            double d = (double) (period >> 1)
                    * Math.sin((double) i / (double) period + (6.2831853071795862D * (double) phase) / (double) frames);
            g.copyArea(i, 0, 1, h1, 0, (int) d);
            if (borderGap) {
                g.setColor(color);
                g.drawLine(i, (int) d, i, 0);
                g.drawLine(i, (int) d + h1, i, h1);
            }
        }
    }
    public static void main(String[] args) throws IOException {
        File dir = new File("F:/verifies");
        int w = 200, h = 80;
        for (int i = 0; i < 50; i++) {
            String verifyCode = generateVerifyCode(4);
            File file = new File(dir, verifyCode + ".jpg");
            outputImage(w, h, file, verifyCode);
        }
    }
}
src/main/java/com/ks/tool/bkz/util/email/MailSendInfo.java
New file
@@ -0,0 +1,105 @@
package com.ks.tool.bkz.util.email;
import java.util.Properties;
public class MailSendInfo {
    private String mailServerHost;
    private String mailServerPort = "25";
    private String fromAddress;
    private String toAddress;
    private String userName;
    private String password;
    private boolean validate = false;
    private String subject;
    private String content;
    private String[] attachFileNames;
    public Properties getProperties() {
        Properties p = new Properties();
        p.put("mail.smtp.host", this.mailServerHost);
        p.put("mail.smtp.port", this.mailServerPort);
        p.put("mail.smtp.auth", validate ? "true" : "false");
        return p;
    }
    public String getMailServerHost() {
        return mailServerHost;
    }
    public void setMailServerHost(String mailServerHost) {
        this.mailServerHost = mailServerHost;
    }
    public String getMailServerPort() {
        return mailServerPort;
    }
    public void setMailServerPort(String mailServerPort) {
        this.mailServerPort = mailServerPort;
    }
    public boolean isValidate() {
        return validate;
    }
    public void setValidate(boolean validate) {
        this.validate = validate;
    }
    public String[] getAttachFileNames() {
        return attachFileNames;
    }
    public void setAttachFileNames(String[] fileNames) {
        this.attachFileNames = fileNames;
    }
    public String getFromAddress() {
        return fromAddress;
    }
    public void setFromAddress(String fromAddress) {
        this.fromAddress = fromAddress;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String getToAddress() {
        return toAddress;
    }
    public void setToAddress(String toAddress) {
        this.toAddress = toAddress;
    }
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    public String getSubject() {
        return subject;
    }
    public void setSubject(String subject) {
        this.subject = subject;
    }
    public String getContent() {
        return content;
    }
    public void setContent(String textContent) {
        this.content = textContent;
    }
}
src/main/java/com/ks/tool/bkz/util/email/MailSenderUtil.java
New file
@@ -0,0 +1,109 @@
package com.ks.tool.bkz.util.email;
import com.alibaba.fastjson.JSONObject;
import com.ks.tool.bkz.util.HttpUtil;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Date;
import java.util.Properties;
public class MailSenderUtil {
    public static boolean sendTextMail(MailSendInfo mailInfo) {
        MyAuthenticator authenticator = null;
        Properties pro = mailInfo.getProperties();
        if (mailInfo.isValidate()) {
            authenticator = new MyAuthenticator(mailInfo.getUserName(), mailInfo.getPassword());
        }
        Session sendMailSession = Session.getDefaultInstance(pro, authenticator);
        try {
            Message mailMessage = new MimeMessage(sendMailSession);
            Address from = new InternetAddress(mailInfo.getFromAddress());
            mailMessage.setFrom(from);
            Address to = new InternetAddress(mailInfo.getToAddress());
            mailMessage.setRecipient(Message.RecipientType.TO, to);
            mailMessage.setSubject(mailInfo.getSubject());
            mailMessage.setSentDate(new Date());
            String mailContent = mailInfo.getContent();
            mailMessage.setText(mailContent);
            Transport.send(mailMessage);
            return true;
        } catch (MessagingException ex) {
            ex.printStackTrace();
        }
        return false;
    }
    public static boolean sendHtmlMail(MailSendInfo mailInfo) {
        MyAuthenticator authenticator = null;
        Properties pro = mailInfo.getProperties();
        if (mailInfo.isValidate()) {
            authenticator = new MyAuthenticator(mailInfo.getUserName(), mailInfo.getPassword());
        }
        Session sendMailSession = Session.getDefaultInstance(pro, authenticator);
        try {
            Message mailMessage = new MimeMessage(sendMailSession);
            Address from = new InternetAddress(mailInfo.getFromAddress());
            mailMessage.setFrom(from);
            Address to = new InternetAddress(mailInfo.getToAddress());
            mailMessage.setRecipient(Message.RecipientType.TO, to);
            mailMessage.setSubject(mailInfo.getSubject());
            mailMessage.setSentDate(new Date());
            Multipart mainPart = new MimeMultipart();
            BodyPart html = new MimeBodyPart();
            html.setContent(mailInfo.getContent(), "text/html; charset=utf-8");
            mainPart.addBodyPart(html);
            mailMessage.setContent(mainPart);
            Transport.send(mailMessage);
            return true;
        } catch (MessagingException ex) {
            ex.printStackTrace();
        }
        return false;
    }
    public static boolean sendEmail(String email, String title, String content) {
        String username = "baokuanzhu@163.com";
        String pwd = "PFUNNXGCCTSNOPPX";
        MailSendInfo mailInfo = new MailSendInfo();
        mailInfo.setMailServerHost("smtp." + username.split("@")[1]);
        mailInfo.setMailServerPort("25");
        mailInfo.setValidate(true);
        mailInfo.setUserName(username);
        mailInfo.setPassword(pwd);
        mailInfo.setFromAddress(username);
        mailInfo.setToAddress(email);
        mailInfo.setSubject(title);
        StringBuffer buffer = new StringBuffer();
        buffer.append(content);
        mailInfo.setContent(buffer.toString());
        return sendTextMail(mailInfo);
    }
    public static boolean sendEmail(String toEmail, String fromEmail, String fromEmailPwd, String title,
            String content) {
        try {
            String url = String.format(
                    "http://193.112.34.40:9001/BuWan/email/sendEmail?fromAccount=%s&fromPwd=%s&toAccount=%s&title=%s&content=%s",
                    URLEncoder.encode(fromEmail, "UTF-8"), URLEncoder.encode(fromEmailPwd, "UTF-8"),
                    URLEncoder.encode(toEmail, "UTF-8"), URLEncoder.encode(title, "UTF-8"),
                    URLEncoder.encode(content, "UTF-8"));
            String result = HttpUtil.get(url);
            JSONObject data =JSONObject.parseObject(result);
            if (data.getInteger("code") == 0)
                return true;
            else
                return false;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return false;
    }
}
src/main/java/com/ks/tool/bkz/util/email/MyAuthenticator.java
New file
@@ -0,0 +1,21 @@
package com.ks.tool.bkz.util.email;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
public class MyAuthenticator extends Authenticator {
    String userName = null;
    String password = null;
    public MyAuthenticator() {
    }
    public MyAuthenticator(String username, String password) {
        this.userName = username;
        this.password = password;
    }
    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(userName, password);
    }
}
src/main/java/com/ks/tool/bkz/vo/sdlj/SDLJGoodsInfoVO.java
@@ -3,6 +3,7 @@
import java.util.List;
public class SDLJGoodsInfoVO {
    private int index;
    private String title;
    private String zkPrice;
    private String couponPrice;
@@ -13,6 +14,14 @@
    private String commissionRate;
    private List<String> imgList;
    public int getIndex() {
        return index;
    }
    public void setIndex(int index) {
        this.index = index;
    }
    public String getTitle() {
        return title;
    }
src/main/resources/application.yml
@@ -10,9 +10,9 @@
      enabled: true
  datasource:
    url: jdbc:mysql://gz-cdb-r13d0yi9.sql.tencentcdb.com:62929/test
    url: jdbc:mysql://192.168.1.253:3306/tbtool?serverTimezone=UTC
    username: root
    password: Yeshi2016@
    password: 123456
    driver-class-name: com.mysql.jdbc.Driver
    type: com.alibaba.druid.pool.DruidDataSource
    druid:
src/main/resources/generatorConfig.xml
New file
@@ -0,0 +1,81 @@
<!DOCTYPE generatorConfiguration
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
    <!-- 数据库驱动:选择你的本地硬盘上面的数据库驱动包-->
    <classPathEntry
            location="C:\Users\Administrator\.m2\repository\mysql\mysql-connector-java\5.1.47\mysql-connector-java-5.1.47.jar"/>
    <context id="mysql" targetRuntime="MyBatis3">
        <commentGenerator>
            <!-- 是否去除自动生成的注释 true:是 : false:否 -->
            <property name="suppressAllComments" value="true"/>
            <!-- 将数据库中表的字段描述信息添加到注释 -->
            <property name="addRemarkComments" value="true"/>
            <!-- 注释里不添加日期 -->
            <property name="suppressDate" value="false"/>
        </commentGenerator>
        <!--数据库链接URL,用户名、密码 -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://192.168.1.253:3306/tbtool"
                        userId="root" password="123456">
        </jdbcConnection>
        <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和
        NUMERIC 类型解析为java.math.BigDecimal -->
        <javaTypeResolver>
            <property name="forceBigDecimals" value="true"/>
        </javaTypeResolver>
        <!-- 生成模型的包名和位置-->
        <javaModelGenerator targetPackage="com.ks.tool.bkz.entity.auto" targetProject="src/main/java">
            <!-- enableSubPackages:是否让schema作为包的后缀 -->
            <property name="enableSubPackages" value="true"/>
           <!-- 从数据库返回的值被清理前后的空格 -->
             <property name="trimStrings" value="false"/>
         </javaModelGenerator>
        <!-- 生成映射文件的包名和位置-->
        <!-- targetProject:mapper映射文件生成的位置
        如果maven工程只是单独的一个工程,targetProject="src/main/java"
        若果maven工程是分模块的工程,targetProject="所属模块的名称",例如:
        targetProject="ecps-manager-mapper",下同-->
        <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources/auto">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>
        <!-- 生成DAO的包名和位置-->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.ks.tool.bkz.dao.mybatis.auto"
                             targetProject="src/main/java">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>
        <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
        <!--
        enableCountByExample="true"
        enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true"
        selectByExampleQueryId="true"
        -->
        <!--
        <table tableName="tt_user" domainObjectName="UserInfo"  enableCountByExample="false"
               enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false"/>
               -->
        <!--
                <table tableName="tt_card_pwd_info" domainObjectName="CardPwdInfo"  enableCountByExample="false"
                       enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
                       selectByExampleQueryId="false"/>
        -->
                <table tableName="tt_sdlj_share_open_history" domainObjectName="SDLJShareOpenHistory"  enableCountByExample="false"
                       enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
                       selectByExampleQueryId="false"/>
            </context>
        </generatorConfiguration>
src/main/resources/mapper/CardPwdInfoMapper.xml
New file
@@ -0,0 +1,149 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.ks.tool.bkz.dao.mybatis.user.CardPwdInfoMapper" >
  <resultMap id="BaseResultMap" type="com.ks.tool.bkz.entity.user.CardPwdInfo" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="card" property="card" jdbcType="VARCHAR" />
    <result column="pwd" property="pwd" jdbcType="VARCHAR" />
    <result column="type" property="type" jdbcType="INTEGER" />
    <result column="consume_state" property="consumeState" jdbcType="INTEGER" />
    <result column="consume_time" property="consumeTime" jdbcType="TIMESTAMP" />
    <result column="consume_uid" property="consumeUid" jdbcType="BIGINT" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, card, pwd, type, consume_state, consume_time, consume_uid, create_time, update_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select
    <include refid="Base_Column_List" />
    from tt_card_pwd_info
    where id = #{id,jdbcType=BIGINT}
  </select>
  <select id="selectByCard" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select
    <include refid="Base_Column_List" />
    from tt_card_pwd_info
    where card = #{0}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
    delete from tt_card_pwd_info
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="com.ks.tool.bkz.entity.user.CardPwdInfo" >
    insert into tt_card_pwd_info (id, card, pwd,
      type, consume_state, consume_time,
      consume_uid, create_time, update_time
      )
    values (#{id,jdbcType=BIGINT}, #{card,jdbcType=VARCHAR}, #{pwd,jdbcType=VARCHAR},
      #{type,jdbcType=INTEGER}, #{consumeState,jdbcType=INTEGER}, #{consumeTime,jdbcType=TIMESTAMP},
      #{consumeUid,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.ks.tool.bkz.entity.user.CardPwdInfo" >
    insert into tt_card_pwd_info
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="card != null" >
        card,
      </if>
      <if test="pwd != null" >
        pwd,
      </if>
      <if test="type != null" >
        type,
      </if>
      <if test="consumeState != null" >
        consume_state,
      </if>
      <if test="consumeTime != null" >
        consume_time,
      </if>
      <if test="consumeUid != null" >
        consume_uid,
      </if>
      <if test="createTime != null" >
        create_time,
      </if>
      <if test="updateTime != null" >
        update_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=BIGINT},
      </if>
      <if test="card != null" >
        #{card,jdbcType=VARCHAR},
      </if>
      <if test="pwd != null" >
        #{pwd,jdbcType=VARCHAR},
      </if>
      <if test="type != null" >
        #{type,jdbcType=INTEGER},
      </if>
      <if test="consumeState != null" >
        #{consumeState,jdbcType=INTEGER},
      </if>
      <if test="consumeTime != null" >
        #{consumeTime,jdbcType=TIMESTAMP},
      </if>
      <if test="consumeUid != null" >
        #{consumeUid,jdbcType=BIGINT},
      </if>
      <if test="createTime != null" >
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null" >
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.ks.tool.bkz.entity.user.CardPwdInfo" >
    update tt_card_pwd_info
    <set >
      <if test="card != null" >
        card = #{card,jdbcType=VARCHAR},
      </if>
      <if test="pwd != null" >
        pwd = #{pwd,jdbcType=VARCHAR},
      </if>
      <if test="type != null" >
        type = #{type,jdbcType=INTEGER},
      </if>
      <if test="consumeState != null" >
        consume_state = #{consumeState,jdbcType=INTEGER},
      </if>
      <if test="consumeTime != null" >
        consume_time = #{consumeTime,jdbcType=TIMESTAMP},
      </if>
      <if test="consumeUid != null" >
        consume_uid = #{consumeUid,jdbcType=BIGINT},
      </if>
      <if test="createTime != null" >
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null" >
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.ks.tool.bkz.entity.user.CardPwdInfo" >
    update tt_card_pwd_info
    set card = #{card,jdbcType=VARCHAR},
      pwd = #{pwd,jdbcType=VARCHAR},
      type = #{type,jdbcType=INTEGER},
      consume_state = #{consumeState,jdbcType=INTEGER},
      consume_time = #{consumeTime,jdbcType=TIMESTAMP},
      consume_uid = #{consumeUid,jdbcType=BIGINT},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=BIGINT}
  </update>
</mapper>
src/main/resources/mapper/SDLJShareOpenHistoryMapper.xml
New file
@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.ks.tool.bkz.dao.mybatis.user.SDLJShareOpenHistoryMapper" >
  <resultMap id="BaseResultMap" type="com.ks.tool.bkz.entity.user.SDLJShareOpenHistory" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="uid" property="uid" jdbcType="BIGINT" />
    <result column="start_time" property="startTime" jdbcType="TIMESTAMP" />
    <result column="expire_time" property="expireTime" jdbcType="TIMESTAMP" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, uid, start_time, expire_time, create_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select
    <include refid="Base_Column_List" />
    from tt_sdlj_share_open_history
    where id = #{id,jdbcType=BIGINT}
  </select>
  <select id="selectLatestOpenHistory" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select
    <include refid="Base_Column_List" />
    from tt_sdlj_share_open_history
    where uid = #{0} order by expire_time desc limit 1
  </select>
  <select id="selectByUidAndTime" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from tt_sdlj_share_open_history
    where uid = #{uid} and create_time>=#{time} and #{time}>expire_time limit 1
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
    delete from tt_sdlj_share_open_history
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="com.ks.tool.bkz.entity.user.SDLJShareOpenHistory" >
    insert into tt_sdlj_share_open_history (id, uid, start_time,
      expire_time, create_time)
    values (#{id,jdbcType=BIGINT}, #{uid,jdbcType=BIGINT}, #{startTime,jdbcType=TIMESTAMP},
      #{expireTime,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.ks.tool.bkz.entity.user.SDLJShareOpenHistory" >
    insert into tt_sdlj_share_open_history
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="uid != null" >
        uid,
      </if>
      <if test="startTime != null" >
        start_time,
      </if>
      <if test="expireTime != null" >
        expire_time,
      </if>
      <if test="createTime != null" >
        create_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=BIGINT},
      </if>
      <if test="uid != null" >
        #{uid,jdbcType=BIGINT},
      </if>
      <if test="startTime != null" >
        #{startTime,jdbcType=TIMESTAMP},
      </if>
      <if test="expireTime != null" >
        #{expireTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createTime != null" >
        #{createTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.ks.tool.bkz.entity.user.SDLJShareOpenHistory" >
    update tt_sdlj_share_open_history
    <set >
      <if test="uid != null" >
        uid = #{uid,jdbcType=BIGINT},
      </if>
      <if test="startTime != null" >
        start_time = #{startTime,jdbcType=TIMESTAMP},
      </if>
      <if test="expireTime != null" >
        expire_time = #{expireTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createTime != null" >
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.ks.tool.bkz.entity.user.SDLJShareOpenHistory" >
    update tt_sdlj_share_open_history
    set uid = #{uid,jdbcType=BIGINT},
      start_time = #{startTime,jdbcType=TIMESTAMP},
      expire_time = #{expireTime,jdbcType=TIMESTAMP},
      create_time = #{createTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=BIGINT}
  </update>
</mapper>
src/main/resources/mapper/UserInfoMapper.xml
New file
@@ -0,0 +1,162 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.ks.tool.bkz.dao.mybatis.user.UserInfoMapper" >
  <resultMap id="BaseResultMap" type="com.ks.tool.bkz.entity.user.UserInfo" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="account" property="account" jdbcType="VARCHAR" />
    <result column="level" property="level" jdbcType="INTEGER" />
    <result column="login_time" property="loginTime" jdbcType="TIMESTAMP" />
    <result column="super_time" property="superTime" jdbcType="TIMESTAMP" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
    <result column="login_ip_info" property="loginIpInfo" jdbcType="VARCHAR" />
    <result column="state" property="state" jdbcType="INTEGER" />
    <result column="state_desc" property="stateDesc" jdbcType="VARCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, account, level, login_time, super_time, create_time, update_time, login_ip_info,
    state, state_desc
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select
    <include refid="Base_Column_List" />
    from tt_user
    where id = #{id,jdbcType=BIGINT}
  </select>
  <select id="selectByAccount" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select
    <include refid="Base_Column_List" />
    from tt_user
    where account = #{0}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
    delete from tt_user
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="com.ks.tool.bkz.entity.user.UserInfo" >
    insert into tt_user (id, account, level,
      login_time, super_time, create_time,
      update_time, login_ip_info, state,
      state_desc)
    values (#{id,jdbcType=BIGINT}, #{account,jdbcType=VARCHAR}, #{level,jdbcType=INTEGER},
      #{loginTime,jdbcType=TIMESTAMP}, #{superTime,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP},
      #{updateTime,jdbcType=TIMESTAMP}, #{loginIpInfo,jdbcType=VARCHAR}, #{state,jdbcType=INTEGER},
      #{stateDesc,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.ks.tool.bkz.entity.user.UserInfo" >
    insert into tt_user
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="account != null" >
        account,
      </if>
      <if test="level != null" >
        level,
      </if>
      <if test="loginTime != null" >
        login_time,
      </if>
      <if test="superTime != null" >
        super_time,
      </if>
      <if test="createTime != null" >
        create_time,
      </if>
      <if test="updateTime != null" >
        update_time,
      </if>
      <if test="loginIpInfo != null" >
        login_ip_info,
      </if>
      <if test="state != null" >
        state,
      </if>
      <if test="stateDesc != null" >
        state_desc,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=BIGINT},
      </if>
      <if test="account != null" >
        #{account,jdbcType=VARCHAR},
      </if>
      <if test="level != null" >
        #{level,jdbcType=INTEGER},
      </if>
      <if test="loginTime != null" >
        #{loginTime,jdbcType=TIMESTAMP},
      </if>
      <if test="superTime != null" >
        #{superTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createTime != null" >
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null" >
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="loginIpInfo != null" >
        #{loginIpInfo,jdbcType=VARCHAR},
      </if>
      <if test="state != null" >
        #{state,jdbcType=INTEGER},
      </if>
      <if test="stateDesc != null" >
        #{stateDesc,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.ks.tool.bkz.entity.user.UserInfo" >
    update tt_user
    <set >
      <if test="account != null" >
        account = #{account,jdbcType=VARCHAR},
      </if>
      <if test="level != null" >
        level = #{level,jdbcType=INTEGER},
      </if>
      <if test="loginTime != null" >
        login_time = #{loginTime,jdbcType=TIMESTAMP},
      </if>
      <if test="superTime != null" >
        super_time = #{superTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createTime != null" >
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null" >
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="loginIpInfo != null" >
        login_ip_info = #{loginIpInfo,jdbcType=VARCHAR},
      </if>
      <if test="state != null" >
        state = #{state,jdbcType=INTEGER},
      </if>
      <if test="stateDesc != null" >
        state_desc = #{stateDesc,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.ks.tool.bkz.entity.user.UserInfo" >
    update tt_user
    set account = #{account,jdbcType=VARCHAR},
      level = #{level,jdbcType=INTEGER},
      login_time = #{loginTime,jdbcType=TIMESTAMP},
      super_time = #{superTime,jdbcType=TIMESTAMP},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP},
      login_ip_info = #{loginIpInfo,jdbcType=VARCHAR},
      state = #{state,jdbcType=INTEGER},
      state_desc = #{stateDesc,jdbcType=VARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>
</mapper>
src/test/java/com/ks/tool/bkz/UserTest.java
New file
@@ -0,0 +1,61 @@
package com.ks.tool.bkz;
import com.ks.tool.bkz.dao.mybatis.user.CardPwdInfoMapper;
import com.ks.tool.bkz.dao.mybatis.user.SDLJShareOpenHistoryMapper;
import com.ks.tool.bkz.dao.mybatis.user.UserInfoMapper;
import com.ks.tool.bkz.entity.user.CardPwdTypeEnum;
import com.ks.tool.bkz.util.CardPwdUtil;
import com.ks.tool.bkz.util.TimeUtil;
import com.ks.tool.bkz.util.UserUtil;
import com.ks.tool.bkz.util.email.MailSenderUtil;
import org.junit.jupiter.api.Test;
import javax.annotation.Resource;
import java.util.Date;
//@SpringBootTest
public class UserTest {
    @Resource
    private UserInfoMapper userInfoMapper;
    @Resource
    private CardPwdInfoMapper cardPwdInfoMapper;
    @Resource
    private SDLJShareOpenHistoryMapper sdljShareOpenHistoryMapper;
    @Test
    public void testTime() {
        Date date = CardPwdUtil.getExpireTime(new Date(TimeUtil.convertToTimeTemp("2020-06-17 13:49:49", "yyyy-MM-dd HH:mm:ss")), CardPwdTypeEnum.sdljShort);
        System.out.println(TimeUtil.getGernalTime(date.getTime(),"yyyy-MM-dd HH:mm:ss"));
        date = CardPwdUtil.getExpireTime(new Date(TimeUtil.convertToTimeTemp("2020-06-17 13:49:49", "yyyy-MM-dd HH:mm:ss")), CardPwdTypeEnum.sdljMonth);
        System.out.println(TimeUtil.getGernalTime(date.getTime(),"yyyy-MM-dd HH:mm:ss"));
        date = CardPwdUtil.getExpireTime(new Date(TimeUtil.convertToTimeTemp("2020-06-17 13:49:49", "yyyy-MM-dd HH:mm:ss")), CardPwdTypeEnum.sdljSeason);
        System.out.println(TimeUtil.getGernalTime(date.getTime(),"yyyy-MM-dd HH:mm:ss"));
        date = CardPwdUtil.getExpireTime(new Date(TimeUtil.convertToTimeTemp("2020-06-17 13:49:49", "yyyy-MM-dd HH:mm:ss")), CardPwdTypeEnum.sdljYear);
        System.out.println(TimeUtil.getGernalTime(date.getTime(),"yyyy-MM-dd HH:mm:ss"));
    }
    @Test
    public void testMapper(){
        userInfoMapper.selectByAccount("1101184511@qq.com");
        cardPwdInfoMapper.selectByCard("123123");
        sdljShareOpenHistoryMapper.selectLatestOpenHistory(1L);
        sdljShareOpenHistoryMapper.selectByUidAndTime(1L,new Date());
    }
    @Test
    public void testAES(){
        String token= UserUtil.getToken("1101184511@qq.com",System.currentTimeMillis());
        String account=UserUtil.getAccountFromToken(token);
        System.out.println(token+":"+account);
        System.out.println(UserUtil.getTokenTime(token));
    }
    @Test
    public void testSendEmail(){
        String code="123456";
        MailSenderUtil.sendEmail("hexiaohui@banliapp.com", "爆款猪登录验证", "登录验证码为:" + code);
    }
}