Controller.php
1.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace app\products\controller;
use app\common\controller\ProductsController;
/**
* 功能描述 换取access_token
* Class Controller
* @package app\products\controller
* Date: 2020/7/14
* Time: 16:06
* @author gxd
*/
class Controller extends ProductsController
{
protected $appid = "";
protected $appsecret = "";
public function _initialize()
{
parent::_initialize(); // TODO: Change the autogenerated stub
$this->appid = config("appid");
$this->appsecret = config("appsecret");
$this->allOrigin();
}
public function allOrigin() {
header('Content-Type: text/html;charset=utf-8');
header('Access-Control-Allow-Origin:*'); // *代表允许任何网址请求
header('Access-Control-Allow-Methods:POST,GET,OPTIONS,DELETE'); // 允许请求的类型
header('Access-Control-Allow-Credentials: true'); // 设置是否允许发送 cookies
header('Access-Control-Allow-Headers: Content-Type,Content-Length,Accept-Encoding,X-Requested-with, Origin');
}
}