Java Code Examples for org.nutz.lang.util.NutMap#put()

The following examples show how to use org.nutz.lang.util.NutMap#put() . 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: 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 2
Source File: WxApi2Impl.java    From nutzwx with Apache License 2.0 5 votes vote down vote up
@Override
public WxResp createQRTicket(long expire, Type type, String str) {
    NutMap json = NutMap.NEW();
    json.put("expire_seconds", expire);
    json.put("action_name", type.getValue());
    NutMap action = NutMap.NEW();
    NutMap scene = NutMap.NEW();
    scene.put("scene_str", str);
    action.put("scene", scene);
    json.put("action_info", action);
    return postJson("/qrcode/create", json);
}
 
Example 3
Source File: WxApi2Impl.java    From nutzwx with Apache License 2.0 5 votes vote down vote up
@Override
public WxResp bindLocation(int device_id, int poi_id) {
    NutMap params = new NutMap();
    params.put("device_identifier", new NutMap().setv("device_id", device_id));
    params.put("poi_id", poi_id);
    return postJson(wxBase + "/shakearound/device/bindlocation", params);
}
 
Example 4
Source File: WxApi2Impl.java    From nutzwx with Apache License 2.0 5 votes vote down vote up
@Override
public WxResp update(String uuid, int major, int minor, String comment) {
    NutMap params = new NutMap();
    params.put("device_identifier", new NutMap().setv("uuid", uuid).setv("major", major).setv("minor", minor));
    params.put("comment", comment);
    return postJson(wxBase + "/shakearound/device/update", params);
}
 
Example 5
Source File: WxApi2Impl.java    From nutzwx with Apache License 2.0 5 votes vote down vote up
@Override
public WxResp update(int device_id, String comment) {
    NutMap params = new NutMap();
    params.put("device_identifier", new NutMap().setv("device_id", device_id));
    params.put("comment", comment);
    return postJson(wxBase + "/shakearound/device/update", params);
}
 
Example 6
Source File: WxApi2Impl.java    From nutzwx with Apache License 2.0 5 votes vote down vote up
@Override
public WxResp mass_sendall(boolean is_to_all, String group_id, WxOutMsg msg) {
    NutMap filter = new NutMap();
    filter.put("is_to_all", is_to_all);
    if (!is_to_all) {
        filter.put("group_id", group_id);
    }
    return this._mass_send(filter, null, null, msg);
}
 
Example 7
Source File: WxApi2Impl.java    From nutzwx with Apache License 2.0 5 votes vote down vote up
@Override
public WxResp qrcode_create(Object scene_id, int expire_seconds) {
    NutMap params = new NutMap();
    NutMap scene;
    // 临时二维码
    if (expire_seconds > 0) {
        params.put("expire_seconds", expire_seconds);

        // 临时整型二维码
        if (scene_id instanceof Number) {
            params.put("action_name", "QR_SCENE");
            scene = Lang.map("scene_id", Castors.me().castTo(scene_id, Integer.class));
            // 临时字符串二维码
        } else {
            params.put("action_name", "QR_STR_SCENE");
            scene = Lang.map("scene_str", scene_id.toString());
        }
    }
    // 永久二维码
    else if (scene_id instanceof Number) {
        params.put("action_name", "QR_LIMIT_SCENE");
        scene = Lang.map("scene_id", Castors.me().castTo(scene_id, Integer.class));
    }
    // 永久字符串二维码
    else {
        params.put("action_name", "QR_LIMIT_STR_SCENE");
        scene = Lang.map("scene_str", scene_id.toString());
    }
    params.put("action_info", Lang.map("scene", scene));
    return postJson("/qrcode/create", params);
}
 
Example 8
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 9
Source File: WxApiImpl.java    From nutzwx with Apache License 2.0 5 votes vote down vote up
public String sendTemplateMsg(String touser,
                              String template_id,
                              String topcolor,
                              Map<String, WxTemplateData> data) {
    if (Strings.isBlank(topcolor))
        topcolor = WxTemplateData.DFT_COLOR;
    NutMap map = new NutMap();
    map.put("touser", touser);
    map.put("template_id", template_id);
    map.put("topcolor", topcolor);
    map.put("data", data);
    return call("/message/template/send", METHOD.POST, Json.toJson(map)).get("msgid")
                                                                        .toString();
}
 
