Search in sources :

Example 11 with SimplePostRequestExecutor

use of me.chanjar.weixin.common.util.http.SimplePostRequestExecutor in project weixin-java-tools by chanjarster.

the class WxMpServiceImpl method massNewsUpload.

public WxMpMassUploadResult massNewsUpload(WxMpMassNews news) throws WxErrorException {
    String url = "https://api.weixin.qq.com/cgi-bin/media/uploadnews";
    String responseContent = execute(new SimplePostRequestExecutor(), url, news.toJson());
    return WxMpMassUploadResult.fromJson(responseContent);
}
Also used : SimplePostRequestExecutor(me.chanjar.weixin.common.util.http.SimplePostRequestExecutor)

Example 12 with SimplePostRequestExecutor

use of me.chanjar.weixin.common.util.http.SimplePostRequestExecutor in project weixin-java-tools by chanjarster.

the class WxMpServiceImpl method qrCodeCreateLastTicket.

public WxMpQrCodeTicket qrCodeCreateLastTicket(String scene_str) throws WxErrorException {
    String url = "https://api.weixin.qq.com/cgi-bin/qrcode/create";
    JsonObject json = new JsonObject();
    json.addProperty("action_name", "QR_LIMIT_STR_SCENE");
    JsonObject actionInfo = new JsonObject();
    JsonObject scene = new JsonObject();
    scene.addProperty("scene_str", scene_str);
    actionInfo.add("scene", scene);
    json.add("action_info", actionInfo);
    String responseContent = execute(new SimplePostRequestExecutor(), url, json.toString());
    return WxMpQrCodeTicket.fromJson(responseContent);
}
Also used : JsonObject(com.google.gson.JsonObject) SimplePostRequestExecutor(me.chanjar.weixin.common.util.http.SimplePostRequestExecutor)

Example 13 with SimplePostRequestExecutor

use of me.chanjar.weixin.common.util.http.SimplePostRequestExecutor in project weixin-java-tools by chanjarster.

the class WxMpServiceImpl method qrCodeCreateTmpTicket.

public WxMpQrCodeTicket qrCodeCreateTmpTicket(int scene_id, Integer expire_seconds) throws WxErrorException {
    String url = "https://api.weixin.qq.com/cgi-bin/qrcode/create";
    JsonObject json = new JsonObject();
    json.addProperty("action_name", "QR_SCENE");
    if (expire_seconds != null) {
        json.addProperty("expire_seconds", expire_seconds);
    }
    JsonObject actionInfo = new JsonObject();
    JsonObject scene = new JsonObject();
    scene.addProperty("scene_id", scene_id);
    actionInfo.add("scene", scene);
    json.add("action_info", actionInfo);
    String responseContent = execute(new SimplePostRequestExecutor(), url, json.toString());
    return WxMpQrCodeTicket.fromJson(responseContent);
}
Also used : JsonObject(com.google.gson.JsonObject) SimplePostRequestExecutor(me.chanjar.weixin.common.util.http.SimplePostRequestExecutor)

Example 14 with SimplePostRequestExecutor

use of me.chanjar.weixin.common.util.http.SimplePostRequestExecutor in project weixin-java-tools by chanjarster.

the class WxMpServiceImpl method shortUrl.

public String shortUrl(String long_url) throws WxErrorException {
    String url = "https://api.weixin.qq.com/cgi-bin/shorturl";
    JsonObject o = new JsonObject();
    o.addProperty("action", "long2short");
    o.addProperty("long_url", long_url);
    String responseContent = execute(new SimplePostRequestExecutor(), url, o.toString());
    JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
    return tmpJsonElement.getAsJsonObject().get("short_url").getAsString();
}
Also used : JsonElement(com.google.gson.JsonElement) StringReader(java.io.StringReader) JsonObject(com.google.gson.JsonObject) JsonReader(com.google.gson.stream.JsonReader) SimplePostRequestExecutor(me.chanjar.weixin.common.util.http.SimplePostRequestExecutor)

Example 15 with SimplePostRequestExecutor

use of me.chanjar.weixin.common.util.http.SimplePostRequestExecutor in project weixin-java-tools by chanjarster.

the class WxCpServiceImpl method departCreate.

public Integer departCreate(WxCpDepart depart) throws WxErrorException {
    String url = "https://qyapi.weixin.qq.com/cgi-bin/department/create";
    String responseContent = execute(new SimplePostRequestExecutor(), url, depart.toJson());
    JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
    return GsonHelper.getAsInteger(tmpJsonElement.getAsJsonObject().get("id"));
}
Also used : JsonElement(com.google.gson.JsonElement) StringReader(java.io.StringReader) JsonReader(com.google.gson.stream.JsonReader) SimplePostRequestExecutor(me.chanjar.weixin.common.util.http.SimplePostRequestExecutor)

Aggregations

SimplePostRequestExecutor (me.chanjar.weixin.common.util.http.SimplePostRequestExecutor)18 JsonObject (com.google.gson.JsonObject)9 JsonElement (com.google.gson.JsonElement)4 JsonReader (com.google.gson.stream.JsonReader)4 StringReader (java.io.StringReader)4 WxErrorException (me.chanjar.weixin.common.exception.WxErrorException)1