Search in sources :

Example 31 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project TrebleShot by genonbeta.

the class RemoteServer method connect.

public String connect(String postKey, String postValue) throws IOException {
    HttpRequest request = HttpRequest.get(mConnection);
    StringBuilder output = new StringBuilder();
    request.readTimeout(5000);
    if (postKey != null && postValue != null)
        request.send(postKey + "=" + URLEncoder.encode(postValue, "UTF-8"));
    request.receive(output);
    return output.toString();
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest)

Example 32 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project dubidubi by lzzzz4.

the class LocationServiceImpl method getWeather.

/**
 * @Description: 得到天气预报拼接后的字符串
 * @data: @param wxLocationDO
 * @data: @return
 * @date: 2018年1月10日下午3:24:24
 */
@Override
public String getWeather(WxLocationDO wxLocationDO) {
    HttpRequest request = HttpRequest.get("http://restapi.amap.com/v3/weather/weatherInfo?key=" + key + "&city=" + wxLocationDO.getAdcode());
    String body = request.body();
    JSONObject jsonObject = JSON.parseObject(body);
    JSONArray live = jsonObject.getJSONArray("lives");
    // 雨天发送模版消息
    // if (live.getJSONObject(0).getString("weather").indexOf("雨") != -1) {
    wxTempService.sendTempMessage(live);
    // }
    StringBuilder stringBuilder = new StringBuilder();
    // 拼接天气预报字符串
    stringBuilder.append("天气:").append(live.getJSONObject(0).getString("weather")).append("\n").append("温度:").append(live.getJSONObject(0).getString("temperature")).append("℃").append("\n").append("风速:").append(live.getJSONObject(0).getString("windpower")).append("\n").append("发布时间:").append(live.getJSONObject(0).getString("reporttime")).append("\n").append("城市:").append(wxLocationDO.getAddress()).append("\n");
    return stringBuilder.toString();
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray)

Example 33 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project dubidubi by lzzzz4.

the class WxMenuUtil method main.

/**
 * @Description: 自定义菜单按钮
 * @data :@param args
 * @date :2018年3月6日下午1:44:50
 */