Example 10
Source File: WxApi2Impl.java    From nutzwx with Apache License 2.0 5 votes vote down vote up
@Override
public WxResp createQRTicket(long expire, Type type, int id) {
    if (type != Type.EVER || type != Type.TEMP) {// 非整形场景自动适配一下
        return createQRTicket(expire, type, id + "");
    }
    NutMap json = NutMap.NEW();
    json.put("expire_seconds", expire);
    json.put("action_name", type.getValue());
    NutMap action = NutMap.NEW();
    NutMap scene = NutMap.NEW();
    scene.put("scene_id", id);
    action.put("scene", scene);
    json.put("action_info", action);
    return postJson("/qrcode/create", json);
}
 
Example 11
Source File: WxLoginImpl.java    From nutzwx with Apache License 2.0 5 votes vote down vote up
@Override
public WxResp userinfo(String openid, String access_token) {
    // https://api.weixin.qq.com/sns/userinfo?access_token=ACCESS_TOKEN&openid=OPENID
    Request req = Request.create("https://api.weixin.qq.com/sns/userinfo", METHOD.GET);
    NutMap params = new NutMap();
    params.put("access_token", access_token);
    params.put("openid", openid);
    req.setParams(params);
    Response resp = Sender.create(req).send();
    if (!resp.isOK()) {
        return null;
    }
    return Json.fromJson(WxResp.class, resp.getReader("UTF-8"));
}
 
Example 12
Source File: WxLoginImpl.java    From nutzwx with Apache License 2.0 5 votes vote down vote up
@Override
public WxResp access_token(String code) {
    Request req = Request.create("https://api.weixin.qq.com/sns/oauth2/access_token", METHOD.GET);
    NutMap params = new NutMap();
    params.put("appid", appid);
    params.put("secret", appsecret);
    params.put("code", code);
    params.put("grant_type", "authorization_code");
    req.setParams(params);
    Response resp = Sender.create(req).send();
    if (!resp.isOK()) {
        return null;
    }
    return Json.fromJson(WxResp.class, resp.getReader("UTF-8"));
}
 
Example 13
Source File: WxLoginImpl.java    From nutzwx with Apache License 2.0 5 votes vote down vote up
@Override
public String authorize(String redirect_uri, String scope, String state) {
    Request req = Request.create("https://open.weixin.qq.com/connect/oauth2/authorize", METHOD.GET);
    NutMap params = new NutMap();
    params.put("appid", appid);
    if (redirect_uri.startsWith("http"))
        params.put("redirect_uri", redirect_uri);
    else
        params.put("redirect_uri", host + redirect_uri);
    params.put("response_type", "code");
    params.put("scope", Strings.sBlank(scope, "snsapi_userinfo"));
    req.setParams(params);
    return req.getUrl().toString() + "#wechat_redirect";
}
 
Example 14
Source File: WxLoginImpl.java    From nutzwx with Apache License 2.0 5 votes vote down vote up
@Override
public String qrconnect(String redirect_uri, String scope, String state) {
    Request req = Request.create("https://open.weixin.qq.com/connect/qrconnect", METHOD.GET);
    NutMap params = new NutMap();
    params.put("appid", appid);
    if (redirect_uri.startsWith("http"))
        params.put("redirect_uri", redirect_uri);
    else
        params.put("redirect_uri", host + redirect_uri);
    params.put("response_type", "code");
    params.put("scope", Strings.sBlank(scope, "snsapi_login"));
    req.setParams(params);
    return req.getUrl().toString() + "#wechat_redirect";
}
 
Example 15
Source File: BeanConfigures.java    From nutzwx with Apache License 2.0 5 votes vote down vote up
public static Map<String, Object> toMap(Properties properties) {
	NutMap map = new NutMap();
	for (Entry<Object, Object> en : properties.entrySet()) {
		map.put(en.getKey().toString(), en.getValue());
	}
	if (map.isEmpty())
		return null;
	return map;
}
 
