


Implementation code for scanning QR code to follow and one-click following WeChat official account
This article mainly shares with you the implementation code of scanning the QR code to follow and one-click following the WeChat public account, hoping to help everyone better develop the WeChat public account function.
* 获取一键关注授权标识 * */ public function getIdentification() { $burl = "https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info?access_token=" . $this->access_tokens . ""; $result = curl_get($burl); preg_match('/__biz.*&mid/', $result, $matches);//正则截取字符串 $sVid = $this->get_between($matches[0], "__biz=", "==&mid");//截取出微信公众号唯一标识 $okurl="https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=".$sVid."==&scene=124#wechat_redirect"; jumpUrl($okurl); }
php custom interception of the middle part of the string method, used above, post it!
/* * php截取指定两个字符之间字符串 * */function get_between($input, $start, $end) { $substr = substr($input, strlen($start) + strpos($input, $start), (strlen($input) - strpos($input, $end)) * (-1)); return $substr;}
WeChat public account scan code to follow the code
First go to the WeChat public account before and after Scan the code to focus on the code that is not separated
<?php header("Content-type: text/html; charset=utf-8"); //http://pay.sucaihuo.com/project/access_token //php获取微信access_token,appid和app_secret得到微信access_token //php根据appid和secret获取微信access_token,php通过curl远程获取微信access_token信息 $appid = '自己公众号的appid'; $secret = '自己公众号的secret '; $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . ""; $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($ch); if($result == false) { echo 'Curl error: ' . curl_error($ch); } curl_close($ch); $access_tokens = json_decode($result, true); //print_r($access_tokens); $access_token = $access_tokens['access_token']; function getTemporaryQrcode($access_token, $orderId) { $url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" . $access_token . ""; $qrcode = '{"expire_seconds": 1800, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": ' . $orderId . '}}}'; $result = api_notice_increment($url, $qrcode); $rs = json_decode($result, true); return $rs; // return urldecode($rs['url']); } $rs = getTemporaryQrcode($access_token, 1123); //print_r($rs); $ticket = $rs['ticket']; $qrcode = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" . $ticket . ""; //print_r($qrcode); function api_notice_increment($url, $data) { $ch = curl_init(); // $header = "Content-type: text/xml"; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); // curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_AUTOREFERER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $tmpInfo = curl_exec($ch); if (curl_errno($ch)) { curl_close($ch); return $ch; } else { curl_close($ch); return $tmpInfo; } } ?> <p style="text-align: center;"> <p>关注素材火公众号</p> <img src="<?php echo $qrcode; ?>" alt="关注公众号二维码" style="width:100px;height:100px;"/> </p>
and then put the code changed into the interface
post method
class Wxfollow { protected $appid = 'wxf1d959b99f33b156'; protected $secret = '248f3a560604555ec96215c085cb2723'; protected $url = ""; protected $access_tokens = ""; public function __construct() { //获取$access_token $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $this->appid . "&secret=" . $this->secret . ""; $result = curl_post($url); $access_tokens = json_decode($result, true); $this->access_tokens = $access_tokens['access_token']; } public function Follow(){ //非必传项 $rs = $this->getTemporaryQrcode($this->access_tokens, 123); $ticket = $rs['ticket']; $qrcode = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" . $ticket . ""; ///打印二维码显示 jumpUrl($qrcode); } //生成二维码 public function getTemporaryQrcode($access_tokens,$orderId) { $url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" .$access_tokens . ""; //生成二维码需要的参数 $qrcode = '{"expire_seconds": 1800, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": ' . $orderId . '}}}'; $momo = json_decode($qrcode, true); $result = curl_post($url, $momo); $rs = json_decode($result, true); return $rs; }
curl encapsulation class
function curl_post($url, array $params = array()) { $data_string = json_encode($params); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json' ) ); $data = curl_exec($ch); curl_close($ch); return ($data); }
Related recommendations :
Use php to determine whether the user follows the WeChat public account
PHP background development WeChat public account example
The above is the detailed content of Implementation code for scanning QR code to follow and one-click following WeChat official account. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Some friends want to use their mobile phones to install computer systems. But I don’t know how to install Windows system on my mobile phone. In fact, there is a way to reinstall the computer system on a mobile phone with one click. So how to reinstall the computer system on a mobile phone with one click? Next, I will teach you a detailed tutorial on reinstalling the Windows system on your computer with one click on your mobile phone. 1. Download and install Android running the virtual machine software and system Bochs image file on your computer. 2. After the installation is completed, unzip the installation package of the Android running virtual machine software, and you will see the "Bochs" and "SDL" files. Then unzip the system package and copy the ".Img" CD image file to the "SDL" directory. 3. Then install the Bochs file into the phone and put the SDL folder on the phone S

As Microsoft's most classic system, win7 has a large number of loyal users, but no matter what system is used for a long time, various problems will always occur. At this time, we will think of reinstalling the system to solve the problem, so how to solve the problem? What about reinstalling the win7 system with one click? Next, the editor will share with you the one-click reinstallation system tutorial for windows7. Let’s take a look. 1. First, download the one-click reinstallation system software from the official website. The official website address: http ://www.zhuangjiba.com 2. Open the Run Installation Bar and reinstall the system software with one click. Close all anti-virus software before opening it to avoid failure of the reinstallation process due to interception. 3. After opening the software, the one-click installation interface will be opened by default. Here, select system reinstallation. 4.

When we use computers, we will inevitably encounter some problems that require us to reinstall the system to solve them. When reinstalling the system, we need to use the one-click system reinstallation tool to help us reinstall the system. Recently, a user asked the editor Dabaicai how to operate the one-click system reinstallation. So let me demonstrate it to you below. Let’s take a look below! Graphic tutorial for one-click system reinstallation of Dabaicai: 1. After inserting the U disk, double-click to open the Dabaicai U disk creation tool, click "Yes" to download the components online, and click "One-click to create a USB boot disk" after the components are successfully updated. That’s it. 2. After making the USB boot disk, insert the USB disk and press the shortcut key to enter bios. Select the U disk option and press Enter to enter the next step. Note: It usually has the word "USB"

In previous Windows systems, you can use the return to desktop button in the lower right corner to return to the desktop with one click. However, many friends found that this function is no longer available after updating to win11. In fact, win11 just made it into a line, and you can click it. Okay, let’s take a look together. How to return to the desktop with one click in win11 1. The one-click return to the desktop in win11 is made into a line, just click it. 2. But unlike the win10 system, you can also return to the desktop by clicking on the range on the right side of the line. In win11, you must click accurately on the line to use it, which is very troublesome. 3. Therefore, if we find it troublesome, we can directly press the "Win+D" shortcut key on the keyboard to return directly to the desktop.

The longer our computer is used, the more running memory will be occupied, so we need to clean up the running memory from time to time. However, there are still many users who don’t know how to release running memory in Win10 with one click. Next, the editor will give you a one-click guide on Win10 Let me share with you how to release running memory. How to quickly clean up running memory in win10: 1. First, we open "This PC" on the desktop, on the page, right-click and select "Properties" in the C drive. 2. After entering the properties page, we click the "Disk Cleanup" option below. 3. Then it will start scanning the junk files in the c drive, just wait patiently for a while. 4. After the cleaning is completed, the disk junk files will pop up. We can just check the box to clean them all. 5.

Although the latest operating system is win10 system, win7 system is still loved by many users. Recently, some users want to know the graphic tutorial on one-click reinstallation of win7 system, so the editor has compiled some information for you in the past two days. Let’s take a look at how to reinstall the win7 system with one click. How to reinstall Windows 7 system with one click 1. We open Baidu search to download the Xiaobai three-step installation software and open it, select to install win7, and click to reinstall now. 2. After Xiaobai’s three-step installation version downloads the system files, we click Restart Now. 3. Select xiaobaipe to enter the windows startup management page. 4. In the pe system, the Xiaobai installation tool will automatically help us install the system. After installation, click Restart Now

How to use one-click ghost system software in win10? Many friends who have installed ghostwin10 system do not know how to use one-click ghost. In fact, ghostwin10 is a very good system software, very stable and convenient. Today I have a detailed explanation installation method. Let’s take a look at the practical process of applying one-click ghost in Win10. The process of using one-key ghost in win10 1. Run the one-key ghost recovery tool, click "Backup System", select the backup path, click the partition C drive, and confirm. 2. Partition the backup disk to the D drive and ask if you want to restart the computer. Click "Restart now" to restart.

Many friends have started to experience some lags because their computers have been used for a long time. Since they don’t want to reinstall the system, they want to restore the system. However, because the computer still has some important things that need to be backed up, they don’t know how to back them up. System, the editor below will share with you the steps to back up the system with one click. 1. First, back up the important data inside the computer, then download and install the one-click system reinstallation tool of Kaka Installer and open it, select "Backup/Restore" to enter Next step. As shown in the figure: 2. Switch the interface to the "GHOST Backup Restore" option, click "Add Backup" to next step. As shown in the figure: 3. Add backup to the system that needs to be backed up, and change the compression level to "Low (large file, fast speed)" and next step. As shown in the picture
