diff --git a/app/BaseController.php b/app/BaseController.php index 5ef6495..c18ff80 100755 --- a/app/BaseController.php +++ b/app/BaseController.php @@ -1,4 +1,5 @@ app = $app; + $this->app = $app; $this->request = $this->app->request; // 控制器初始化 @@ -50,15 +51,23 @@ 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); + } /** * 验证数据 * @access protected - * @param array $data 数据 - * @param string|array $validate 验证器名或者验证规则数组 - * @param array $message 提示信息 - * @param bool $batch 是否批量验证 + * @param array $data 数据 + * @param string|array $validate 验证器名或者验证规则数组 + * @param array $message 提示信息 + * @param bool $batch 是否批量验证 * @return array|string|true * @throws ValidateException */ @@ -73,7 +82,7 @@ abstract class BaseController [$validate, $scene] = explode('.', $validate); } $class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate); - $v = new $class(); + $v = new $class(); if (!empty($scene)) { $v->scene($scene); } diff --git a/app/api/controller/food/User.php b/app/api/controller/food/User.php index ee0c895..24fe0ec 100644 --- a/app/api/controller/food/User.php +++ b/app/api/controller/food/User.php @@ -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, '成功'); } diff --git a/extend/hema/wechat/Driver.php b/extend/hema/wechat/Driver.php index ce19cac..1bbb607 100755 --- a/extend/hema/wechat/Driver.php +++ b/extend/hema/wechat/Driver.php @@ -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; } }