<?php
namespace App\Http\Controllers\WX;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Throwable;
use Exception;
use Carbon\Carbon;
use Illuminate\Validation\Rule;
use App\Models\UserExtra;
use App\Models\User;
use App\Services\UtilService;

class HomeController extends Controller
{
    private $time;

    public function __construct()
    {
        $this->time = Carbon::now()->format('Y-m-d H:i:s');
    }

    /**
     * 验证微信token
     * @return array
     * @date 2021/05/28
     * @author live
     */
    public function getVerityWX(Request $request){
        $postData = $request->all();
        $echoStr = $postData['echostr'] ?? '';
        if($echoStr == ''){
            echo '未接到随机字符串';
            exit();
        }
        echo $echoStr;
        exit();
        $signature = $postData['signature'] ?? '';
        $timestamp = $postData['timestamp'] ?? '';
        $nonce = $postData['nonce'] ?? '';
        $token = 'srccwl2021';
        $tmpArr = array($token, $timestamp, $nonce);
        sort($tmpArr, SORT_STRING);
        $tmpStr = implode($tmpArr);
        $tmpStr = sha1($tmpStr);
        if ($tmpStr == $signature) {
            echo $echoStr;
            exit();
        } else {
            echo '验证未通过';
            exit();
        }
    }


}