This commit is contained in:
尖叫 2023-12-08 14:42:43 +08:00
parent a04c5359ec
commit 4af9aa38f9
3 changed files with 23 additions and 9 deletions

View File

@ -1,4 +1,5 @@
<?php
namespace app;
use think\App;
@ -50,7 +51,15 @@ abstract class BaseController
// 初始化
protected function initialize()
{}
{
$allowOrigin = Request::header('origin');
$allowHeaders = 'X-Requested-With, Content-Type, Authorization';
$allowMethods = 'GET, POST, PUT, DELETE, PATCH, OPTIONS';
header("Access-Control-Allow-Origin: " . $allowOrigin);
header("Access-Control-Allow-Headers: " . $allowHeaders);
header("Access-Control-Allow-Methods: " . $allowMethods);
}
/**
* 验证数据

View File

@ -174,7 +174,12 @@ class User extends Controller
public function wxCode()
{
$appid = 'wx89c12dd426a55a2e';
$redirect_uri = $this->request->host() . 'api/food.user/wxLogin';
$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri={$redirect_uri}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
return $this->renderSuccess($url, '成功');
}

View File

@ -1819,7 +1819,7 @@ class Driver
$result = json_decode(Http::get($url), true);
if (isset($result['access_token'])) {
$access_token = $result['access_token'];
Cache::set($key, $access_token, 3600);
Cache::set($key, $access_token, 7200);
return $access_token;
}
}