Search in sources :

Example 1 with MemoryBuffer

use of cn.cerc.jbean.other.MemoryBuffer in project summer-mis by cn-cerc.

the class ClientDevice method setSid.

public void setSid(String value) {
    String tmp = value == null || "".equals(value) ? null : value;
    if (tmp != null) {
        // req.getSession().getAttribute(deviceId_key);
        try (MemoryBuffer buff = new MemoryBuffer(BufferType.getDeviceInfo, tmp)) {
            // 设备ID
            deviceId = getValue(buff, deviceId_key, deviceId);
            // 设备样式
            deviceType = getValue(buff, deviceType_key, deviceType);
        }
    } else if (tmp == null) {
        if (this.sid != null && !"".equals(this.sid)) {
            MemoryBuffer.delete(BufferType.getDeviceInfo, this.sid);
        }
    }
    this.sid = tmp;
    request.getSession().setAttribute(RequestData.appSession_Key, this.sid);
    request.setAttribute(RequestData.appSession_Key, this.sid == null ? "" : this.sid);
}
Also used : MemoryBuffer(cn.cerc.jbean.other.MemoryBuffer)

Example 2 with MemoryBuffer

use of cn.cerc.jbean.other.MemoryBuffer in project summer-mis by cn-cerc.

the class ClientDevice method setId.

public void setId(String value) {
    this.deviceId = value;
    request.setAttribute(deviceId_key, deviceId == null ? "" : deviceId);
    request.getSession().setAttribute(deviceId_key, value);
    if (value != null && value.length() == 28)
        setDevice(device_phone);
    if (sid != null && deviceId != null && !"".equals(deviceId)) {
        try (MemoryBuffer buff = new MemoryBuffer(BufferType.getDeviceInfo, sid)) {
            getValue(buff, deviceId_key, deviceId);
        }
    }
}
Also used : MemoryBuffer(cn.cerc.jbean.other.MemoryBuffer)

Example 3 with MemoryBuffer

use of cn.cerc.jbean.other.MemoryBuffer in project summer-mis by cn-cerc.

the class SvrUserLogin method sendVerifyCode.

@Webfunc
public boolean sendVerifyCode() throws DataValidateException {
    try (MemoryBuffer buff = new MemoryBuffer(BufferType.getObject, getUserCode(), SvrUserLogin.class.getName(), "sendVerifyCode")) {
        if (!buff.isNull()) {
            log.info(String.format("verifyCode %s", buff.getString("VerifyCode_")));
            throw new RuntimeException(String.format("请勿在 %d 分钟内重复点击获取认证码!", TimeOut));
        }
        Record headIn = getDataIn().getHead();
        DataValidateException.stopRun("用户帐号不允许为空", "".equals(getUserCode()));
        String deviceId = headIn.getString("deviceId");
        if ("".equals(deviceId)) {
            throw new RuntimeException("认证码不允许为空");
        }
        SqlQuery cdsUser = new SqlQuery(this);
        cdsUser.add("select Mobile_ from %s ", SystemTable.get(SystemTable.getUserInfo));
        cdsUser.add("where Code_='%s' ", getUserCode());
        cdsUser.open();
        DataValidateException.stopRun("系统检测到该帐号还未登记过手机号,无法发送认证码到该手机上,请您联系管理员,让其开一个认证码给您登录系统!", cdsUser.eof());
        String mobile = cdsUser.getString("Mobile_");
        SqlQuery cdsVer = new SqlQuery(this);
        cdsVer.add("select * from %s", SystemTable.get(SystemTable.getDeviceVerify));
        cdsVer.add("where UserCode_='%s' and MachineCode_='%s'", getUserCode(), deviceId);
        cdsVer.open();
        DataValidateException.stopRun("系统出错,请您重新进入系统!", cdsVer.size() != 1);
        String verifyCode = "888888";
        if (ServerConfig.getAppLevel() != ServerConfig.appTest) {
            verifyCode = intToStr(random(900000) + 100000);
        }
        cdsVer.edit();
        cdsVer.setField("VerifyCode_", verifyCode);
        cdsVer.setField("DeadLine_", TDateTime.Now().incDay(1));
        cdsVer.post();
        // 发送认证码到手机上
        Record record = getDataOut().getHead();
        LocalService svr = new LocalService(this, "SvrNotifyMachineVerify");
        if (svr.exec("verifyCode", verifyCode, "mobile", mobile)) {
            record.setField("Msg_", String.format("系统已将认证码发送到您尾号为 %s 的手机上,并且该认证码 %d 分钟内有效,请注意查收!", mobile.substring(mobile.length() - 4, mobile.length()), TimeOut));
            buff.setExpires(TimeOut * 60);
            buff.setField("VerifyCode", verifyCode);
        } else {
            record.setField("Msg_", String.format("验证码发送失败,失败原因:%s", svr.getMessage()));
        }
        record.setField("VerifyCode_", verifyCode);
        return true;
    }
}
Also used : MemoryBuffer(cn.cerc.jbean.other.MemoryBuffer) SqlQuery(cn.cerc.jdb.mysql.SqlQuery) Record(cn.cerc.jdb.core.Record) LocalService(cn.cerc.jbean.client.LocalService) Webfunc(cn.cerc.jbean.core.Webfunc)

Example 4 with MemoryBuffer

