Sina Weibo data capture (Java implementation)

Source: Internet
Author: User
Tags base64
1do not say more, directly posted the relevant part of the implementation code2 3 4 5encryption Part implementation:  6 7 8 9 Package Token.exe;
 One import Java.math.BigInteger;
 Import Java.util.Random;
 Import org.apache.commons.codec.binary.Base64;
 The public class Weiboencoder {+ private static BigInteger n = null;
 private static BigInteger E = null; 20 21/** 22 * Use Base64 encrypted username (su obtained) * @param account * @return * * * @Supp Resswarnings ("deprecation")-public-static string Encodeaccount (String account) {new STR
 ING (base64.encodebase64 (account.getbytes ());      29} 30 31/** 32 * Use Rsaencrypt to encrypt user password (SP) * @param pwd * * @param nstr 35 * @param estr * @return (+) public static string Rsaencrypt (string pwd, String nstr, String eSt
 R) {+ n = new BigInteger (nstr,16);
 E = new BigInteger (estr,16); BigInteger r = rsadopublic (Pkcs1pad2 (pwd, n.bitlength () +7); >3));
 The SP = r.tostring (16);
 if ((Sp.length () &1)!= 0) sp = "0" + sp;
 The return SP;
 BigInteger private static Rsadopublic (BigInteger x) {return X.modpow (e, N); The private static BigInteger pkcs1pad2 (String s, int n) {A/n < s.length () + 11) {/
 /Todo:fix for Utf-8 System.err.println ("message too long for RSA");
 return null;
 byte[] ba = new Byte[n];
 int i = S.length ()-1;
 while (i >= 0 && n > 0) {m int c = S.codepointat (i--);
 if (c < 128) {//encode using utf-8 ba[--n] = new Byte (string.valueof (c)); (C > 127) && (C < 2048) {Ba[--n] = new Byte (Str
 Ing.valueof ((C & 63) | 128); Ba[--n] = new Byte (String.valuEOf ((c >> 6) | 192);
 "Ba[--n Else" = new Byte (string.valueof (C & 63) | 128);
 Ba[--n] = new Byte (string.valueof ((c >> 6) & 63) | 128);
 Ba[--n] = new Byte (string.valueof (c >> 12) | 224);
 Ba[--n] = new Byte ("0");
 byte[] temp = new BYTE[1];
 Random RDM = new Random (47L);
 2 while (n >) {//random Non-zero pad bayi temp[0] = new Byte ("0");
 while (temp[0] = = 0) rdm.nextbytes (temp);
 Ba[--n] = temp[0];
 Ba[--n] = 2;
 Ba[--n] = 0;
 The new BigInteger (BA);  90} 91 92 93 94} 95 96 parameter entity:   Package token.def;
102 Import Java.io.Serializable; The Loginparams public class implements Serializable {The private static final long Serialversionuid =
-5775728968372860382l;
The private String pcid;
108 Private String Servertime;
109 Private String nonce;
The private String rsakv;
The private String Imgurl;
112 private String SP;
113 private String Code;
114 Private Boolean islogin = true; 116 public String Getpcid () {117 return pcid; 118} 119 The public void Setpcid (string PCID) {121 this.pcid = pcid; 122} 123 124 public String GetServerTime () {
Time     126} 127 128 public void Setservertime (String servertime) {129 this.servertime = Servertime; 130 131 132 public String getnonce () {the nonce; 134} 135 public void Setnonce (string no NCE) {136 this.nonce = nOnce 137} 138 139 Public String getrsakv () {140 return rsakv; RSAKV (String rsakv) {144 THIS.RSAKV = RSAKV; 145} 146 147 public String Getimgurl () {148 R
Eturn Imgurl;     149} 151 public void Setimgurl (String imgurl) {152 This.imgurl = Imgurl; 153} 154 155 Public String getsp () {156 return SP. 157} 158 159 public void setsp (String sp) {160 THIS.SP
= SP; 161} 162 163 public String GetCode () {164 return code; 165} 166 167 public void Setcode (Strin     G code) {This.code = code; 169} 170 171 public Boolean islogin () {172 return islogin; 173 } 174 175 public void Setlogin (Boolean islogin) {176 this.islogin = islogin; 177} 178 179 @Ove Rride 180 public String toString () {181 return "Loginparams [pcid=" + Pcid + ", servertime=" + servertime 1+ ", nonce=" + nonce + ", rsakv=" + rsakv + ", imgurl=" 183 + Imgurl + ", sp=" + SP + "
, code= "+ code +", islogin= "184 + IsLogin +"];  185} 186 187} 188 189 190 191 192 193 194 195 Landing Part implementation:  196 197 198 199 Package Token.exe;
201 Import Java.io.FileOutputStream;
Java.io.IOException import;
203 Import Java.net.URLEncoder;
204 Import Java.security.KeyManagementException;
205 Import java.security.NoSuchAlgorithmException;
206 Import Java.util.ArrayList;
207 Import Java.util.Date;
The import Java.util.HashMap;
209 Import Java.util.List;
210 Import java.util.Properties;
211 Import Java.util.Scanner;
212 213 Import Org.apache.commons.httpclient.Header;
214 Import Org.apache.commons.httpclient.HttpClient;
215 Import org.apache.commons.httpclient.HttpException;
216 Import Org.apache.commons.httpclient.HttpStatus;
217 Import Org.apache.commons.httpclient.HttpVersion;
218 Import Org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
219 Import Org.apache.commons.httpclient.NameValuePair;
The import Org.apache.commons.httpclient.cookie.CookiePolicy;
221 Import Org.apache.commons.httpclient.methods.GetMethod; 222 Import Org.apache.commons.httpclient.methods.PoStmethod;
223 Import Org.apache.commons.httpclient.params.HttpClientParams;
224 Import Org.apache.commons.httpclient.params.HttpConnectionManagerParams;
Import Org.apache.commons.httpclient.protocol.Protocol;
The import Org.jsoup.Jsoup;
The import org.jsoup.nodes.Document;
228 import org.jsoup.nodes.Element; 229 230 Import token.
Sinaweibooauth;
231 Import Token.def.LoginParams;
232 Import Weibo4j.model.MySSLSocketFactory;     233 234 235 public class Weibologiner {236 237 private httpclient httpclient;//httpclient Instance initialization 238 239 Public Weibologiner () {241//httpclient connection Configuration 242 Multithreadedhttpconnectionmanager HTTPM
Anager = new Multithreadedhttpconnectionmanager ();
243 Httpconnectionmanagerparams connectparams = Httpmanager.getparams ();
244 Connectparams.setconnectiontimeout (3000);
245 connectparams.setdefaultmaxconnectionsperhost (100);        
246 connectparams.setsotimeout (3000); 247//HTTPCLIENT parameter configuration 248 httpclientparams httpparams = new Httpclientparams ();
249 Httpparams.setcookiepolicy (cookiepolicy.browser_compatibility);
Httpparams.setversion (httpversion.http_1_1);
251//Set default Header 252 list
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.