本接口走的是移动wap飞信接口,绝对安全
package net.duohuo.tengzhinei.Feition;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLEncoder;
import java.net.HttpURLConnection;
public class Feition {
static final String MOBILE="手机号";//实际使用时可放在配置文件中
static final String PASSWORD="密码啊";
static final String LOGINURL="http://f.10086.cn/im/login/inputpasssubmit1.action?";//登陆的URL
static final String SENDMSGURL="http://f.10086.cn/im/chat/sendShortMsg.action;";//发短信的URL
static final String SEARCH="http://f.10086.cn/im/index/searchOtherInfoList.action;";
static final String ADDFRIEND="http://f.10086.cn/im/user/insertfriend2.action;";
static final String CARD="jsessionid";
private String session; //对应的session 这里是jsessionid=abcukqLZwma_35eswdRdt的形式
private String t; //t不知到是什么返回的连接中都包含他,且是变化的这里是t=26181745728233079的形式
public String getSession() {
return session;
}
public void setSession(String session) {
this.session = session;
}
public String getT() {
return t;
}
public void setT(String t) {
this.t = t;
}
/**
* @param args
*/
public boolean login(String mobile ,String password){ //登录
String tAndSession=null;
String loginMsg="m="+mobile+"&pass="+password+"&loginstatus=4";
String loginURL=LOGINURL+loginMsg;
String all=null;
try {
all=post(loginURL);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// System.out.println(all);
int begin=all.indexOf(CARD);
int end=all.indexOf("\"", begin);
tAndSession=all.substring(begin, end);
String s=tAndSession.substring(0,tAndSession.indexOf("?"));
String t=tAndSession.substring(tAndSession.indexOf("?")+1);
setSession(s);
try {
Thread.sleep(1000); //sleep是因为登录后不能马上发短信的缘故
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setT(t);
return true;
}
String getToUserid(String toPhone){
String url=SEARCH+getSession()+"?"+getT()+"&searchText="+toPhone;
String all = "";
try {
all=post(url);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int begin=all.indexOf("touserid=");
int end=all.indexOf("&", begin);
return all.substring(begin,end);
}
/**
*@return String 放回的东西没什么意义只是看看移动到底返回什么给我
* @param touserid 是对方手机号
*/
public String sendMsg(String msg,String toPhone){
if( getSession()==null||getT()==null){
login(MOBILE, PASSWORD);
}
try {
msg=URLEncoder.encode(msg, "UTF-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
String msgSendURL=SENDMSGURL+getSession()+"?"+getToUserid(toPhone)+"&"+getT()+"&msg="+msg;
String all=null;
try {
all=post(msgSendURL);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(!all.contains("成功")){ //防止session过期等无法发送的问题
login(MOBILE, PASSWORD);
sendMsg(msgSendURL, toPhone);
}
return all;
}
void addFrident(String phone){
login(MOBILE, PASSWORD);
String url=ADDFRIEND+getSession()+"?"+getT()+"&number="+phone+"&type=0";
String all=null;
try {
all=post(url);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(all);
}
/**
* @see 原来方法中是用的是post方法,但是好像post没用,不知是我代码问题还是移动问题,反正get方法有用,方法名我就没改
*/
public String post(String urlStr) throws IOException{
String result="";
URL url=new URL(urlStr);
HttpURLConnection connection= (HttpURLConnection)url.openConnection();
BufferedReader in=new BufferedReader(new InputStreamReader( connection.getInputStream(),"UTF-8"));
String line;
while((line=in.readLine())!=null){
result+=line;
}
return result;
}
public static void main(String[] args) throws IOException {
Feition f=new Feition();
f.addFrident("好友手机号");
System.out.println("sfsdf");
f.sendMsg("消息", "你的手机号");
}
}
分享到:
相关推荐
import java.io.Console; import java.io.IOException; import java.util.Date; import cn.edu.ctgu.ghl.fetion.Contact; import cn.edu.ctgu.ghl.fetion.Fetion; import cn.edu.ctgu.ghl.fetion.FetionAppEvent; ...
java 飞信 接口 移动(用的移动的wap飞信接口)
java 飞信接口,有测试程序,及源代码。源代码经过反编译,测试时请注意
飞信的API在lib里面fetion-java-api.jar~~ 还说明一点,飞信大家都知道,免费的前提是自己开通飞信并且只能发送给飞信好友,所以别抱怨说还要密码什么的! !!!!!!!!!!!!!!!!!!!! 有童鞋说不能...
import java.io.IOException; import cn.edu.ctgu.ghl.fetion.Contact; import cn.edu.ctgu.ghl.fetion.Fetion; import cn.edu.ctgu.ghl.fetion.FetionEvent; import cn.edu.ctgu.ghl.fetion.IFetionEventListener;...
import java.io.IOException; import cn.edu.ctgu.ghl.fetion.Contact; import cn.edu.ctgu.ghl.fetion.Fetion; import cn.edu.ctgu.ghl.fetion.FetionEvent; import cn.edu.ctgu.ghl.fetion.IFetionEventListener;...
很难得的 java版飞信接口,下载了绝不后悔
Java开发的飞信程序,基于飞信接口,可以直接登录飞信账号执行各种操作,很强大的接口程序,对于学习QQ接口,飞信接口等这种接口的童鞋最适合不过
一个简单的例子实现java利用飞信接口发送短信
import java.io.IOException; import cn.edu.ctgu.ghl.fetion.Contact; import cn.edu.ctgu.ghl.fetion.Fetion; import cn.edu.ctgu.ghl.fetion.FetionEvent; import cn.edu.ctgu.ghl.fetion.IFetionEventListener;...
调用本资源的fection接口,可以实现免费发送短信,里面有详细的文档说明和代码注释。
使用java程序调用飞信的接口给好友发信息。 运行环境必须是6.0的
调用移动飞信接口实现免费发送短信java版源码
java程序利用中国移动的飞信接口进行开发基于飞信的发送短信模块..
import java.io.IOException; import cn.edu.ctgu.ghl.fetion.Contact; import cn.edu.ctgu.ghl.fetion.Fetion; import cn.edu.ctgu.ghl.fetion.FetionEvent; import cn.edu.ctgu.ghl.fetion.IFetionEventListener;...
我也是在网上搜了很久,搜出来都是不行,都是不能用了的...3分可能是有点 贵,但是为了避免更多人下载,乱发短信,现在飞信也没有很多接口,大家珍惜吧。希望大家不要用来乱发。我以我的拍着胸说,这个我测试通过了的。
包括STM32、ESP8266、PHP、QT、Linux、iOS、C++、Java、python、web、C#、EDA、proteus、RTOS等项目的源码。【项目质量】:所有源码都经过严格测试,可以直接运行。功能在确认正常工作后才上传。【适用人群】:适用...