1 PackageCom.hydsoft.hotnetworks.system.controller;2 3 Importjava.io.IOException;4 Importjava.io.UnsupportedEncodingException;5 Importjava.security.MessageDigest;6 Importjava.util.ArrayList;7 Importjava.util.Date;8 Importjava.util.List;9 Ten Importorg.apache.http.HttpEntity; One ImportOrg.apache.http.NameValuePair; A Importorg.apache.http.client.ClientProtocolException; - Importorg.apache.http.client.entity.UrlEncodedFormEntity; - ImportOrg.apache.http.client.methods.CloseableHttpResponse; the ImportOrg.apache.http.client.methods.HttpPost; - Importorg.apache.http.impl.client.CloseableHttpClient; - Importorg.apache.http.impl.client.HttpClients; - ImportOrg.apache.http.message.BasicNameValuePair; + Importorg.apache.http.util.EntityUtils; - + Public classTest { A at Public Static voidMain (String args[]) { -String url = "Https://api.netease.im/sms/sendcode.action";//get the fixed request path for the captcha -String AppKey = "b9bfe886534643e110f8446d860ead7c";//Key for Application -String Appsecret = "610128b2fabe";//password for the app -String nonce = "123456";//Random number -String mobile = "18201623501";//Target Phone number inString curtime=string.valueof ((NewDate (). GetTime ()/1000l)); -String checkSum = Getchecksum (Appsecret, nonce, curtime);//get the parameters required to send the verification code checksum to +Closeablehttpclient httpclient =Httpclients.createdefault (); - //saving parameters to the request header theHttpPost HttpPost =Newhttppost (URL); *Httppost.addheader ("AppKey", AppKey); $Httppost.addheader ("Nonce", nonce);Panax NotoginsengHttppost.addheader ("Curtime", curtime); -Httppost.addheader ("CheckSum", checkSum); theHttppost.addheader ("Content-type", "Application/x-www-form-urlencoded;charset=utf-8"); + A theList<namevaluepair> Formparams =NewArraylist<namevaluepair>(); +Formparams.add (NewBasicnamevaluepair ("mobile", mobile)); - urlencodedformentity uefentity; $ Try { $Uefentity =NewUrlencodedformentity (Formparams, "UTF-8"); - httppost.setentity (uefentity); -SYSTEM.OUT.PRINTLN ("Executing request" +Httppost.geturi ()); theCloseablehttpresponse response =Httpclient.execute (HttpPost); - Try { Wuyihttpentity entity =response.getentity (); the if(Entity! =NULL) { -System.out.println ("Response content:" + entityutils.tostring (Entity, "UTF-8")); Wu } -}finally { About Response.close (); $ } -}Catch(clientprotocolexception e) { - E.printstacktrace (); -}Catch(unsupportedencodingexception E1) { A E1.printstacktrace (); +}Catch(IOException e) { the E.printstacktrace (); -}finally { $ //Close the connection and release the resource the Try { the httpclient.close (); the}Catch(IOException e) { the E.printstacktrace (); - } in } the } the //calculate and get checksum About Public Staticstring Getchecksum (String Appsecret, String nonce, String curtime) { the returnEncode ("SHA1", Appsecret + nonce +curtime); the } the + //calculate and get MD5 values - Public Staticstring getMD5 (String requestbody) { the returnEncode ("MD5", requestbody);Bayi } the the Private Staticstring Encode (string algorithm, String value) { - if(Value = =NULL) { - return NULL; the } the Try { the messagedigest messagedigest the=messagedigest.getinstance (algorithm); - messagedigest.update (Value.getbytes ()); the returnGetformattedtext (Messagedigest.digest ()); the}Catch(Exception e) { the Throw NewRuntimeException (e);94 } the } the Private StaticString Getformattedtext (byte[] bytes) { the intLen =bytes.length;98StringBuilder buf =NewStringBuilder (LEN * 2); About for(intj = 0; J < Len; J + +) { -Buf.append (hex_digits[(Bytes[j] >> 4) & 0x0f]);101Buf.append (Hex_digits[bytes[j] & 0x0f]);102 }103 returnbuf.tostring ();104 } the Private Static Final Char[] hex_digits = {' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ',106' 6 ', ' 7 ', ' 8 ', ' 9 ', ' A ', ' B ', ' C ', ' d ', ' e ', ' F ' };107}
2016-08-09 18:28:51
NetEase Cloud Letter Send SMS Verification code