WeChat URL validity verification and email URL validity Verification

Source: Internet
Author: User
Tags sha1 encryption

URL validity verification and email URL validity Verification

1. Fill in configuration items: Fill in the URL and Token, click the submit button, the server will request the specified URL in get mode, and verify the URL validity in this URL

2. URL validity Verification:

1 if ("get ". equalsIgnoreCase (request. getMethod () {2 StringBuffer sb = new StringBuffer (); 3 // find the token from the database or set the token to a fixed value of 4 String token = ""; 5 // 1. sort the token, timestamp, and nonce parameters in Lexicographic Order. 6 // 2. splice the three parameter strings into one string for sha1 encryption 7 // 3. the encrypted string obtained by the developer can be compared with signature to identify that the request comes from 8 // If you confirm that the GET request is from the server, the request returns the echostr parameter content as it is, and the access takes effect, the developer is successful. Otherwise, the access fails. 9 String signature = request. getParameter ("signature"); 10 String timestamp = request. getParameter ("timestamp"); 11 String nonce = request. getParameter ("nonce"); 12 String echostr = request. getParameter ("echostr"); 13 if (! WeixinUtil. checkSignature (signature, token, timestamp, nonce) 14 {15 echostr = ""; 16} 17 sb. append (echostr); 18 this. inputStream = new ByteArrayInputStream (sb. toString (). getBytes ("UTF-8"); 19}

 

/*** Check whether the request is a qualified Request * @ param signature * @ param token * @ param timestamp * @ param nonce * @ return true: Pass <br/> * false: unqualified */public static boolean checkSignature (String signature, String token, String timestamp, String nonce) {if (signature = null | token = null | timestamp = null | nonce = null) {return false ;} list <String> tmpArr = new ArrayList <String> (); tmpArr. add (token); tmpArr. add (timestamp); tmpArr. add (nonce); Collections. sort (tmpArr); String tmpStr = tmpArr. get (0) + tmpArr. get (1) + tmpArr. get (2); try {MessageDigest md; md = MessageDigest. getInstance ("SHA-1"); md. update (tmpStr. getBytes (); tmpStr = getFormattedText (md. digest ();} catch (NoSuchAlgorithmException e) {e. printStackTrace ();} if (tmpStr. equals (signature) {return true;} else {return false ;}}

 

1/** 2 * Format 3 * @ param bytes 4 * @ return 5 */6 public static String getFormattedText (byte [] bytes) {7 int len = bytes. length; 8 StringBuilder buf = new StringBuilder (len * 2); 9 for (int j = 0; j <len; j ++) {10 buf. append (HEX_DIGITS [(bytes [j]> 4) & 0x0f]); 11 buf. append (HEX_DIGITS [bytes [j] & 0x0f]); 12} 13 return buf. toString (); 14}

 


Java Development public platform development URL Verification

Let's take a look at Liu Feng's java Development blog blog.csdn.net/...944988.
Blog.csdn.net/..6622/2

C # How to verify the validity of a URL to become a developer

To have an internet server, you can rent a virtual host that supports asp.net, and then return the specified content with reference to the settings to complete the verification. Very simple.

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.