liuxiaolong
2019-05-09 0d1d88cdb668e75ea8609417ac18ae19947e9525
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.tools.web;
 
import javax.servlet.http.HttpServletRequest;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import com.jeeplus.common.config.Global;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.common.utils.FileUtils;
import com.jeeplus.common.web.BaseController;
import com.jeeplus.modules.sys.entity.User;
import com.jeeplus.modules.sys.security.SystemAuthorizingRealm.Principal;
import com.jeeplus.modules.sys.service.SystemService;
import com.jeeplus.modules.sys.utils.UserUtils;
import com.jeeplus.modules.tools.utils.TwoDimensionCode;
 
/**
 * 二维码Controller
 * @author jeeplus
 * @version 2015-11-30
 */
@Controller
@RequestMapping(value = "${adminPath}/tools/TwoDimensionCodeController")
public class TwoDimensionCodeController extends BaseController {
 
    @Autowired
    private SystemService systemService;
    /**
     * 二维码页面
     */
    @RequestMapping(value = {"index", ""})
    public String index() throws Exception{
        return "modules/tools/TwoDimensionCode";
    }
    
    /**
     *    生成二维码
     * @param args
     * @throws Exception
     */
    @RequestMapping(value="createTwoDimensionCode")
    @ResponseBody
    public AjaxJson createTwoDimensionCode(HttpServletRequest request, String encoderContent){
        AjaxJson j = new AjaxJson();
        Principal principal = (Principal) UserUtils.getPrincipal();
        User user = UserUtils.getUser();
        if (principal == null){
            j.setSuccess(false);
            j.setErrorCode("0");
            j.setMsg("没有登录");
        }
        String realPath = Global.getUserfilesBaseDir() + Global.USERFILES_BASE_URL
                            + principal + "/qrcode/";
        FileUtils.createDirectory(realPath);
        String name="test.png"; //encoderImgId此处二维码的图片名
            try {
                String filePath = realPath + name;  //存放路径
                TwoDimensionCode.encoderQRCode(encoderContent, filePath, "png");//执行生成二维码
                user.setQrCode(request.getContextPath()+Global.USERFILES_BASE_URL
                        + principal + "/qrcode/"+name);
                systemService.updateUserInfo(user);
                j.setSuccess(true);
                j.setMsg("二维码生成成功");
                j.put("filePath", request.getContextPath()+Global.USERFILES_BASE_URL
                        + principal + "/qrcode/"+name);
            } catch (Exception e) {
                
            }
        return j;
    }
//    
//    /**
//     *    解析二维码
//     * @param args
//     * @throws Exception
//     */
//    @RequestMapping(value="/readTwoDimensionCode")
//    @ResponseBody
//    public Object readTwoDimensionCode(){
//        Map<String,String> map = new HashMap<String,String>();
//        PageData pd = new PageData();
//        pd = this.getPageData();
//        String errInfo = "success",readContent="";
//        String imgId = pd.getString("imgId");//内容
//        if(null == imgId){
//            errInfo = "error";
//        }else{
//            try {
//                String filePath = PathUtil.getClasspath() + Const.FILEPATHTWODIMENSIONCODE + imgId;  //存放路径
//                readContent = TwoDimensionCode.decoderQRCode(filePath);//执行读取二维码
//            } catch (Exception e) {
//                errInfo = "error";
//            }
//        }
//        map.put("result", errInfo);                        //返回结果
//        map.put("readContent", readContent);            //读取的内容
//        return AppUtil.returnObject(new PageData(), map);
//    }
//    
 
}