Search in sources :

Example 1 with SimpleGetRequestExecutor

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

the class WxCpServiceImpl method getJsapiTicket.

public String getJsapiTicket(boolean forceRefresh) throws WxErrorException {
    if (forceRefresh) {
        wxCpConfigStorage.expireJsapiTicket();
    }
    if (wxCpConfigStorage.isJsapiTicketExpired()) {
        synchronized (globalJsapiTicketRefreshLock) {
            if (wxCpConfigStorage.isJsapiTicketExpired()) {
                String url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket";
                String responseContent = execute(new SimpleGetRequestExecutor(), url, null);
                JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
                JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
                String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
                int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
                wxCpConfigStorage.updateJsapiTicket(jsapiTicket, expiresInSeconds);
            }
        }
    }
    return wxCpConfigStorage.getJsapiTicket();
}
Also used : JsonElement(com.google.gson.JsonElement) StringReader(java.io.StringReader) JsonReader(com.google.gson.stream.JsonReader) JsonObject(com.google.gson.JsonObject) SimpleGetRequestExecutor(me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor)

Example 2 with SimpleGetRequestExecutor

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

the class WxMpServiceImpl method getJsapiTicket.

public String getJsapiTicket(boolean forceRefresh) throws WxErrorException {
    if (forceRefresh) {
        wxMpConfigStorage.expireJsapiTicket();
    }
    if (wxMpConfigStorage.isJsapiTicketExpired()) {
        synchronized (globalJsapiTicketRefreshLock) {
            if (wxMpConfigStorage.isJsapiTicketExpired()) {
                String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi";
                String responseContent = execute(new SimpleGetRequestExecutor(), url, null);
                JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
                JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
                String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
                int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
                wxMpConfigStorage.updateJsapiTicket(jsapiTicket, expiresInSeconds);
            }
        }
    }
    return wxMpConfigStorage.getJsapiTicket();
}
Also used : JsonElement(com.google.gson.JsonElement) StringReader(java.io.StringReader) JsonReader(com.google.gson.stream.JsonReader) JsonObject(com.google.gson.JsonObject) SimpleGetRequestExecutor(me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor)

Example 3 with SimpleGetRequestExecutor

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

the class WxMpServiceImpl method groupGet.

public List<WxMpGroup> groupGet() throws WxErrorException {
    String url = "https://api.weixin.qq.com/cgi-bin/groups/get";
    String responseContent = execute(new SimpleGetRequestExecutor(), url, null);
    /*
     * 操蛋的微信API,创建时返回的是 { group : { id : ..., name : ...} }
     * 查询时返回的是 { groups : [ { id : ..., name : ..., count : ... }, ... ] }
     */
    JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
    return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("groups"), new TypeToken<List<WxMpGroup>>() {
    }.getType());
}
Also used : WxMpGroup(me.chanjar.weixin.mp.bean.WxMpGroup) JsonElement(com.google.gson.JsonElement) TypeToken(com.google.gson.reflect.TypeToken) StringReader(java.io.StringReader) JsonReader(com.google.gson.stream.JsonReader) SimpleGetRequestExecutor(me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor)

Example 4 with SimpleGetRequestExecutor

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

the class WxMpServiceImpl method menuDelete.

public void menuDelete() throws WxErrorException {
    String url = "https://api.weixin.qq.com/cgi-bin/menu/delete";
    execute(new SimpleGetRequestExecutor(), url, null);
}
Also used : SimpleGetRequestExecutor(me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor)

Example 5 with SimpleGetRequestExecutor

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

the class WxMpServiceImpl method menuDelete.

public void menuDelete(String menuid) throws WxErrorException {
    String url = "https://api.weixin.qq.com/cgi-bin/menu/delconditional";
    execute(new SimpleGetRequestExecutor(), url, "menuid=" + menuid);
}
Also used : SimpleGetRequestExecutor(me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor)

Aggregations

SimpleGetRequestExecutor (me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor)7 JsonElement (com.google.gson.JsonElement)3 JsonReader (com.google.gson.stream.JsonReader)3 StringReader (java.io.StringReader)3 JsonObject (com.google.gson.JsonObject)2 TypeToken (com.google.gson.reflect.TypeToken)1 WxMpGroup (me.chanjar.weixin.mp.bean.WxMpGroup)1