网站监测短信、微信提醒

1.注册来信码:@官网

注册后

1.1,开发者选项-开发设置,获取accesskey\secretkey

1.2,融合通讯-IM及时通讯,开启IM

2.微信关注公众号"来信码",手机绑定

3.代码

 

复制代码
package yanantest;

import java.io.IOException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

public class TestImlaixin {
    public static void main(String[] args) {
        //测试时请将替换你的useraccesskey、、usersecretkey、、mobile
        //url1和url2作用一样,个人猜测url1是现在的语法,url2是老版本。get和post结果一样。httpclient个人学的不精通,不推荐哪种方式了
        //String url1="https://imlaixin.cn/Api/send/data/json?accesskey=useraccesskey&secretkey=usersecretkey&mobile=1******76**&content=你好,world";
        //String url2="http://sms.bechtech.cn/Api/send/data/json?accesskey=useraccesskey&secretkey=usersecretkey&mobile=1******76**&content=你好,world";
        //testGet(url1);
        //testPost(url2);
    }
    @SuppressWarnings("finally")
    public static String testGet(String url){
        @SuppressWarnings({ "resource", "deprecation" })
        HttpClient httpClient=new DefaultHttpClient();
        HttpGet get= new HttpGet(url);
        get.setHeader("User-Agent", "Mozilla/5.0");
        String string="";
        try {
            HttpResponse response = httpClient.execute(get);
            HttpEntity entity = response.getEntity();
            string = EntityUtils.toString(entity, "UTF-8");
            System.out.println(response.getStatusLine().getStatusCode());
            get.releaseConnection();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally{
            return string;
        }
    }@SuppressWarnings("finally")
    public static String testPost(String url){
        @SuppressWarnings({ "resource", "deprecation" })
        HttpClient httpClient=new DefaultHttpClient();
        HttpPost post=new HttpPost(url);
        StringEntity se = new StringEntity("", "UTF-8");
        post.setHeader("User-Agent", "Mozilla/5.0");
        post.setEntity(se);
        String string="";
        try {
            HttpResponse response = httpClient.execute(post);
            HttpEntity entity = response.getEntity();
            string = EntityUtils.toString(entity, "UTF-8");
            System.out.println(response.getStatusLine().getStatusCode());
            post.releaseConnection();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally{
            return string;
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值