[笔记]使用java简单製作line提示

这是我第一次在it邦发文章,主要是做一下笔记,顺便和大家技术交流,请各位指教

首先是IFTTT,说明请参照IFTTT 发送 LINE 讯息通知

再来是java的类别部分

JMaker.javapackage javaapplication4;import java.io.IOException;import java.io.UnsupportedEncodingException;import java.util.List;import org.apache.http.client.HttpClient;import org.apache.http.client.methods.HttpPost;import org.apache.http.entity.StringEntity;import org.apache.http.impl.client.HttpClientBuilder;public class JMaker {    private String eventName;    private String key;    public JMaker(String eventName, String key) {        this.eventName = eventName;        this.key = key;    }    public void trigger() throws IOException {        HttpClient httpClient = HttpClientBuilder.create().build();        HttpPost request = new HttpPost("https://maker.ifttt.com/trigger/" + eventName + "/with/key/" + key);        httpClient.execute(request);    }    public void trigger(String values) throws IOException {        HttpClient httpClient = HttpClientBuilder.create().build();        HttpPost request = new HttpPost("https://maker.ifttt.com/trigger/" + eventName + "/with/key/" + key);        StringEntity params = new StringEntity(buildJson(values), "UTF-8");        request.addHeader("content-type", "application/json");        request.setEntity(params);        httpClient.execute(request);    }    //2018-07-25 确认是否发送    public void trigger(String values, int state) throws IOException {        HttpClient httpClient = HttpClientBuilder.create().build();        HttpPost request = new HttpPost("https://maker.ifttt.com/trigger/" + eventName + "/with/key/" + key);        if (state == 0) {            StringEntity params = new StringEntity(buildJson(values), "UTF-8");            request.addHeader("content-type", "application/json");            request.setEntity(params);            httpClient.execute(request);        } else {            httpClient.execute(request);        }    }    private String buildJson(String values) throws UnsupportedEncodingException {        String json = "{";        json += "\"value1\":\"" + values + "\"";        json += "}";        System.out.println("传送 json: " + json);        return json;    }}

最后是使用的部分

main.javaJMaker maker = new JMaker(IFTTT的eventNam, IFTTT的key);maker.trigger("test");

lib引用的部分
http://img2.58codes.com/2024/20105113SRf77Yi6qL.jpg

完成的样子
http://img2.58codes.com/2024/20105113MGXB0L7jOr.jpg

最后再次讚叹google大神的伟大,也感谢各位大大无私的分享,在此贡献小弟一点经验,回馈大家


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章