zoukankan      html  css  js  c++  java
  • java 连接飞信API

    通过java连接飞信api给自己的好友(包括自己)发送飞信内容。如果对方的手机号非你的飞信好友则不能发送。
    1. [代码]飞信发送类     
    package per.artisan.fetion;


    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.net.URLEncoder;


    public class FetionSend {

    private String user; //mobile number of your fetion
    private String passwd; // the password for your account of fetion
    private String sendTo; // who you want to send
    private String message; // the message content

    private static final String httpUrl = "http://quanapi.sinaapp.com/fetion.php";
     public String getUser() {
    return user;
    }
    public void setUser(String user) {
    this.user = user;
    }
     public String getPasswd() {
    return passwd;
    }
    public void setPasswd(String passwd) {
    this.passwd = passwd;
    }
    public String getSendTo() {
    return sendTo;
    }
     public void setSendTo(String sendTo) {
    this.sendTo = sendTo;
    }
    public String getMessage() {
    return message;
    }
     public void setMessage(String message) {
    this.message = message;
    }
     public FetionResult send() throws IOException {
    FetionResult result = new FetionResult();
    result.setIfSucceed(false);

    if ("".equals(user) || user == null) {
    result.setResult("The user name can't be empty!");
    return result;
    }

    if ("".equals(passwd) || passwd == null) {
    result.setResult("The password can't be empty!");
    return result;
    }

    if ("".equals(sendTo) || sendTo == null) {
    result.setResult("The number you send to can't be empty!");
    return result;
    }

    if ("".equals(message) || message == null) {
    result.setResult("The message content can't be empty!");
    return result;
    }

    String getUrl = new StringBuffer(httpUrl).append("?u=").append(user).append("&p=").append(passwd)
    .append("&to=").append(sendTo).append("&m=").append(URLEncoder.encode(message,"utf-8")).toString();
    URL urlLocate = new URL(getUrl);广告代码
    HttpURLConnection connection = (HttpURLConnection) urlLocate.openConnection();
    connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    connection.connect();http://www.huiyi8.com/jiaoben/
    BufferedReader reader = new BufferedReader( new InputStreamReader(connection.getInputStream()));

    String lineResult;
    while ((lineResult = reader.readLine()) != null) {
    System.out.println(lineResult);
    }

    return result;
    }


    /**
    * @param args
    * @throws IOException 
    */
    public static void main(String[] args) throws IOException {
    FetionSend fetion = new FetionSend();
    fetion.setUser("123123123");
    fetion.setPasswd("xxx");
    fetion.setSendTo("123123123");
    fetion.setMessage("Hello Wrold!");
    fetion.send();
     }
    }
    2. [代码]结果返回类     
    package per.artisan.fetion;


    public class FetionResult {
    private boolean ifSucceed;
    private String result;

    public FetionResult() { }

    public FetionResult(boolean ifSucceed, String result) {
    this.ifSucceed = ifSucceed;
    this.result = result;
    }

    public boolean isIfSucceed() {
    return ifSucceed;
    }
    public void setIfSucceed(boolean ifSucceed) {
    this.ifSucceed = ifSucceed;
    }
    public String getResult() {
    return result;
    }
    public void setResult(String result) {
    this.result = result;
    }

    }

  • 相关阅读:
    递归
    二叉树
    IIs 网站应用程序与虚拟目录的区别及高级应用说明(文件分布式存储方案)
    Python时间,日期,时间戳之间转换
    jquery 时间戳和日期时间转化
    javascript 中解析json
    设计模式之单例模式
    深入理解DIP、IoC、DI以及IoC容器
    《大型网站技术架构》读书笔记一:大型网站架构演化
    Key/Value之王Memcached初探:二、Memcached在.Net中的基本操作
  • 原文地址:https://www.cnblogs.com/xkzy/p/3820466.html
Copyright © 2011-2022 走看看