This article mainly shares with you how to verify the owner on WeChat, hoping to help everyone.
<?php //这两个控制器是我本来就有的这里就不做演示 可以不继承 这个控制器用到的东西 不依靠外面的东西 namespace Apps\Controller; use Common\Controller\AppBaseController; /** * 首页 */ define("TOKEN", "");//定义你公众号自己设置的token define("APPID", "");//填写你微信公众号的appid 千万要一致啊 define("APPSECRET", "");//填写你微信公众号的appsecret 千万要记得保存 以后要看的话就只有还原了 保存起来 有益无害 class WeChatController extends AppBaseController { //判断是介入还是用户 只有第一次介入的时候才会返回echostr function index() { //这个echostr呢 只有说验证的时候才会echo 如果是验证过之后这个echostr是不存在的字段了 $echoStr = $_GET["echostr"]; if ($this->checkSignature()) { echo $echoStr; //如果你不知道是否验证成功 你可以先echo echostr 然后再写一个东西 exit; } }//index end //验证微信开发者模式接入是否成功 private function checkSignature() { //signature 是微信传过来的 类似于签名的东西 $signature = $_GET["signature"]; //微信发过来的东西 $timestamp = $_GET["timestamp"]; //微信传过来的值 什么用我不知道... $nonce = $_GET["nonce"]; //定义你在微信公众号开发者模式里面定义的token $token = "xiaochen"; //三个变量 按照字典排序 形成一个数组 $tmpArr = array( $token, $timestamp, $nonce ); // use SORT_STRING rule sort($tmpArr, SORT_STRING); $tmpStr = implode($tmpArr); //哈希加密 在laravel里面是Hash:: $tmpStr = sha1($tmpStr); //按照微信的套路 给你一个signature没用是不可能的 这里就用得上了 if ($tmpStr == $signature) { return true; } else { return false; } }// checkSignature end //构建一个发送请求的curl方法 微信的东西都是用这个 直接百度 function https_request($url, $data = null) { //这个方法我不知道是怎么个意思 我看都是这个方法 就copy过来了 $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); if (!empty($data)){ curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($curl); curl_close($curl); return $output; }//https_request end } //classend
The above is the detailed content of How to verify owner on WeChat. For more information, please follow other related articles on the PHP Chinese website!
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

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
Roblox: Grow A Garden - Complete Mutation Guide
3 weeks agoByDDD
Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
How to fix KB5055612 fails to install in Windows 10?
3 weeks agoByDDD
Nordhold: Fusion System, Explained
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

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

SublimeText3 Linux new version
SublimeText3 Linux latest version

WebStorm Mac version
Useful JavaScript development tools