public static void main(String[] args) {
    // 一级生活按钮
    WxButton life = new WxButton();
    life.setName("生活");
    WxButton[] lifes = new WxButton[2];
    // 二级天气按钮
    WxButton wxButton = new WxButton();
    // 种类,点击事件
    wxButton.setType("click");
    // 按钮名
    wxButton.setName("获取当前天气");
    // key 实际接受到的key
    wxButton.setKey("weather");
    // 二级绑定邮箱
    WxButton mails = new WxButton();
    mails.setType("view");
    mails.setName("绑定邮箱");
    System.out.println("绑定邮箱的url为" + WxProperties.Mail_Url);
    mails.setUrl(WxProperties.Mail_Url);
    lifes[0] = wxButton;
    lifes[1] = mails;
    life.setSub_button(lifes);
    // 资源一级按钮
    WxButton resource = new WxButton();
    resource.setName("资源");
    // 设置资源二级按钮 百度图片源
    WxButton[] resources = new WxButton[1];
    WxButton baiduPic = new WxButton();
    baiduPic.setName("搜索图片");
    baiduPic.setType("view");
    baiduPic.setUrl(WxProperties.Pic_Url);
    resources[0] = baiduPic;
    resource.setSub_button(resources);
    // 新闻一级按钮
    WxButton news = new WxButton();
    news.setName("新闻");
    WxButton[] news_sub = new WxButton[2];
    // 澎湃子按钮
    WxButton pengpai = new WxButton();
    pengpai.setName("澎湃新闻源");
    pengpai.setType("click");
    pengpai.setKey("100");
    news_sub[0] = pengpai;
    // 腾讯子按钮
    WxButton tencent_news = new WxButton();
    tencent_news.setName("腾讯新闻源");
    tencent_news.setType("click");
    tencent_news.setKey("101");
    news_sub[1] = tencent_news;
    news.setSub_button(news_sub);
    // 将一级按钮放入数组中,将数组放入menu对象中,生成json对象
    WxButton[] button = new WxButton[3];
    // 将天气加入数组
    button[0] = life;
    // 将新闻加入数组
    button[1] = news;
    // 将资源加入数组
    button[2] = resource;
    WxMenu wxMenu = new WxMenu();
    wxMenu.setButton(button);
    WxBaseService wxBaseService = new WxBaseServiceImpl();
    String access_Token = wxBaseService.getAccessToken();
    System.out.println(access_Token);
    HttpRequest request = HttpRequest.post("https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + access_Token);
    request.trustAllCerts();
    request.trustAllHosts();
    String json = JSON.toJSONString(wxMenu);
    System.out.println(json);
    request.send(json);
    String body = request.body();
    System.out.println(body);
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) WxBaseService(cn.dubidubi.service.WxBaseService) WxMenu(cn.dubidubi.model.json.WxMenu) WxBaseServiceImpl(cn.dubidubi.service.impl.WxBaseServiceImpl) WxButton(cn.dubidubi.model.json.WxButton)

Example 34 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project dubidubi by lzzzz4.

the class WxTempServiceImpl method sendTempMessage.

@Override
public void sendTempMessage(JSONArray jsonArray) {
    WxTemp wxTemp = new WxTemp();
    // 三个单独的属性值
    wxTemp.setTopcolor("#FF0000");
    wxTemp.setTouser("oWH4hwjClpJPB6IwAsH_RapXhLbI");
    wxTemp.setUrl("http://www.baidu.com");
    wxTemp.setTemplate_id("Sw2ublSJFBfIWvUQaZRKThGoX8FYYOVD_e4XGRQ86iA");
    // data对象中的值
    WxWeatherTempData wxWeatherTempData = new WxWeatherTempData();
    // 设置user
    WxTempOne one = new WxTempOne();
    one.setValue("lzzzz");
    one.setColor("#173177");
    // 设置weather
    WxTempOne weather = new WxTempOne();
    weather.setValue(jsonArray.getJSONObject(0).getString("weather"));
    weather.setColor("#173177");
    // 设置温度
    WxTempOne temp = new WxTempOne();
    temp.setValue(jsonArray.getJSONObject(0).getString("temperature"));
    temp.setColor("#173177");
    // 设置发布时间
    WxTempOne time = new WxTempOne();
    time.setValue(jsonArray.getJSONObject(0).getString("reporttime"));
    time.setColor("#173177");
    // 放入data中
    wxWeatherTempData.setUser(one);
    wxWeatherTempData.setTime(time);
    wxWeatherTempData.setWeather(weather);
    wxWeatherTempData.setTemp(temp);
    // 放入wxtemp中
    wxTemp.setData(wxWeatherTempData);
    String access_token = baseService.getAccessToken();
    HttpRequest httpRequest = HttpRequest.post("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token);
    httpRequest.trustAllCerts();
    httpRequest.trustAllHosts();
    System.out.println(JSON.toJSONString(wxTemp));
    HttpRequest response = httpRequest.send(JSON.toJSONString(wxTemp));
    System.out.println(response.body());
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest) WxTempOne(cn.dubidubi.model.json.WxTempOne) WxTemp(cn.dubidubi.model.json.WxTemp) WxWeatherTempData(cn.dubidubi.model.json.WxWeatherTempData)

Example 35 with HttpRequest

use of com.github.kevinsawicki.http.HttpRequest in project PowerNukkitX by BlocklyNukkit.

the class VersionListHelper method listRemoteVersions.

public static List<VersionEntry> listRemoteVersions(final String category) {
    if (cache.containsKey(category)) {
        return exactKeys(cache.get(category));
    } else {
        final HttpRequest request = HttpRequest.get(OSS + "?" + "list-type=2" + "&" + "prefix=" + category + "/&" + "max-keys=30" + "&" + "delimiter=/");
        final String result = request.body(HttpRequest.CHARSET_UTF8);
        cache.put(category, result);
        return exactKeys(result);
    }
}
Also used : HttpRequest(com.github.kevinsawicki.http.HttpRequest)

Aggregations

HttpRequest (com.github.kevinsawicki.http.HttpRequest)86 HttpRequestException (com.github.kevinsawicki.http.HttpRequest.HttpRequestException)29 IOException (java.io.IOException)25 JSONObject (org.json.JSONObject)19 UnsupportedEncodingException (java.io.UnsupportedEncodingException)13 File (java.io.File)8 TimerTask (java.util.TimerTask)8 AtomicLong (java.util.concurrent.atomic.AtomicLong)8 Pair (android.util.Pair)6 URL (java.net.URL)5 JSONException (org.json.JSONException)5 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)4 JSONObject (com.alibaba.fastjson.JSONObject)4 ZipFile (net.lingala.zip4j.ZipFile)4 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)3 IPEntity (com.example.li.springboot_crawler_demo.utils.img.entity.IPEntity)2 HttpURLConnection (java.net.HttpURLConnection)2 MalformedURLException (java.net.MalformedURLException)2 Matcher (java.util.regex.Matcher)2 JSONArray (org.json.JSONArray)2