日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java 飞信接口_java 飞信接口

發布時間:2025/3/19 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 飞信接口_java 飞信接口 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本接口走的是移動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("&amp", 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("消息", "你的手機號");

}

}

分享到:

2011-07-13 11:41

瀏覽 1842

評論

1 樓

dingchuan

2012-08-19

有驗證碼,連接失敗

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的java 飞信接口_java 飞信接口的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。