Fill in the relevant information for registration. here I register a personal subscription number. if you have company information, you can register a service number. In addition, the personal subscription number interface is limited, which is not very favorable for personal development. a test account is also provided for developers, enter the following address to apply for test code development: preparation Phase 1 development preparation phase
Required Resources: 1. public platform account
2. Baidu BAE platform account
I,Public Account application
You have registered on the public platform in the upper right corner.
The test code permission is good for developers ~
Because the developer access mode needs to provide the url address that can be used by the server to send requests, your server must be able to access the public network and use dns service providers such as peanut shells, because I am using residential broadband and cannot resolve it, I switched to Baidu's bae instead. I can try it without a public ip address. it is quite convenient to test the preliminary access ,, you can log on with a Baidu account. Note that you must use svn and other management applications in bae, however, the user name does not support Chinese characters. if your Baidu account is a Chinese user, register a new English user,
After the preparation is complete, write the code to become a developer of the public platform. the following code is from the blog of Liu Feng.
Core Category:
Package com. vlive. action. connector; import java. io. IOException; import java. io. printWriter; import javax. servlet. servletException; import javax. servlet. http. httpServlet; import javax. servlet. http. httpServletRequest; import javax. servlet. http. httpServletResponse; import com. vlive. utils. signUtil; public class URlresponse extends HttpServlet {@ Override protected void doGet (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {// encrypted signature String signature = req. getParameter ("signature"); // timestamp String timestamp = req. getParameter ("timestamp"); // random number String nonce = req. getParameter ("nonce"); // random String echostr = req. getParameter ("echostr"); PrintWriter out = resp. getWriter (); // verify the request by verifying signature. if the request is verified successfully, echostr is returned as is, indicating that the access is successful. Otherwise, the access fails if (SignUtil. checkSignature (signature, timestamp, nonce) {out. print (echostr);} out. close (); out = null ;}}
This class uses the checkSignature method of SignUtil:
Package com. vlive. utils; import java. security. messageDigest; import java. security. noSuchAlgorithmException; import java. util. arrays; public class SignUtil {private static String token = "vlive"; public static boolean checkSignature (String signature, String timestamp, String nonce) {String [] arr = new String [] {token, timestamp, nonce}; // lexicographically sorts the three parameters token, timestamp, and nonce. sort (arr); String Builder content = new StringBuilder (); for (int I = 0; I <arr. length; I ++) {content. append (arr [I]);} MessageDigest md = null; String tmpStr = null; try {md = MessageDigest. getInstance ("SHA-1"); // concatenates three parameter strings into one string for sha1 encryption byte [] digest = md. digest (content. toString (). getBytes (); tmpStr = byteToStr (digest);} catch (NoSuchAlgorithmException e) {e. printStackTrace ();} content = null; // encrypt sha1 The following string can be compared with signature to identify the request from return tmpStr! = Null? TmpStr. equals (signature. toUpperCase (): false ;} /*** convert a byte array to a hexadecimal String ** @ param byteArray * @ return */private static String byteToStr (byte [] byteArray) {String strDigest = ""; for (int I = 0; I <byteArray. length; I ++) {strDigest + = byteToHexStr (byteArray [I]);} return strDigest ;} /*** convert bytes to a hexadecimal String ** @ param mByte * @ return */private static String byteToHexStr (byte mByte) {char [] Digit = {'0', '1', '2', '3', '4', '5', '6', '7 ', '8', '9', 'A', 'B', 'C', 'D', 'e', 'F '}; char [] tempArr = new char [2]; tempArr [0] = Digit [(mByte >>> 4) & 0X0F]; tempArr [1] = Digit [mByte & 0X0F]; String s = new String (tempArr); return s ;}}
Below is the web. xml
URlresponse
Com. vlive. action. connector. URlresponse
URlresponse
/Urlresponse
Index. jsp
Now the access configuration can begin.
Enter the corresponding url and token to become a developer ~
The above is a detailed description of the graphic code at the preparation stage of development. For more information, see other related articles on php Chinese network!