use of cn.cerc.jbean.other.MemoryBuffer in project summer-mis by cn-cerc.

the class PhoneVerify method sendVerifyCode.

// 创建并发送效验码,请改使用sendVerify函数
public boolean sendVerifyCode() {
    // 生成6位数字随机码
    verifyCode = createRandomNum(6);
    try (MemoryBuffer buff = new MemoryBuffer(BufferType.getObject, "code" + mobile)) {
        if (!buff.isNull()) {
            log.info("SMS verifyCode: " + buff.getString("code"));
            this.message = String.format("%s %s", "" + (this.expires / 60), R.asString(handle, ERROR_1));
            return false;
        }
        // 组装发送内容
        String text, templateId, templateValues;
        if (nationalCode.equals("+86")) {
            // 发短信调用
            text = "【MIUGROUP】由账号" + this.phone + "发送的验证码是" + verifyCode;
            templateId = "51591";
        } else if (nationalCode.equals("+852")) {
            // 发短信调用
            text = "【MIUGROUP】由賬號" + this.phone + "發送的驗證碼是" + verifyCode;
            templateId = "51592";
        } else {
            // 发短信调用
            text = "【MIUGROUP】The verification code sent by " + this.phone + " is " + verifyCode;
            templateId = "51593";
        }
        templateValues = "#account#=" + this.phone + "&#code#=" + verifyCode;
        // 开始发送讯息
        String no = this.mobile;
        if (!no.startsWith("+"))
            no = nationalCode + no;
        YunpianSMS obj1 = new YunpianSMS(no);
        obj1.sendText(text);
        // }
        if (no.startsWith("+86")) {
            JuheSMS obj2 = new JuheSMS(no.substring(3));
            obj2.sendByTemplateId(templateId, templateValues);
        // if (!obj2.sendByTemplateId(templateId, templateValues)) {
        // this.message = obj2.getMessage();
        // return false;
        // }
        }
        // 存入到缓存
        buff.setExpires(this.expires);
        buff.setField("code", verifyCode);
    }
    return true;
}
Also used : MemoryBuffer(cn.cerc.jbean.other.MemoryBuffer)

Example 5 with MemoryBuffer

use of cn.cerc.jbean.other.MemoryBuffer in project summer-mis by cn-cerc.

the class SvrUserLoginTest method test_sendVerifyCode.

@Test
@Ignore(value = "此处用于测试在5分钟内不允许重复申请验证码,耗时很长")
public void test_sendVerifyCode() throws InterruptedException, DataValidateException {
    String corpNo = "911001";
    String userCode = "91100123";
    String deviceId = "TEST";
    try (StubHandle handle = new StubHandle(corpNo, userCode)) {
        // 清空缓存
        try (MemoryBuffer buff = new MemoryBuffer(BufferType.getObject, handle.getUserCode(), SvrUserLogin.class.getName(), "sendVerifyCode")) {
            buff.clear();
        }
        // 检查验证码是否存在
        SqlQuery ds = new SqlQuery(handle);
        ds.add("select * from %s", SystemTable.get(SystemTable.getDeviceVerify));
        ds.add("where CorpNo_='%s'", corpNo);
        ds.add("and UserCode_='%s'", userCode);
        ds.add("and MachineCode_='%s'", deviceId);
        ds.open();
        String msg = String.format("帐号 %s 验证码 %s 不存在,无法完成测试", userCode, deviceId);
        assertThat(msg, ds.eof(), is(false));
        SvrUserLogin app = new SvrUserLogin();
        app.init(handle);
        app.getDataIn().getHead().setField("deviceId", deviceId);
        assertThat(app.sendVerifyCode(), is(true));
        Thread.sleep(1000 * 30);
        try {
            app.sendVerifyCode();
            assertThat("此处不应该执行到", false, is(true));
        } catch (Exception e) {
            e.printStackTrace();
            assertThat(e.getMessage().indexOf("5 分钟") > 0, is(true));
        }
        Thread.sleep(1000 * 60 * SvrUserLogin.TimeOut);
        assertThat(app.sendVerifyCode(), is(true));
    }
}
Also used : MemoryBuffer(cn.cerc.jbean.other.MemoryBuffer) StubHandle(cn.cerc.jbean.rds.StubHandle) SqlQuery(cn.cerc.jdb.mysql.SqlQuery) DataValidateException(cn.cerc.jbean.core.DataValidateException) ServiceException(cn.cerc.jbean.core.ServiceException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

MemoryBuffer (cn.cerc.jbean.other.MemoryBuffer)10 LocalService (cn.cerc.jbean.client.LocalService)4 Record (cn.cerc.jdb.core.Record)3 SqlQuery (cn.cerc.jdb.mysql.SqlQuery)3 Webfunc (cn.cerc.jbean.core.Webfunc)2 CustomHandle (cn.cerc.jbean.core.CustomHandle)1 DataValidateException (cn.cerc.jbean.core.DataValidateException)1 ServiceException (cn.cerc.jbean.core.ServiceException)1 UserNotFindException (cn.cerc.jbean.other.UserNotFindException)1 StubHandle (cn.cerc.jbean.rds.StubHandle)1 DataSet (cn.cerc.jdb.core.DataSet)1 IHandle (cn.cerc.jdb.core.IHandle)1 Transaction (cn.cerc.jdb.mysql.Transaction)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1