微信公众号开发文档
https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1445241432
接口测试号申请
https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421137522
URL和Token
url地址 这里需要自己有服务器,没有服务器的可以使用内网穿透工具 如下:
https://u.tools/
Token验证代码
//1. 将timestamp , nonce , token 按照字典排序
$timestamp = $_GET['timestamp'];
$nonce = $_GET['nonce'];
$token = "ceshi";#你自定义的Token值 用于验证
$signature = $_GET['signature'];
$array = array($timestamp,$nonce,$token);
sort($array);
//2.将排序后的三个参数拼接后用sha1加密
$tmpstr = implode('',$array);
$tmpstr = sha1($tmpstr);
//3. 将加密后的字符串与 signature 进行对比, 判断该请求是否来自微信
if($tmpstr == $signature)
{
echo $_GET['echostr'];
exit;
}
网页授权登录
授权登录代码demo
使用了composer包
地址:https://packagist.org/packages/yurunsoft/yurun-oauth-login
index.php
<?php
require 'vendor/autoload.php';
use Yurun\OAuthLogin\Weixin;
session_start();
$obj = new Weixin\OAuth2('wxcd9aec1397657647','8d31cb9e1645abbac90327ef757508ec','http://zouzhanhao.utools.club/callback.php');
$url = $obj->getWeixinAuthUrl();
$_SESSION['YURUN_QQ_STATE'] = $obj->state;
header('location:' . $url);
callback.php
<?php
require 'vendor/autoload.php';
use Yurun\OAuthLogin\Weixin;
session_start();
$obj = new Weixin\OAuth2('wxcd9aec1397657647','8d31cb9e1645abbac90327ef757508ec','http://zouzhanhao.utools.club/callback.php');
$data = $obj->getAccessToken($_SESSION['YURUN_QQ_STATE'],$_GET['code'],$_GET['state']);
$userInfo = $obj->getUserInfo();
$openid = $obj->openid;
var_dump($userInfo);
微信web开发者工具
https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1455784140
可以很方便的在pc上输入网址进行调试