作者 赵彬吉

Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6 into develop

... ... @@ -152,9 +152,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'];
}
... ... @@ -173,25 +181,16 @@ class LoginController extends BaseController
$message = simplexml_load_string($message, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NOERROR);
$jsonData = json_encode($message);
$arrayData = json_decode($jsonData, true);
$data = $this->wechatLogin($arrayData['ToUserName']);
@file_put_contents(storage_path('logs/lyh_error.log'), var_export($data, true) . PHP_EOL, FILE_APPEND);
$data = $this->setWechat($arrayData['ToUserName'],$arrayData['EventKey']);
if($data['code'] == 0){//登录失败,请先绑定
$resMessage = $data['message'];
}else{
}elseif($data['code'] == 1){
$resMessage = $data['message'];
$info = $data['data'];
Cache::add($arrayData['Ticket'],$info,300);
}else{
$resMessage = $data['message'];
}
@file_put_contents(storage_path('logs/lyh_error.log'), var_export($resMessage, true) . PHP_EOL, FILE_APPEND);
// $arr = [
// 'ToUserName' => 'gh_27174ac5c9d8',
// 'FromUserName' => 'oMbcI6gRzvfrU8ssGsEyvzXOO94w',
// 'CreateTime' => '1693385898',
// 'MsgType' => 'event',
// 'Event' => 'subscribe',
// 'EventKey' => 'qrscene_global-v6_v6',
// 'Ticket' => 'gQF27zwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAyWnppdHhWTlRjOEcxTlBpTE5BY2IAAgRjBO9kAwQQDgAA',
// ];
return "<xml>
<ToUserName><![CDATA[$message->FromUserName]]></ToUserName>
<FromUserName><![CDATA[$message->ToUserName]]></FromUserName>
... ... @@ -246,93 +245,18 @@ 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'=>0,
'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']]);
$data = [
'code'=>1,
'message'=>'登陆成功',
'data'=>$info
];
public function setWechat($wechat,$eventKey){
$userLoginLogic = new UserLoginLogic();
$key = explode("_",$eventKey);
@file_put_contents(storage_path('logs/lyh_error.log'), var_export($key, true) . PHP_EOL, FILE_APPEND);
if($key[1] == 'login'){
$data = $userLoginLogic->wechatLogin($wechat);
}else{
$data = $userLoginLogic->wechatBind($wechat,$key[2]);
}
return $data;
}
public function ceshi(){
$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'],'develop.globalso.com','ecdn6.globalso.com');
$html = $this->re($v['html'],'develop.globalso.com','ecdn6.globalso.com');
}
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);
}
}
}
$templateModel->edit(['html'=>$html],['id'=>$v['id']]);
}
}
}
... ...
... ... @@ -10,6 +10,7 @@ use App\Models\Project\Project;
use App\Models\Sms\SmsLog;
use App\Models\User\ProjectRole as ProjectRoleModel;
use App\Models\User\User;
use App\Models\User\User as UserModel;
use Illuminate\Support\Facades\Cache;
class UserLoginLogic
... ... @@ -203,6 +204,70 @@ class UserLoginLogic
}
return $this->success($info);
}
/**
* @remark :扫码登录
* @name :wechatLogin
* @author :lyh
* @method :post
* @time :2023/9/1 11:29
*/
public function wechatLogin($wechat){
$info = $this->model->read(['wechat'=>$wechat]);
if($info === false){
$data = [
'code'=>0,
'message'=>'当前用户未绑定账户,请绑定后登录',
];
}else {
//获取项目详情
$info = $this->autoAssembleParam($info);
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']]);
$data = [
'code'=>1,
'message'=>'登陆成功',
'data'=>$info
];
}
return $this->success($data);
}
/**
* @remark :微信绑定
* @name :wechatBind
* @author :lyh
* @method :post
* @time :2023/9/1 11:43
*/
public function wechatBind($wechat,$id){
$info = $this->model->read(['wechat'=>$wechat]);
if($info !== false){
$data = [
'code'=>0,
'message'=>'当前微信已绑定其他微信,请解绑后再操作',
];
}else{
if(!empty($id)){
$this->model->edit(['wechat'=>$wechat],['id'=>$id]);
}
$data = [
'code'=>2,
'message'=>'绑定成功',
];
}
return $this->success($data);
}
/**
* @notes: 请简要描述方法功能
* @param array $data
... ...