IndexController.php
2.1 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
namespace app\ht\modules\device\controllers;
use Yii;
use yii\filters\AccessControl;
use app\ht\controllers\BaseController;
use domain\trade\RepairOrderChannel;
use function strpos;
use function in_array;
use function header;
class IndexController extends BaseController
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['index', 'error'],
'allow' => true,
//'roles' => ['?'],
],
],
],
];
}
// 默认检测是否为钉钉浏览器
public function actionIndex()
{
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$serverName = $_SERVER['SERVER_NAME'];
$req = Yii::$app->request;
$channel = $req->get('channel');
$number = $req->get('number');
if (false === strpos($serverName, 'jiwork.com')) {
$params = array('msg' => "二维码不是OTA设备二维码");
return $this->renderPartial('index',$params);
}
if (!in_array($channel, [RepairOrderChannel::REPAIR_CHANNEL_SCAN, RepairOrderChannel::REPAIR_CHANNEL_HOME_SCAN]) || empty($number)) {
$params = array('msg' => "二维码有误");
return $this->renderPartial('index', $params);
}
if (false !== strpos($user_agent,'DingTalk') && false !== strpos($user_agent,'alibaba')) {
// 钉钉浏览器
$site_url = Yii::$app->params['DINGTALKL_URL'];
// 这个应该从后台的配置数据里面获取,但是由于历史原因,二维码上的url和后台配置可能出现不一致,所以先写到配置里面
header('Location: ' . $site_url . 'site/index#view-device/scan/' . $number . '/0/0?showmenu=false');
exit;
}
$params = array('msg' => "当前应用只支持钉钉和微信小程序");
return $this->renderPartial('index', $params);
}
}