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
var layer;// 定义全局变量
(function () {
    layui.use(['layer', 'form'], function () {
        layer = layui.layer;
 
        if(TEST_TAG){
            renderRegisterInfo(950);
            renderSn("CDECyDOrNl59kFU+vJIy6qRsgAUTt+xlWyA00t0IZlY=");
        }else{
            queryRegister();
 
            querySn();
        }
    });
}).call(this);
 
 
//注册授权
function register() {
    var obj = {};
    obj.add = $("#zcm").val();
    // console.log("注册码:" + obj.add);
    $.post("./cgi-bin/register/add_register", JSON.stringify(obj), function (data, status) {
        window.parent.parent.notify(data.msg);
        if ("success" == data.code) {
            queryRegister();
        }
    }, "json");
}
 
 
//查询授权信息
function queryRegister() {
    $.get("./cgi-bin/register/query_register", function (data, status) {
        if ("success" == data.code) {
            renderRegisterInfo(data.msg);
        } else {
            window.parent.parent.notify("获取授权信息出错,请重新操作!!");
        }
    }, "json");
}
 
//获取机器码
function querySn() {
    $.get("./cgi-bin/register/query_sn", function (data, status) {
        if ("success" == status) {
            renderSn(data.msg);
        } else {
            window.parent.parent.notify("获取机器码出错,请重新操作!!");
        }
    }, "json");
}
 
//渲染授权信息
function renderRegisterInfo(data) {
    var text = "";
    if(data == 36500){
        text = "已授权成功,该授权为永久授权";
    }else{
        text = "已授权成功,还可以使用"+ data +"天!";
    }
 
    $("#licenseInfo").text(text);
}
 
//渲染机械码
function renderSn(data) {
    $("#mechanicsCode").val(data);
    renderSnQrcode(data);
}
 
//将机械码渲染成二维码
function renderSnQrcode(data) {
    data = toUtf8(data);
    $('#qrcode').html('');
    // $('#qrcode').qrcode(data);
    $('#qrcode').qrcode({
        render: 'table',
        width: 170,
        height: 170,
        text: data
    })
}
 
function toUtf8(str) {
    var out, i, len, c;
    out = "";
    len = str.length;
    for (i = 0; i < len; i++) {
        c = str.charCodeAt(i);
        if ((c >= 0x0001) && (c <= 0x007F)) {
            out += str.charAt(i);
        } else if (c > 0x07FF) {
            out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
            out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
            out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
        } else {
            out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
            out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
        }
    }
    return out;
}