Users to scan the page to provide the QR code to achieve access to information, we refer to the use of it
Please download the Snoopy class first
The code is as follows:
<?php
/**
* Public Platform PHP-SDK
* Wechatauth for unofficial Login API
* Users to access the QR code provided by scanning the Web page to achieve the landing information
* The main implementation of the following functions:
* Get_login_code () to obtain a login authorization code, through the authorization code to obtain the QR code
* Get_code_image ($code = ") Converts the authorization code obtained above to the image QR code
* Verify_code () to determine if the login was successful, return 200 for final authorization success.
* Get_login_cookie () Call this method to obtain basic user information after successful authentication
* Sendnews ($account, $title, $summary, $content, $pic, $srcurl = ") send text messages to an account
* Get_avatar ($url) Get profile picture data
* @author Dodge <dodgepudding@gmail.com>
* @link HTTPS://GITHUB.COM/DODGEPUDDING/WECHAT-PHP-SDK
* @version 1.1
*
*/
Include "snoopy.class.php";
Class Wechatauth
{
Private $cookie;
Private $_cookiename;
Private $_cookieexpired = 3600;
Private $_account = ' test ';
Private $_datapath = './data/cookie_ ';
Private $debug;
Private $_logcallback;
Public $login _user; Current login user, call Get_login_info after get
/**
* Read Cookie cache content
* @param string $filename cache file name
* @return A string cookie
*/
Public Function GetCookie ($filename) {
if (file_exists ($filename)) {
$mtime = Filemtime ($filename);
if ($mtime <time ()-$this->_cookieexpired) return false;
$data = file_get_contents ($filename);
if ($data) $this->cookie = $data;
}
return $this->cookie;
}
/*
* Delete Cookies
*/
Public Function Deletecookie ($filename) {
$this->cookie = ";
@unlink ($filename);
return true;
}
Private function log ($log) {
if ($this->debug && function_exists ($this->_logcallback)) {
if (Is_array ($log)) $log = Print_r ($log, true);
Return Call_user_func ($this->_logcallback, $log);
}
}
/**
* Get Authorization code for login QR code
*/
Public Function Get_login_code () {
if ($this->_logincode) return $this->_logincode;
$t = Time (). Strval (Mt_rand (100,999));
$codeurl = ' https://login.weixin.qq.com/jslogin?appid=wx782c26e4c19acffb&redirect_uri=https%3A%2F% 2fwx.qq.com%2fcgi-bin%2fmmwebwx-bin%2fwebwxnewloginpage&fun=new&lang=zh_cn&_= '. $t;
$send _snoopy = new Snoopy;
$send _snoopy->fetch ($codeurl);
$result = $send _snoopy->results;
if ($result) {
Preg_match ("/window. Qrlogin.uuids+=s+ "([^"]+) "/", $result, $matches);
if (count ($matches) >1) {
$this->_logincode = $matches [1];
$_session[' login_step '] = 0;
return $this->_logincode;
}
}
return $result;
}
/**
* Obtain the corresponding QR code image address by authorization code
* @param string $code
* @return string Image URL
*/
Public Function get_code_image ($code = ") {
if ($code = = ") $code = $this->_logincode;
if (! $code) return false;
Return ' http://login.weixin.qq.com/qrcode/'. $this->_logincode. '? T=webwx ';
}
/**
* Set the authorization code corresponding to the QR code
* @param string $code
* @return Class $this
*/
Public Function Set_login_code ($code) {
$this->_logincode = $code;
return $this;
}
/**
* QR Code Login Verification
*
* @return Status:
* >=400:invaild code; 408:not Auth and wait, 400,401:not valid or expired
* 201:just scaned but not confirm
* 200:confirm then you can get user info
*/
Public Function Verify_code () {
if (! $this->_logincode) return false;
$t = Time (). Strval (Mt_rand (100,999));
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.