1
This commit is contained in:
parent
a04c5359ec
commit
4af9aa38f9
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace app;
|
namespace app;
|
||||||
|
|
||||||
use think\App;
|
use think\App;
|
||||||
@ -37,11 +38,11 @@ abstract class BaseController
|
|||||||
/**
|
/**
|
||||||
* 构造方法
|
* 构造方法
|
||||||
* @access public
|
* @access public
|
||||||
* @param App $app 应用对象
|
* @param App $app 应用对象
|
||||||
*/
|
*/
|
||||||
public function __construct(App $app)
|
public function __construct(App $app)
|
||||||
{
|
{
|
||||||
$this->app = $app;
|
$this->app = $app;
|
||||||
$this->request = $this->app->request;
|
$this->request = $this->app->request;
|
||||||
|
|
||||||
// 控制器初始化
|
// 控制器初始化
|
||||||
@ -50,15 +51,23 @@ abstract class BaseController
|
|||||||
|
|
||||||
// 初始化
|
// 初始化
|
||||||
protected function initialize()
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证数据
|
* 验证数据
|
||||||
* @access protected
|
* @access protected
|
||||||
* @param array $data 数据
|
* @param array $data 数据
|
||||||
* @param string|array $validate 验证器名或者验证规则数组
|
* @param string|array $validate 验证器名或者验证规则数组
|
||||||
* @param array $message 提示信息
|
* @param array $message 提示信息
|
||||||
* @param bool $batch 是否批量验证
|
* @param bool $batch 是否批量验证
|
||||||
* @return array|string|true
|
* @return array|string|true
|
||||||
* @throws ValidateException
|
* @throws ValidateException
|
||||||
*/
|
*/
|
||||||
@ -73,7 +82,7 @@ abstract class BaseController
|
|||||||
[$validate, $scene] = explode('.', $validate);
|
[$validate, $scene] = explode('.', $validate);
|
||||||
}
|
}
|
||||||
$class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);
|
$class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);
|
||||||
$v = new $class();
|
$v = new $class();
|
||||||
if (!empty($scene)) {
|
if (!empty($scene)) {
|
||||||
$v->scene($scene);
|
$v->scene($scene);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -174,7 +174,12 @@ class User extends Controller
|
|||||||
public function wxCode()
|
public function wxCode()
|
||||||
{
|
{
|
||||||
$appid = 'wx89c12dd426a55a2e';
|
$appid = 'wx89c12dd426a55a2e';
|
||||||
|
|
||||||
|
|
||||||
$redirect_uri = $this->request->host() . 'api/food.user/wxLogin';
|
$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";
|
$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, '成功');
|
return $this->renderSuccess($url, '成功');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1819,7 +1819,7 @@ class Driver
|
|||||||
$result = json_decode(Http::get($url), true);
|
$result = json_decode(Http::get($url), true);
|
||||||
if (isset($result['access_token'])) {
|
if (isset($result['access_token'])) {
|
||||||
$access_token = $result['access_token'];
|
$access_token = $result['access_token'];
|
||||||
Cache::set($key, $access_token, 3600);
|
Cache::set($key, $access_token, 7200);
|
||||||
return $access_token;
|
return $access_token;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user