Search in sources :

Example 16 with JsonObject

use of com.google.gson.JsonObject in project weixin-java-tools by chanjarster.

the class WxMpServiceImpl method userUpdateRemark.

public void userUpdateRemark(String openid, String remark) throws WxErrorException {
    String url = "https://api.weixin.qq.com/cgi-bin/user/info/updateremark";
    JsonObject json = new JsonObject();
    json.addProperty("openid", openid);
    json.addProperty("remark", remark);
    execute(new SimplePostRequestExecutor(), url, json.toString());
}
Also used : JsonObject(com.google.gson.JsonObject) SimplePostRequestExecutor(me.chanjar.weixin.common.util.http.SimplePostRequestExecutor)

Example 17 with JsonObject

use of com.google.gson.JsonObject in project weixin-java-tools by chanjarster.

the class WxMpMaterialArticleUpdateGsonAdapter method serialize.

public JsonElement serialize(WxMpMaterialArticleUpdate wxMpMaterialArticleUpdate, Type typeOfSrc, JsonSerializationContext context) {
    JsonObject articleUpdateJson = new JsonObject();
    articleUpdateJson.addProperty("media_id", wxMpMaterialArticleUpdate.getMediaId());
    articleUpdateJson.addProperty("index", wxMpMaterialArticleUpdate.getIndex());
    articleUpdateJson.add("articles", WxMpGsonBuilder.create().toJsonTree(wxMpMaterialArticleUpdate.getArticles(), WxMpMaterialNews.WxMpMaterialNewsArticle.class));
    return articleUpdateJson;
}
Also used : JsonObject(com.google.gson.JsonObject)

Example 18 with JsonObject

use of com.google.gson.JsonObject in project weixin-java-tools by chanjarster.

the class WxMpServiceImpl method userUpdateGroup.

public void userUpdateGroup(String openid, long to_groupid) throws WxErrorException {
    String url = "https://api.weixin.qq.com/cgi-bin/groups/members/update";
    JsonObject json = new JsonObject();
    json.addProperty("openid", openid);
    json.addProperty("to_groupid", to_groupid);
    execute(new SimplePostRequestExecutor(), url, json.toString());
}
Also used : JsonObject(com.google.gson.JsonObject) SimplePostRequestExecutor(me.chanjar.weixin.common.util.http.SimplePostRequestExecutor)

Example 19 with JsonObject

use of com.google.gson.JsonObject in project weixin-java-tools by chanjarster.

the class WxMpServiceImpl method getUserCumulate.

@Override
public List<WxMpUserCumulate> getUserCumulate(Date beginDate, Date endDate) throws WxErrorException {
    String url = "https://api.weixin.qq.com/datacube/getusercumulate";
    JsonObject param = new JsonObject();
    param.addProperty("begin_date", SIMPLE_DATE_FORMAT.format(beginDate));
    param.addProperty("end_date", SIMPLE_DATE_FORMAT.format(endDate));
    String responseContent = post(url, param.toString());
    JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
    return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("list"), new TypeToken<List<WxMpUserCumulate>>() {
    }.getType());
}
Also used : WxMpUserCumulate(me.chanjar.weixin.mp.bean.result.WxMpUserCumulate) JsonElement(com.google.gson.JsonElement) TypeToken(com.google.gson.reflect.TypeToken) StringReader(java.io.StringReader) JsonObject(com.google.gson.JsonObject) JsonReader(com.google.gson.stream.JsonReader)

Example 20 with JsonObject

use of com.google.gson.JsonObject 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)

Aggregations

JsonObject (com.google.gson.JsonObject)1124 JsonParser (com.google.gson.JsonParser)263 JsonElement (com.google.gson.JsonElement)228 JsonArray (com.google.gson.JsonArray)226 JsonPrimitive (com.google.gson.JsonPrimitive)78 HashMap (java.util.HashMap)78 Test (org.junit.Test)77 Gson (com.google.gson.Gson)70 Map (java.util.Map)66 ArrayList (java.util.ArrayList)63 Test (org.testng.annotations.Test)61 IOException (java.io.IOException)53 InputStreamReader (java.io.InputStreamReader)27 JsonParseException (com.google.gson.JsonParseException)24 File (java.io.File)21 HttpResponse (org.apache.http.HttpResponse)21 InvalidArgumentException (com.pratilipi.common.exception.InvalidArgumentException)19 JsonReader (com.google.gson.stream.JsonReader)17 InputStream (java.io.InputStream)17 URL (java.net.URL)15