org.nutz.lang.random.R Java Examples

The following examples show how to use org.nutz.lang.random.R. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AreaController.java    From NutzSite with Apache License 2.0 6 votes vote down vote up
public static void getAreaList(List<Districts> list,String pid){
    list.forEach(districts -> {
        Area area =new Area();
        area.setId(R.UU32().toLowerCase());
        area.setParentId(pid);
        area.setAdcode(districts.getAdcode());
        area.setName(districts.getName());
        area.setLevel(districts.getLevel());
        if(districts.getCitycode()!=null && districts.getCitycode().size()>0){
            area.setCitycode(districts.getCitycode().get(0));
        }

        areaList.add(area);
        if(districts.getDistricts()!=null && districts.getDistricts().size()>0){
            getAreaList(districts.getDistricts(),area.getId());
        }
    });
}
 
Example #2
Source File: CaptchaController.java    From NutzSite with Apache License 2.0 6 votes vote down vote up
/**
 * 获取验证码
 *
 * @param session session
 * @param w       宽
 * @param h       高
 * @return
 */
@At
@Ok("raw:png")
@ApiOperation(value = "获取验证码", notes = "公共验证码", httpMethod = "GET")
public BufferedImage next(HttpSession session,
                          @Param("w") int w,
                          @Param("h") int h) {
    /**
     * 长或宽为0?重置为默认长宽.
     */
    if (w * h < 1) {
        w = 145;
        h = 35;
    }
    String text = R.captchaChar(4);
    session.setAttribute(Toolkit.captcha_attr, text);
    return Images.createCaptcha(text, w, h, null, "FFF", null);
}
 
Example #3
Source File: AbstractWxApi2.java    From nutzwx with Apache License 2.0 6 votes vote down vote up
@Override
public NutMap genJsSDKConfig(String url, String... jsApiList) {
    String jt = this.getJsapiTicket();
    long timestamp = System.currentTimeMillis();
    String nonceStr = R.UU64();

    String str = String.format("jsapi_ticket=%s&noncestr=%s&timestamp=%d&url=%s", jt, nonceStr, timestamp, url);
    String signature = Lang.sha1(str);

    NutMap map = new NutMap();
    map.put("appId", appid);
    map.put("timestamp", timestamp);
    map.put("nonceStr", nonceStr);
    map.put("signature", signature);
    map.put("jsApiList", jsApiList);
    return map;
}
 
Example #4
Source File: GenUtils.java    From NutzSite with Apache License 2.0 5 votes vote down vote up
/**
 * 获取模板信息
 *
 * @return 模板列表
 */
public static VelocityContext getVelocityContext(TableInfo table) {
    // java对象数据传递到模板文件vm
    VelocityContext velocityContext = new VelocityContext();
    String packageName = GenConfig.getPackageName();
    String packageNameOpen = GenConfig.getPackageNameOpen();
    velocityContext.put("tableName", table.getTableName());
    velocityContext.put("tableComment", replaceKeyword(table.getTableComment()));
    velocityContext.put("primaryKey", table.getPrimaryKey());
    velocityContext.put("className", table.getClassName());
    velocityContext.put("classname", table.getClassname());
    velocityContext.put("moduleName", getModuleName(packageName));
    velocityContext.put("moduleNameOpen", getModuleName(packageNameOpen));
    velocityContext.put("columns", table.getColumns());
    velocityContext.put("package", packageName);
    velocityContext.put("packageOpen", packageNameOpen);
    velocityContext.put("author", GenConfig.getAuthor());
    velocityContext.put("datetime", DateUtils.getDate());
    velocityContext.put("uuid1", R.UU32().toLowerCase());
    velocityContext.put("uuid2", R.UU32().toLowerCase());
    velocityContext.put("uuid3", R.UU32().toLowerCase());
    velocityContext.put("uuid4", R.UU32().toLowerCase());
    velocityContext.put("uuid5", R.UU32().toLowerCase());
    //args[0].
    velocityContext.put("array2str", "${array2str(args[0])}");
    velocityContext.put("args", "${args[0].");
    return velocityContext;
}
 
