Some new ideas about the verification of WeChat public account attention

» WordPress » Some new ideas about the verification of WeChat public account attention

preface

I have written about the plug-in of WeChat official account verification code function before, and recently found that it can also be improved. Of course, I haven't actually changed this plug-in, just to say the following

 Some new ideas about the verification of WeChat public account attention - Geek Park

idea

The current verification function of public account verification code is to leave a QR code on the web page, and the user scans the code to follow, then reply to formulate keywords, such as verification code, and then obtain random characters, and then fill in the random characters on the web page to verify them. If OK, the content or other operations will be displayed.

Today, we are going to change the method. The process is to display the QR code first, and then the user needs to click to generate random characters, such as: sd345 is displayed on the web page, and the user needs to send this character to the WeChat public account. If the WeChat public account receives this verification code within the specified time, then it is deemed that the verification is passed and the next operation is carried out.

Implementation code

I'm not ready to do this today. I just sort out the code.
First, generate a random character, which can add many elements, such as date, time, article link, user browser UA, user IP, and package MD5 encryption together

Use a button where the short code is displayed, and click it to load a random verification code

 //Generate WeChat verification code function wx_captcha() { date_default_timezone_set('Asia/Shanghai'); $min      = floor(date("i") / 5); $day      = date("d"); $day      = ltrim($day, 0); $url      = get_permalink(); $wx_token = trim('xxxxoooootoken');/* WeChat token*/ $ua       = $_SERVER['HTTP_USER_AGENT']; $ip       = $_SERVER['HTTP_CLIENT_IP']; $captcha  = sha1($min . $url . $wx_token.$ua.$ip); $captcha  = substr($captcha, $day, 6); return $captcha; } //Short code for generating verification code function wx_captcha_gen_btn() { return '<a id="wx_captcha_gen_btn" href="javascript:; "Data action=" wx_captcha_gen "class=" cm btn primary wx_captcha_gen_btn ">Click to load the verification code</a>';; } add_shortcode('wx_captcha_btn', 'wx_captcha_gen_btn'); //Accept ajajx information function wx_captcha_gen() { if (isset($_POST['action']) && $_POST['action'] == 'wx_captcha_gen') { exit(wx_captcha()); } else { exit('400'); } } add_action('wp_ajax_wx_captcha_gen', 'wx_captcha_gen'); add_action('wp_ajax_nopriv_wx_captcha_gen', 'wx_captcha_gen');

Create an ajax generated verification code in the js code

 $("#wx_captcha_gen_btn").click(function() { var ajax_data = { action: $("#wx_captcha_gen_btn").data("action") }; $.post(ajaxurl,  ajax_data,function(b){ b = $.trim(b); // Login information if (b !== ' 400' && b == '200') { $('#wx_captcha_gen_btn').after(b);// Insert verification code character $.post(ajaxurl, 'checkmp', Function (c) {//Start to check whether the public account receives this verification code c = $.trim(c); // Login information if (c !== ' 400 '&&c=='200') {//If information is received $load_content();// Load hidden content } else { Alert ("An error occurred"); } }); } else { Alert ("An error occurred"); } }); });

The above code is only a rough outline. Don't take it seriously. The specific implementation needs to be further deepened.

Comb

1. The user opens the page
2. The user clicked the button to load the verification code
3. The load verification code button initiates ajax, and the background receives information to generate the verification code and displays it on the foreground page
4. After the verification code is displayed, launch another ajax to poll whether the WeChat public account has received the verification code generated above. For performance reasons, set the upper limit of the number of polling times. It is not easy to identify the failure at that time
5. WeChat official account receives the verification code and verifies that it is OK, and starts to display the hidden content

--End--

Post reply

Your email address will not be disclosed. Required items have been used * tagging

3 Replies to "Some new ideas about the verification of WeChat public accounts"

  1. The plugin before the blogger always prompts on the public account
    "I replied that the service provided by the public account is faulty, please try again later."
    The code can't be downloaded. It's troublesome to deal with it at a convenient time when you send a private message to gitee.

    Under the technical advice, the plug-in has a cache. How long is the default cache time? The technology is limited, and no code changes have been found. Thank you.