天天看點

Java模拟登入微信平台,主動推送消息給使用者,自動綁定url、token等

一、簡要說明

在博文《Java模拟登入微信公衆平台,主動推送圖文消息給使用者》中提到使用Java語言登入微信公衆平台,然後發送圖文消息給使用者,基本可以符合使用要求,但是在今年10月23日,微信公衆平台的界面有所變化,是以,上一篇博文的代碼不再适用,很多朋友留言,不能使用了怎麼辦,這篇文章針對新版本做了處理,并且加入了新的功能,代碼上要感謝trprebel這位朋友。

二、代碼功能和要求

*.new Weixin()對象,先登入再取粉絲數和者發消息;

*.發消息需要設定post參數中的content;

*.内容中的超連結可以直接發送不用使用标簽;

*.經過我(trprebel)修改之後,此份代碼可在2013年11月之後使用;

*.我隻做了擷取粉絲清單和發送消息,其他部分未做;

*.理論上可以擷取到粉絲的位址,簽名等一切你登陸可以得到的資訊;

*.另外可能需要你在本機先登陸過至少一次微信公衆平台擷取SSL證書;

*.此份代碼作者較多,函數前面都有作者名,我隻修改了登陸,擷取粉絲清單和發送消息;

*.其他代碼可能已經不能用了但我并沒有删除,友善大家擴充,我做的也比較粗糙,沒整理;

*.另外,騰訊3天之内又加了一條限制,粉絲24小時之内沒有主動說話,微信公衆平台不能主動與其說話,官方平台登陸也不行;

使用到的庫:commons-codec-1.3.jar、commons-httpclient-3.1.jar、commons-lang.jar、commons-logging-1.0.4.jar、fastjson-1.1.15.jar、gson-2.2.4.jar、httpclient-4.1.3.jar、httpcore-4.1.4.jar、jsoup-1.5.2.jar

環境:JDK1.6

三、代碼下載下傳

使用的庫請自己下載下傳,源代碼如下:

Java模拟登入微信平台,主動推送消息給使用者,自動綁定url、token等

SimulateWechatLogin.zip

如果使用有任何的問題,請直接回複博文即可...

四、核心代碼和說明

Weixin.java模拟請求的連結及結構

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100

public

final

static

String HOST = 

"http://mp.weixin.qq.com"

;

public

final

static

String LOGIN_URL = 

"http://mp.weixin.qq.com/cgi-bin/login?

;

public

final

static

String INDEX_URL = 

"

http://mp.weixin.qq.com/cgi-bin/indexpage?t=wxm-index&

;

public

final

static

String SENDMSG_URL = 

"

https://mp.weixin.qq.com/cgi-bin/singlesend"

;

public

final

static

String FANS_URL = 

"http://mp.weixin.qq.com/cgi-bin/contactmanagepage?t=wxm-friend&

;

public

final

static

String LOGOUT_URL = 

"

http://mp.weixin.qq.com/cgi-bin/logout?t=wxm-logout&

;

public

final

static

String DOWNLOAD_URL = 

"

http://mp.weixin.qq.com/cgi-bin/downloadfile?"

;

public

final

static

String VERIFY_CODE = 

"http://mp.weixin.qq.com/cgi-bin/verifycode?"

;

public

final

static

String POST_MSG = 

"https://mp.weixin.qq.com/cgi-bin/masssend?t=ajax-response"

;

public

final

static

String VIEW_HEAD_IMG = 

"http://mp.weixin.qq.com/cgi-bin/viewheadimg"

;

public

final

static

String GET_IMG_DATA = 

"http://mp.weixin.qq.com/cgi-bin/getimgdata"

;

public

final

static

String GET_REGIONS = 

"http://mp.weixin.qq.com/cgi-bin/getregions"

;

public

final

static

String GET_MESSAGE = 

"http://mp.weixin.qq.com/cgi-bin/getmessage"

;

public

final

static

String OPER_ADVANCED_FUNC = 

"http://mp.weixin.qq.com/cgi-bin/operadvancedfunc"

;

public

final

static

String MASSSEND_PAGE = 

"http://mp.weixin.qq.com/cgi-bin/masssendpage"

;

public

final

static

String FILE_MANAGE_PAGE = 

"http://mp.weixin.qq.com/cgi-bin/filemanagepage"

;

public

final

static

String OPERATE_APPMSG = 

"https://mp.weixin.qq.com/cgi-bin/operate_appmsg?token=416919388&

;

public

final

static

String FMS_TRANSPORT = 

"

http://mp.weixin.qq.com/cgi-bin/fmstransport"

;

// public final static String CONTACT_MANAGE_PAGE =

// "http://mp.weixin.qq.com/cgi-bin/contactmanagepage";

public

final

static

String CONTACT_MANAGE_PAGE = 

"http://mp.weixin.qq.com/cgi-bin/contactmanage"

;

public

final

static

String OPER_SELF_MENU = 

"http://mp.weixin.qq.com/cgi-bin/operselfmenu"

;

public

final

static

String REPLY_RULE_PAGE = 

"http://mp.weixin.qq.com/cgi-bin/replyrulepage"

;

public

final

static

String SINGLE_MSG_PAGE = 

"http://mp.weixin.qq.com/cgi-bin/singlemsgpage"

;

public

final

static

String USER_INFO_PAGE = 

"http://mp.weixin.qq.com/cgi-bin/userinfopage"

;

public

final

static

String DEV_APPLY = 

"http://mp.weixin.qq.com/cgi-bin/devapply"

;

public

final

static

String UPLOAD_MATERIAL = 

"https://mp.weixin.qq.com/cgi-bin/uploadmaterial?cgi=uploadmaterial&type=2&token=416919388&t=iframe-uploadfile&

;

public

void

login() {}

private

boolean

_login() {}

private

String getToken(String s) {}

public

void

index() 

throws

HttpException, IOException {}

public

void

logout() 

throws

HttpException, IOException {}

public

InputStream code() 

throws

HttpException, IOException {}

public

int

getFans() {}

private

int

parseFansCount(String text) {}

private

int

parseFans(String text) {}

public

boolean

msgSend(MsgForm form, MsgType type) {}

public

boolean

sendMsg(

int

i) {}

public

void

updateImg(ImgFileForm form) {}

public

void

redirect(String url) {}

//使用樣例說明

public

static

void

main(String[] args) {

String LOGIN_USER = 

"

[email protected]"

// 此為上一任作者的使用者名和密碼,截止到我最後用發現還能用

String LOGIN_PWD = 

"AAbb1122"

;

Weixin wx = 

new

Weixin(LOGIN_USER, LOGIN_PWD);

wx.login();

wx.getCookiestr();

// ImgFileForm form = new ImgFileForm();

// form.setUploadfile(new File("D:Dataimage4.jpg"));

// wx.updateImg(form);

System.out.println(

"粉絲數:"

+ wx.getFans());

wx.sendMsg(

1

);

// 像好友清單中的第幾個好友發消息,從0開始

}

---

Enjoy~~~如果能幫助到你,請回複博文或者分享給他人,謝謝~

轉載出處:【微信公衆平台改版後】Java模拟登入微信平台,主動推送消息給使用者

繼續閱讀