|
|
@ -3,6 +3,7 @@ |
|
|
namespace App\Http\Controllers\Api; |
|
|
namespace App\Http\Controllers\Api; |
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller; |
|
|
use App\Http\Controllers\Controller; |
|
|
|
|
|
use App\Models\AdminSetting; |
|
|
use App\Models\Agent; |
|
|
use App\Models\Agent; |
|
|
use App\Models\Channel; |
|
|
use App\Models\Channel; |
|
|
use App\Models\User; |
|
|
use App\Models\User; |
|
|
@ -34,12 +35,25 @@ class LoginController extends Controller |
|
|
return $this->error('code参数缺失'); |
|
|
return $this->error('code参数缺失'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$config = config('wechat.mini_program.default'); |
|
|
|
|
|
$config = array_merge($config, [ |
|
|
|
|
|
'app_id' => $agent['appid'], |
|
|
|
|
|
'secret' => $agent['appsecret'], |
|
|
|
|
|
]); |
|
|
|
|
|
$app = Factory::miniProgram($config); |
|
|
|
|
|
|
|
|
// 如果有appsecret,使用原来的登录逻辑,否则使用第三方登录逻辑
|
|
|
|
|
|
if ($agent['appsecret']) { |
|
|
|
|
|
$config = config('wechat.mini_program.default'); |
|
|
|
|
|
$config = array_merge($config, [ |
|
|
|
|
|
'app_id' => $agent['appid'], |
|
|
|
|
|
'secret' => $agent['appsecret'], |
|
|
|
|
|
]); |
|
|
|
|
|
$app = Factory::miniProgram($config); |
|
|
|
|
|
} else { |
|
|
|
|
|
$setting = AdminSetting::val(['service_appid', 'service_appsecret', 'service_token', 'service_aeskey']); |
|
|
|
|
|
$config = [ |
|
|
|
|
|
'app_id' => $setting['service_appid'], |
|
|
|
|
|
'secret' => $setting['service_appsecret'], |
|
|
|
|
|
'token' => $setting['service_token'], |
|
|
|
|
|
'aes_key' => $setting['service_aeskey'], |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
$app = Factory::openPlatform($config); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
$res = $app->auth->session($code); |
|
|
$res = $app->auth->session($code); |
|
|
@ -72,11 +86,8 @@ class LoginController extends Controller |
|
|
$channel_ids = Channel::where([ |
|
|
$channel_ids = Channel::where([ |
|
|
['agent_id', '=', $this->agent_id], |
|
|
['agent_id', '=', $this->agent_id], |
|
|
['pid', '<>', 0], |
|
|
['pid', '<>', 0], |
|
|
]) |
|
|
|
|
|
->orderBy('id') |
|
|
|
|
|
->limit(8) |
|
|
|
|
|
->pluck('id') |
|
|
|
|
|
->toArray(); |
|
|
|
|
|
|
|
|
])->orderBy('id')->limit(8)->pluck('id')->toArray(); |
|
|
|
|
|
|
|
|
//存入user_channel
|
|
|
//存入user_channel
|
|
|
UserChannel::where('user_id', $userModel->id) |
|
|
UserChannel::where('user_id', $userModel->id) |
|
|
->insert([ |
|
|
->insert([ |
|
|
|