|
...
|
...
|
@@ -12,20 +12,23 @@ namespace App\Http\Controllers\Bside; |
|
|
|
use App\Enums\Common\Code;
|
|
|
|
use App\Events\WebSocketMessage;
|
|
|
|
use App\Events\WebSocketMessageSent;
|
|
|
|
use App\Helper\Arr;
|
|
|
|
use App\Helper\Common;
|
|
|
|
use App\Helper\Socket;
|
|
|
|
use App\Helper\Translate;
|
|
|
|
use App\Helper\Wechat;
|
|
|
|
use App\Http\Logic\Bside\User\UserLogic;
|
|
|
|
use App\Http\Logic\Bside\User\UserLoginLogic;
|
|
|
|
use App\Models\File\Image;
|
|
|
|
use App\Models\File\Image as ImageModel;
|
|
|
|
use App\Models\Project\Project;
|
|
|
|
use App\Models\Service\Service;
|
|
|
|
use App\Models\Sms\SmsLog;
|
|
|
|
use App\Models\Template\Template;
|
|
|
|
use App\Models\Template\TemplateModule;
|
|
|
|
use App\Models\User\DeptUser;
|
|
|
|
use App\Models\User\ProjectRole;
|
|
|
|
use App\Models\User\User;
|
|
|
|
use App\Models\User\User as UserModel;
|
|
|
|
use App\Utils\EncryptUtils;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use \Illuminate\Support\Facades\Cache;
|
|
|
|
use Mrgoon\AliSms\AliSms;
|
|
|
|
|
|
...
|
...
|
@@ -152,9 +155,17 @@ class LoginController extends BaseController |
|
|
|
* @time :2023/8/23 18:46
|
|
|
|
*/
|
|
|
|
public function qrcode(){
|
|
|
|
$this->request->validate([
|
|
|
|
'type' => 'required',
|
|
|
|
],[
|
|
|
|
'type.required' => '请选择项目',
|
|
|
|
]);
|
|
|
|
if(!isset($this->param['id'])){
|
|
|
|
$this->param['id'] = 0;
|
|
|
|
}
|
|
|
|
$wechat = new Wechat();
|
|
|
|
$accessToken = $wechat->getAccessToken();
|
|
|
|
$data = $wechat->setQrcode('global-v6',$accessToken);
|
|
|
|
$data = $wechat->setQrcode('global-v6_'.$this->param['type'].'_'.$this->param['id'],$accessToken);
|
|
|
|
if(!empty($data)){
|
|
|
|
$data['url'] = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=".$data['ticket'];
|
|
|
|
}
|
|
...
|
...
|
@@ -171,27 +182,44 @@ class LoginController extends BaseController |
|
|
|
public function eventMessage(){
|
|
|
|
$message = file_get_contents("php://input");
|
|
|
|
$message = simplexml_load_string($message, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NOERROR);
|
|
|
|
$data = $this->wechatLogin($message->FromUserName);
|
|
|
|
$socket = new Socket();
|
|
|
|
$socket->socket(json_encode($data));
|
|
|
|
$arr = [
|
|
|
|
'ToUserName' => 'gh_27174ac5c9d8',
|
|
|
|
'FromUserName' => 'oMbcI6gRzvfrU8ssGsEyvzXOO94w',
|
|
|
|
'CreateTime' => '1693385898',
|
|
|
|
'MsgType' => 'event',
|
|
|
|
'Event' => 'subscribe',
|
|
|
|
'EventKey' => 'qrscene_global-v6_v6',
|
|
|
|
'Ticket' => 'gQF27zwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAyWnppdHhWTlRjOEcxTlBpTE5BY2IAAgRjBO9kAwQQDgAA',
|
|
|
|
];
|
|
|
|
$jsonData = json_encode($message);
|
|
|
|
$arrayData = json_decode($jsonData, true);
|
|
|
|
$data = $this->setWechat($arrayData['ToUserName'],$arrayData['EventKey']);
|
|
|
|
if($data['code'] == 0){//登录失败,请先绑定
|
|
|
|
$resMessage = $data['message'];
|
|
|
|
}elseif($data['code'] == 1){
|
|
|
|
$resMessage = $data['message'];
|
|
|
|
}elseif($data['code'] == 2){
|
|
|
|
$resMessage = $data['message'];
|
|
|
|
}else{
|
|
|
|
$resMessage = $data['message'];
|
|
|
|
}
|
|
|
|
Cache::add($arrayData['Ticket'],$data,300);
|
|
|
|
return "<xml>
|
|
|
|
<ToUserName><![CDATA[$message->FromUserName]]></ToUserName>
|
|
|
|
<FromUserName><![CDATA[$message->ToUserName]]></FromUserName>
|
|
|
|
<CreateTime>".time()."</CreateTime>
|
|
|
|
<MsgType><![CDATA[text]]></MsgType>
|
|
|
|
<Content><![CDATA[扫码成功了]]></Content>
|
|
|
|
<Content><![CDATA[$resMessage]]></Content>
|
|
|
|
</xml>";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :登录成功响应
|
|
|
|
* @name :getWechatLoginInfo
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/9/1 10:12
|
|
|
|
*/
|
|
|
|
public function getWechatLoginInfo(){
|
|
|
|
$this->request->validate([
|
|
|
|
'ticket' => 'required',
|
|
|
|
],[
|
|
|
|
'ticket.required' => 'ticket不能为空',
|
|
|
|
]);
|
|
|
|
$info = Cache::get($this->param['ticket']);
|
|
|
|
$this->response('success',Code::SUCCESS,$info);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :解token
|
|
...
|
...
|
@@ -202,19 +230,45 @@ class LoginController extends BaseController |
|
|
|
*/
|
|
|
|
public function globalSo_v6_login(UserLoginLogic $logic){
|
|
|
|
$common = new Common();
|
|
|
|
$arr = $common->decrypt($this->param['token']);
|
|
|
|
$arr = $common->decrypt(urldecode($this->param['token']));
|
|
|
|
if(empty($arr)){
|
|
|
|
$this->response('登录失败',Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
$userModel = new UserModel();
|
|
|
|
$info = $userModel->read(['mobile'=>$arr['phone']]);
|
|
|
|
if($info === false){
|
|
|
|
$this->response('当前用户不存在请联系管理员',Code::USER_ERROR);
|
|
|
|
//没有from_order_id的项目 进入演示版 运营中心
|
|
|
|
$arr['from_order_id'] = 0;
|
|
|
|
if(!$arr['from_order_id']){
|
|
|
|
//有账号就直接登录, 没有账号创建账号登录
|
|
|
|
$user = (new User())->where('project_id', Project::DEMO_PROJECT_ID)->where('mobile', $arr['phone'])->first();
|
|
|
|
if(!$user){
|
|
|
|
$user = new User();
|
|
|
|
$user->project_id = Project::DEMO_PROJECT_ID;
|
|
|
|
$user->role_id = ProjectRole::OPERATION_CENTER_ID;
|
|
|
|
$user->mobile = $arr['phone'];
|
|
|
|
$user->password = base64_encode(md5('v6.' . substr($arr['phone'], -6)));
|
|
|
|
$user->name = $arr['name'] ?? $arr['phone'];
|
|
|
|
$user->save();
|
|
|
|
//运营中心组织
|
|
|
|
$dept_user = new DeptUser();
|
|
|
|
$dept_user->dept_id = DeptUser::OPERATION_CENTER_ID;
|
|
|
|
$dept_user->project_id = Project::DEMO_PROJECT_ID;
|
|
|
|
$dept_user->user_id = $user->id;
|
|
|
|
$dept_user->save();
|
|
|
|
}
|
|
|
|
$data = [
|
|
|
|
'user_id'=>$user['id'],
|
|
|
|
'manager_id'=>0,
|
|
|
|
];
|
|
|
|
}else{
|
|
|
|
//有from_order_id, 找到对应的项目并登录主账号
|
|
|
|
$project = (new Project())->read(['from_order_id'=>$arr['from_order_id']]);
|
|
|
|
if(!$project){
|
|
|
|
$this->response('项目不存在,请联系管理员',Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
$data = [
|
|
|
|
'project_id'=>$project['id'],
|
|
|
|
'manager_id'=>0,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
$data = [
|
|
|
|
'user_id'=>$info['id'],
|
|
|
|
'manager_id'=>0,
|
|
|
|
];
|
|
|
|
$info = $logic->autologin($data);
|
|
|
|
$this->response('success',Code::SUCCESS,['info'=>$info]);
|
|
|
|
}
|
|
...
|
...
|
@@ -226,96 +280,37 @@ class LoginController extends BaseController |
|
|
|
* @method :post
|
|
|
|
* @time :2023/8/31 9:13
|
|
|
|
*/
|
|
|
|
public function wechatLogin($wechat){
|
|
|
|
//查看当前账户是否绑定
|
|
|
|
$userModel = new UserModel();
|
|
|
|
$info = $userModel->read(['wechat'=>$wechat]);
|
|
|
|
if($info === false){
|
|
|
|
$data = [
|
|
|
|
'code'=>Code::USER_LOGIN_ERROE,
|
|
|
|
'message'=>'当前用户未绑定账户,请绑定后',
|
|
|
|
];
|
|
|
|
}else {
|
|
|
|
//获取项目详情
|
|
|
|
$info = $this->assembleParam($info['mobile'],$info['project_id']);
|
|
|
|
if(isset($info['token']) && !empty($info['token'])){
|
|
|
|
//清除上一次用户缓存
|
|
|
|
Cache::pull($info['token']);
|
|
|
|
}
|
|
|
|
//生成新token
|
|
|
|
$token = md5(uniqid().$info['id']);
|
|
|
|
//存储缓存
|
|
|
|
$info['token'] = $token;
|
|
|
|
Cache::add($token,$info,3600);
|
|
|
|
//更新用户信息
|
|
|
|
$this->model->edit(['token'=>$token],['id'=>$info['id']]);
|
|
|
|
public function setWechat($wechat,$eventKey){
|
|
|
|
$userLoginLogic = new UserLoginLogic();
|
|
|
|
$key = explode("_",$eventKey);
|
|
|
|
if($key[1] == 'login'){
|
|
|
|
$data = $userLoginLogic->wechatLogin($wechat);
|
|
|
|
}elseif($key[1] == 'bind'){
|
|
|
|
$data = $userLoginLogic->wechatBind($wechat,$key[2]);
|
|
|
|
}else{
|
|
|
|
$data = [
|
|
|
|
'code'=>Code::SUCCESS,
|
|
|
|
'message'=>'当前用户未绑定账户,请绑定后',
|
|
|
|
'data'=>$info
|
|
|
|
'code'=>0,
|
|
|
|
'message'=>'关注成功,请登录后绑定账号后扫码,如已绑定,请再次扫码',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ceshi(){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function daoru(){
|
|
|
|
$templateModel = new Template();
|
|
|
|
$list = $templateModel->list();
|
|
|
|
foreach ($list as $k => $v){
|
|
|
|
preg_match_all('/\(https:\/\/admin.item.globalso.site\/a\/image\/(.*?)\)/', $v['html'], $matches);
|
|
|
|
if (!empty($matches[1])) {
|
|
|
|
$srcValues = $matches[1];
|
|
|
|
$imageModel = new Image();
|
|
|
|
$html = $v['html'];
|
|
|
|
foreach ($srcValues as $srcValue) {
|
|
|
|
$image_info = $imageModel->read(['hash' => $srcValue]);
|
|
|
|
if ($image_info !== false) {
|
|
|
|
$path = $image_info['path'];
|
|
|
|
$html = $this->re($html, '/a/image/'.$srcValue, $path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$templateModel->edit(['html'=>$html],['id'=>$v['id']]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function re(&$html,$srcValue,$path){
|
|
|
|
$html = str_replace(
|
|
|
|
$srcValue,
|
|
|
|
$path,
|
|
|
|
$html
|
|
|
|
);
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function updateHtml(){
|
|
|
|
$html = $this->re($v['html'],'https://develop.globalso.com/a/image/','https://ecdn6.globalso.com/public/template/');
|
|
|
|
$html = $this->re($v['html'],'https://develop.globalso.com/b/image/','https://ecdn6.globalso.com/public/template/');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function updateCe(){
|
|
|
|
$templateModel = new TemplateModule();
|
|
|
|
$list = [];
|
|
|
|
foreach ($list as $k => $v){
|
|
|
|
preg_match_all('/\"https:\/\/develop.globalso.com\/a\/image\/(.*?)\"/', $v['html'], $matches);
|
|
|
|
if (!empty($matches[1])) {
|
|
|
|
$srcValues = $matches[1];
|
|
|
|
$imageModel = new Image();
|
|
|
|
$html = $v['html'];
|
|
|
|
foreach ($srcValues as $srcValue) {
|
|
|
|
$image_info = $imageModel->read(['hash' => $srcValue]);
|
|
|
|
if ($image_info !== false) {
|
|
|
|
$path = basename($image_info['path']);
|
|
|
|
$html = $this->re($html, $srcValue, $path);
|
|
|
|
}
|
|
|
|
$list = $templateModel->list();
|
|
|
|
$imageModel = new ImageModel();
|
|
|
|
foreach ($list as $k=>$v){
|
|
|
|
if (strpos($v['image'], '.') !== false) {
|
|
|
|
$v['image'] = '/upload'.$v['image'];
|
|
|
|
}else{
|
|
|
|
$info = $imageModel->read(['hash'=>$v['image']]);
|
|
|
|
if($info !== false){
|
|
|
|
$v['image'] = $info['path'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$templateModel->edit(['html'=>$html],['id'=>$v['id']]);
|
|
|
|
$templateModel->edit(['image'=>$v['image']],['id'=>$v['id']]);
|
|
|
|
}
|
|
|
|
$this->response('success');
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|