167 lines
7.8 KiB
PHP
167 lines
7.8 KiB
PHP
<?php
|
||
/**
|
||
* 云贝餐饮连锁V2版权说明:
|
||
|
||
******************************************************************
|
||
|
||
《云贝餐饮连锁V2》是武汉云贝网络科技有限公司历经2余年时间独立创作开发而成,且在不断的进行升级开发中,《云贝餐饮连锁V2 》的源代码、布局、界面设计、电子文档等均已提交国家版权局登记备案,并已获得著作权审批 和销售许可 (软著登字第 6839058号 登记号 2021SR0114741)。
|
||
|
||
官方网址为:www.b-ke.cn
|
||
|
||
官方联系方式:153-0719-3890(王经理)
|
||
|
||
******************************************************************
|
||
|
||
注意:本软件非开源系统,版权归武汉云贝网络科技有限公司依法所有,并受到法律的严格保护;未经过我司授权,不得擅自二开、破解、倒卖等任何的侵权、盗版行为均将追究其法律责任。
|
||
*/
|
||
namespace app\controllers\channel;
|
||
use Illuminate\Support\Facades\DB;
|
||
use Yii;
|
||
use yii\web\Controller;
|
||
use app\models\common\CallbackOrder;
|
||
use app\models\common\Good;
|
||
class CloudController extends Controller{
|
||
//网站激活
|
||
public function actionCheckAuth(){
|
||
echo json_encode(['code'=>1,'msg'=>'网站已激活','type'=>1]);die;
|
||
//echo json_encode(['code'=>2,'msg'=>'站点授权失败,请联系管理员处理!','type'=>2]);die;
|
||
$request = Yii::$app->request;
|
||
$userData=$_SESSION['userInfo'];
|
||
if(Yii::$app->request->hostInfo!="https://bkycms.com"){
|
||
if(!$userData){
|
||
if(Yii::$app->params['isDev']==true){
|
||
echo json_encode(['code'=>1,'msg'=>'请先登录','data'=>Yii::$app->request->hostInfo,'type'=>3]);die;
|
||
}else{
|
||
echo json_encode(['code'=>1,'msg'=>'请先登录','data'=>'/login','type'=>4]);die;
|
||
}
|
||
}
|
||
}
|
||
if ($request->isPost){
|
||
$result=axios_request();
|
||
$domainUrl=Yii::$app->request->hostInfo;
|
||
$domainUrl = preg_replace("(^https?://)", "", $domainUrl);
|
||
$data=array(
|
||
'domain_url'=>$domainUrl,
|
||
'auth_code'=>trim($result['auth_code']),
|
||
'ip'=>gethostbyname($_SERVER['SERVER_NAME']),
|
||
'auth_type'=>$result['auth_type']?:1,
|
||
);
|
||
$fileData=file_get_contents('./web/secret.json');
|
||
$jsonData=json_decode(ybwmDecrypt($fileData,Yii::$app->params['channel_model_name']),true);
|
||
//dd($jsonData);die;
|
||
if($domainUrl=='bkycms.com' or $domainUrl=='v2.bkycms.com'){
|
||
$domainUrl=$jsonData['domain_url'];
|
||
}
|
||
if($jsonData['authData']&&$jsonData['status']==1&&$jsonData['domain_url']==$domainUrl){
|
||
$sessionInfo=Yii::$app->session->get('userInfo');
|
||
if($sessionInfo['loginType']==2&&$sessionInfo['type']==3){
|
||
$authType=2;
|
||
}else{
|
||
$authType=1;
|
||
}
|
||
echo json_encode(['code'=>1,'msg'=>'网站已激活','type'=>1,'authType'=>$authType]);die;
|
||
}elseif($result['auth_code']){
|
||
$url=Yii::$app->params['domain_url'].'/cloud/auth/checkAuth';
|
||
$result=httpRequest($url,$data);
|
||
$row=json_decode($result,true);
|
||
if($row['code']==1&&$row['type']==1){
|
||
echo json_encode(['code'=>1,'msg'=>'网站已激活','type'=>1]);die;
|
||
}else{
|
||
$authData=$row['authData'];
|
||
if($authData){
|
||
//var_dump($authData);die;
|
||
$row=ybwmEncrypt(json_encode($authData),Yii::$app->params['channel_model_name']);
|
||
touch('./web/secret.json');
|
||
chmod('./web/secret.json',0777);
|
||
if (!is_writable ('./web/secret.json')) {
|
||
echo json_encode(['code'=>2,'msg'=>'证书文件/web/secret.json无写入权限','type'=>2]);die;
|
||
}
|
||
file_put_contents('./web/secret.json',$row);
|
||
echo json_encode(['code'=>1,'msg'=>'网站已激活','type'=>1]);die;
|
||
}else{
|
||
echo json_encode(['code'=>2,'msg'=>'站点授权失败,请联系管理员处理!','type'=>2]);die;
|
||
}
|
||
}
|
||
|
||
}else{
|
||
$url=Yii::$app->params['domain_url'].'/cloud/auth/checkAuth';
|
||
$result=httpRequest($url,$data);
|
||
$row=json_decode($result,true);
|
||
if($row['code']==1&&$row['type']==1){
|
||
echo json_encode(['code'=>1,'msg'=>'网站已激活','type'=>1]);die;
|
||
}else{
|
||
$authData=$row['authData'];
|
||
if($authData){
|
||
//var_dump($authData);die;
|
||
$row=ybwmEncrypt(json_encode($authData),Yii::$app->params['channel_model_name']);
|
||
touch('./web/secret.json');
|
||
chmod('./web/secret.json',0777);
|
||
file_put_contents('./web/secret.json',$row);
|
||
echo json_encode(['code'=>1,'msg'=>'网站已激活','type'=>1]);die;
|
||
}else{
|
||
echo json_encode(['code'=>1,'msg'=>'网站未激活','type'=>2]);die;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
//获取授权信息
|
||
public function actionGetAuthInfo(){
|
||
$request = Yii::$app->request;
|
||
if ($request->isPost){
|
||
$domainUrl=Yii::$app->request->hostInfo;
|
||
$domainUrl= preg_replace("(^https?://)", "",$domainUrl);
|
||
$fileData=file_get_contents('./web/secret.json');
|
||
$jsonData=json_decode(ybwmDecrypt($fileData,Yii::$app->params['channel_model_name']),true);
|
||
if($domainUrl=='bkycms.com' or $domainUrl=='v2.bkycms.com'){
|
||
$domainUrl=$jsonData['domain_url'];
|
||
}
|
||
if($jsonData['authData']&&$jsonData['domain_url']==$domainUrl){
|
||
$jsonData['ip_address']=gethostbyname($_SERVER['SERVER_NAME']);
|
||
echo json_encode(['code'=>1,'msg'=>'成功','data'=>$jsonData]);die;
|
||
}else{
|
||
echo json_encode(['code'=>2,'msg'=>'网站未激活或已停用']);die;
|
||
}
|
||
}
|
||
}
|
||
//网站更新授权信息
|
||
public function actionAuthUp(){
|
||
$domainUrl=Yii::$app->request->hostInfo;
|
||
$data=array(
|
||
'domain_url'=>$domainUrl,
|
||
'ip'=>gethostbyname($_SERVER['SERVER_NAME']),
|
||
);
|
||
$url=Yii::$app->params['domain_url'].'/cloud/auth/authUp';
|
||
$result=httpRequest($url,$data);
|
||
$authData=json_decode($result,true)['authData'];
|
||
//var_dump($result);die;
|
||
if($authData){
|
||
//var_dump($authData);die;
|
||
$row=ybwmEncrypt(json_encode($authData),Yii::$app->params['channel_model_name']);
|
||
touch('./web/secret.json');
|
||
chmod('./web/secret.json',0777);
|
||
file_put_contents('./web/secret.json',$row);
|
||
echo json_encode(['code'=>1,'msg'=>'网站已更新授权','type'=>1]);die;
|
||
}else{
|
||
echo json_encode(['code'=>1,'msg'=>'网站授权更新失败','type'=>2]);die;
|
||
}
|
||
|
||
|
||
}
|
||
|
||
//返回站点信息
|
||
public function actionReturnVersion(){
|
||
$fileData=file_get_contents('./web/secret.json');
|
||
$jsonData=json_decode(ybwmDecrypt($fileData,Yii::$app->params['channel_model_name']),true);
|
||
$auth_code=$jsonData['auth_code'];
|
||
dd($jsonData);die;
|
||
$domain_url=$jsonData['domain_url'];
|
||
$domainUrl=Yii::$app->request->hostInfo;
|
||
$domainUrl= preg_replace("(^https?://)", "",$domainUrl);
|
||
if($domain_url!==$domainUrl){
|
||
var_dump($domain_url);
|
||
var_dump($domainUrl);
|
||
}
|
||
}
|
||
} |