Example #5
Source File: LoachClient.java    From nutzcloud with Apache License 2.0 5 votes vote down vote up
public void init() {
    startUpDelay = conf.getInt("loach.client.startUpDelay", -1);
    es = Executors.newCachedThreadPool();
    id = R.UU32();
    url = conf.get("loach.client.url", "http://127.0.0.1:8610/loach/v1");
    for (String name : ioc.getNamesByType(UpdateListener.class)) {
        addListener(ioc.get(UpdateListener.class, name));
    }

    setDebug(conf.getBoolean("loach.client.debug", false));
    if (conf.getBoolean("loach.client.enable", true)) {
        if (Strings.isBlank(conf.get("nutz.application.name"))) {
            throw new RuntimeException("need nutz.application.name");
        }
    }
    if (conf.getBoolean("loach.client.enable", true)) {
        es.submit(this);
    }
    if (conf.getBoolean("loach.updater.enable", true)) {
        updateServiceList();
        updater = new NutRunner("loach.updater." + url) {
            public long exec() throws Exception {
                LoachClient.this.updateServiceList();
                return conf.getInt("loach.client.updater.interval", 3000);
            }
        };
        updater.setDebug(isDebug());
        es.submit(updater);
    }
}
 
Example #6
Source File: WechatKernelTest.java    From mpsdk4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testLongParamsCheck() {
    log.info("====== WechatKernel#check-toolong ======");
    StringGenerator sg = R.sg(129, 200);
    data.put("signature", new String[]{sg.next()});
    data.put("timestamp", new String[]{sg.next()});
    data.put("nonce", new String[]{sg.next()});
    WechatKernel wk = new WechatKernel(mpAct, new WechatDefHandler(), data);
    String echo = wk.check();
    assertNotNull(echo);
    assertTrue(echo.equals("error"));
}
 
Example #7
Source File: WechatKernelTest.java    From mpsdk4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testLong1ParamsCheck() {
    log.info("====== WechatKernel#check-toolong1 ======");
    StringGenerator sg = R.sg(129, 200);
    data.put("signature", new String[]{sg.next()});
    WechatKernel wk = new WechatKernel(mpAct, new WechatDefHandler(), data);
    String echo = wk.check();
    assertNotNull(echo);
    assertTrue(echo.equals("error"));
}
 
Example #8
Source File: WechatKernelTest.java    From mpsdk4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testLong2ParamsCheck() {
    log.info("====== WechatKernel#check-toolong2 ======");
    StringGenerator sg = R.sg(129, 200);
    data.put("timestamp", new String[]{sg.next()});
    WechatKernel wk = new WechatKernel(mpAct, new WechatDefHandler(), data);
    String echo = wk.check();
    assertNotNull(echo);
    assertTrue(echo.equals("error"));
}
 
Example #9
Source File: WechatKernelTest.java    From mpsdk4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testLong3ParamsCheck() {
    log.info("====== WechatKernel#check-toolong3 ======");
    StringGenerator sg = R.sg(129, 200);
    data.put("nonce", new String[]{sg.next()});
    WechatKernel wk = new WechatKernel(mpAct, new WechatDefHandler(), data);
    String echo = wk.check();
    assertNotNull(echo);
    assertTrue(echo.equals("error"));
}
 
Example #10
Source File: WxApi2Impl.java    From nutzwx with Apache License 2.0 5 votes vote down vote up
/**
 * 微信公众号JS支付
 *
 * @param key
 *            商户KEY
 * @param wxPayUnifiedOrder
 *            交易订单内容
 * @return
 */
@Override
public NutMap pay_jsapi(String key, WxPayUnifiedOrder wxPayUnifiedOrder) {
    NutMap map = this.pay_unifiedorder(key, wxPayUnifiedOrder);
    NutMap params = NutMap.NEW();
    params.put("appId", wxPayUnifiedOrder.getAppid());
    params.put("timeStamp", String.valueOf((int) (System.currentTimeMillis() / 1000)));
    params.put("nonceStr", R.UU32());
    params.put("package", "prepay_id=" + map.getString("prepay_id"));
    params.put("signType", "MD5");
    String sign = WxPaySign.createSign(key, params);
    params.put("paySign", sign);
    return params;
}
 
Example #11
Source File: BaseBean.java    From NutzSite with Apache License 2.0 4 votes vote down vote up
public String uuid() {
    return R.UU32().toLowerCase();
}
 
Example #12
Source File: BaseModel.java    From NutzSite with Apache License 2.0 4 votes vote down vote up
public String uuid() {
    return R.UU32().toLowerCase();
}
 
Example #13
Source File: Wxs.java    From nutzwx with Apache License 2.0 3 votes vote down vote up
/**
 * 为参数集合填充随机数,以及生成签名
 *
 * @param map
 *            参数集合
 * @param key
 *            商户秘钥
 *
 * @see #genPaySignMD5(Map, String)
 */
public static void fillPayMap(Map<String, Object> map, String key) {
    // 首先确保有随机数
    map.put("nonce_str", "" + R.random(10000000, 100000000));

    // 填充签名
    String sign = genPaySignMD5(map, key);
    map.put("sign", sign);
}