|
@@ -4,6 +4,7 @@ namespace Modules\Channel\Http\Controllers;
|
|
|
|
|
|
use Catch\Base\CatchController;
|
|
use Catch\Base\CatchController;
|
|
use EasyWeChat\OpenPlatform\Application;
|
|
use EasyWeChat\OpenPlatform\Application;
|
|
|
|
+use Illuminate\Foundation\Validation\ValidatesRequests;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Redis;
|
|
use Illuminate\Support\Facades\Redis;
|
|
@@ -17,16 +18,21 @@ use Symfony\Component\Cache\Adapter\RedisAdapter;
|
|
class WechatOpenPlatformController extends CatchController
|
|
class WechatOpenPlatformController extends CatchController
|
|
{
|
|
{
|
|
use UserTrait;
|
|
use UserTrait;
|
|
|
|
+ use ValidatesRequests;
|
|
// 授权跳转页
|
|
// 授权跳转页
|
|
public function preauth(Request $request) {
|
|
public function preauth(Request $request) {
|
|
|
|
+ $this->validate($request, [
|
|
|
|
+ 'user_id' => 'required'
|
|
|
|
+ ]);
|
|
$currentUser = $this->getCurrentUser();
|
|
$currentUser = $this->getCurrentUser();
|
|
- $componentInfo = WechatOpenPlatformService::getComponentInfoByCompanyUid($currentUser->pid);
|
|
|
|
|
|
+ $componentInfo = WechatOpenPlatformService::getComponentInfoByCompanyUid($currentUser->id);
|
|
$app = WechatOpenPlatformService::buildApplication($componentInfo);
|
|
$app = WechatOpenPlatformService::buildApplication($componentInfo);
|
|
- $url = $app->createPreAuthorizationUrl(url('/api/channel/openPlatform/auth/'.$componentInfo->app_id), []);
|
|
|
|
|
|
+ $user_id = $request->input('user_id');
|
|
|
|
+ $url = $app->createPreAuthorizationUrl(url('/api/channel/openPlatform/auth/'.$componentInfo->app_id.'/'.$user_id), []);
|
|
return $url;
|
|
return $url;
|
|
}
|
|
}
|
|
|
|
|
|
- public function auth(Request $request, $component_appid) {
|
|
|
|
|
|
+ public function auth(Request $request, $component_appid, $user_id) {
|
|
$auth_code = $request->input('auth_code');
|
|
$auth_code = $request->input('auth_code');
|
|
$componentInfo = WechatOpenPlatformService::getComponentInfoByAppid($component_appid);
|
|
$componentInfo = WechatOpenPlatformService::getComponentInfoByAppid($component_appid);
|
|
$app = WechatOpenPlatformService::buildApplication($componentInfo);
|
|
$app = WechatOpenPlatformService::buildApplication($componentInfo);
|
|
@@ -41,8 +47,8 @@ class WechatOpenPlatformController extends CatchController
|
|
WechatAuthorizationInfo::updateOrCreate([
|
|
WechatAuthorizationInfo::updateOrCreate([
|
|
'authorizer_appid' => $authorizer_appid,
|
|
'authorizer_appid' => $authorizer_appid,
|
|
'component_appid' => $component_appid,
|
|
'component_appid' => $component_appid,
|
|
- 'user_id' => $currentUser->id,
|
|
|
|
- 'puser_id' => $currentUser->pid,
|
|
|
|
|
|
+ 'user_id' => $user_id,
|
|
|
|
+ 'puser_id' => $currentUser->id,
|
|
], [
|
|
], [
|
|
'authorizer_refresh_token' => $authorizer_refresh_token
|
|
'authorizer_refresh_token' => $authorizer_refresh_token
|
|
]);
|
|
]);
|