1:到公众号后台绑定自己得一个回调地址 域名/gongzhong/wxtoken ,验证成功后添加绑定成功,记得把有的验证关掉
2:前端需要写一个检测得是否登录没有,可以用每秒去请求url检测一次,域名/gongzhong/isloged 来检测是否扫码登录,触发wxtoken没有(序列号1)
3:把从微信公众号获取到信息保存到了数据库后,openid检测 或者用unionid
<?php
namespace App\Http\Controllers\Web\Gznumber;
use App\Events\LoginEvent;
use App\Services\Common\User\UserAccountService;
use App\Services\Web\BaseService;
use GuzzleHttp\Utils;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
use App\Exceptions\Common\CaptchaException;
use App\Services\Common\SmsService;
use App\Services\Web\CacheService;
use App\Libraries\Verification\Sms;
use Illuminate\Support\Str;
use Illuminate\Foundation\Auth\User;
use App\Services\Common\Auth\LoginService;
define('TOKEN', 'TOKEN');
class GznumberController extends Controller
{
const ERROR_TIMES = 5;
const SEND_TIMES = 5;
const EXPIRE_TIME = 300;
protected $appid = 'wx2929f30b2bcf14d4';
protected $secret = 'c7cb108d79245d57eeb5f3bf8924897a';
//测试号
/*protected $appid = 'wx2929f30b2bcf14d4';
protected $secret = 'c7cb108d79245d57eeb5f3bf8924897a';*/
/**
* 自定义方法,用于微信访问验证开发者身份
*
* @param Request $request
* @return array|null|string
*/
public function wxtoken(Request $request)
{
// 验证消息来自微信服务器
if($request->method()=='GET'){
$signature = $request->input('signature');
$timestamp = $request->input('timestamp');
$nonce = $request->input('nonce');
$echoStr = $request->input('echostr');
if ($this->checkSignature($signature, $timestamp, $nonce)) {
ob_end_clean(); //必须清空缓冲区
return $echoStr;
} else {
return 'Token verification failed.';
}
} elseif ($request->method()=='POST') {
// 事件处理 关注/取消事件等
$postStr = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : file_get_contents("php://input");
$payChannel='yyyyyy';
file_put_contents(
storage_path('logs/'. $payChannel .'.log'),
'[' . date('Y-m-d H:i:s') . '] ' . Utils::jsonEncode($postStr) . PHP_EOL,
FILE_APPEND
);