Example 16
Source File: WechatAPIImpl.java    From mpsdk4j with Apache License 2.0 5 votes vote down vote up
@Override
public QRTicket createQR(Object sceneId, int expireSeconds) {
    String url = mergeCgiBinUrl(createQRCodeURL + getAccessToken());
    NutMap data = new NutMap();
    NutMap scene;
    // 临时二维码
    if (expireSeconds > 0) {
        data.put("action_name", "QR_SCENE");
        data.put("expire_seconds", expireSeconds);

        scene = Lang.map("scene_id", Castors.me().castTo(sceneId, Integer.class));
    }
    // 永久二维码
    else if (sceneId instanceof Number) {
        data.put("action_name", "QR_LIMIT_SCENE");
        scene = Lang.map("scene_id", Castors.me().castTo(sceneId, Integer.class));
    }
    // 永久字符串二维码
    else {
        data.put("action_name", "QR_LIMIT_STR_SCENE");
        scene = Lang.map("scene_str", sceneId.toString());
    }
    data.put("action_info", Lang.map("scene", scene));
    APIResult ar = wechatServerResponse(url,
            HTTP_POST,
            Json.toJson(data, JsonFormat.compact()),
            "创建公众号[%s]的[%s]场景二维码失败.");
    return Json.fromJson(QRTicket.class, Json.toJson(ar.getContent()));
}
 
Example 17
Source File: DemoFescarWebLauncher.java    From seata-samples with Apache License 2.0 5 votes vote down vote up
@Ok("json:full")
@At("/api/info")
public NutMap info() {
    NutMap re = new NutMap();
    NutMap data = new NutMap();
    data.put("account", dao.fetch(Account.class, Cnd.where("userId", "=", "U100001")));
    data.put("storage", dao.fetch(Storage.class, Cnd.where("commodityCode", "=", "C00321")));
    return re.setv("data", data).setv("ok", true);
}
 
Example 18
Source File: WxApi2Impl.java    From nutzwx with Apache License 2.0 4 votes vote down vote up
@Override
public WxResp search(String uuid, int major, int minor) {
    NutMap params = new NutMap();
    params.put("device_identifier", new NutMap().setv("uuid", uuid).setv("major", major).setv("minor", minor));
    return postJson(wxBase + "/shakearound/device/search", params);
}
 
Example 19
Source File: WxApi2Impl.java    From nutzwx with Apache License 2.0 4 votes vote down vote up
@Override
public WxResp search(int device_id) {
    NutMap params = new NutMap();
    params.put("device_identifier", new NutMap().setv("device_id", device_id));
    return postJson(wxBase + "/shakearound/device/search", params);
}
 
Example 20
Source File: LoachClient.java    From nutzcloud with Apache License 2.0 4 votes vote down vote up
/**
 * 主逻辑
 */
public long exec() throws Exception {
    // 启动延时
    if (startUpDelay > 0) {
        log.debug("start up delay " + startUpDelay + "ms");
        int delay = startUpDelay;
        startUpDelay = 0;
        return delay;
    } else if (startUpDelay == -1) {
        if (!nbApp.isStarted())
            return 100;
    }
    // 心跳
    if (regOk) {
        // 尝试心跳,成功就是返回
        if (_ping()) {
            if (pingRetryCount > 0 && isDebug())
                log.debug("loach client ping OK");
            pingRetryCount = 0;
            return getPingInterval();
        } else {
            if (pingRetryCount < 5) {
                pingRetryCount++;
                log.info("loach client ping FAIL count=" + pingRetryCount);
                return getInterval();
            } else {
                regOk = false;
                log.info("loach client ping FAIL too many time, redo reg!");
            }
        }
    }
    NutMap regInfo = new NutMap();
    regInfo.put("id", id);
    regInfo.put("name", getServiceName());
    regInfo.put("vip", conf.get("server.vip", "127.0.0.1"));
    regInfo.put("port", appContext.getServerPort(null));
    regInfo.put("eth.mac", Networks.mac(NetworkType.LAN));
    regInfo.put("eth.ipv4", Networks.ipv4(NetworkType.LAN));
    regInfo.putAll(EXT_REG_DATA);
    String regData = Json.toJson(regInfo, JsonFormat.compact());
    _reg(regData);
    return getInterval();
}