url ?? ''; $scopes = $request->scopes ?? ['snsapi_userinfo']; $web_url = config('user.web.base'); $redirect = $web_url.$pages; if (! is_array($scopes)) { $scopes = [$scopes]; } $response = $app->oauth->scopes($scopes)->redirect($redirect); return $this->success($response); } /** * Notes: 获取jssdk * * @Author: 玄尘 * @Date : 2021/7/1 11:08 * @param Request $request * @return JsonResponse */ public function getJsSdk(Request $request) { $url = $request->url; $jsApiList = $request->jsApiList ?? []; $openTagList = $request->openTagList ?? []; $app = app('wechat.official_account'); if ($url) { $app->jssdk->setUrl($url); } if (! is_array($jsApiList)) { $jsApiList = [$jsApiList]; } if (! is_array($openTagList)) { $openTagList = [$openTagList]; } return $this->success($app->jssdk->buildConfig($jsApiList, false, false, true, $openTagList)); } /** * Notes: 微信分享 * * @Author: 玄尘 * @Date : 2021/10/26 16:52 * @param Request $request * @return JsonResponse|mixed * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException * @throws \GuzzleHttp\Exception\GuzzleException * @throws \Psr\SimpleCache\InvalidArgumentException */ public function officialShare(Request $request) { $url = $request->url ?? ''; if (empty($url)) { return $this->failed('地址必须传'); } $app = app('wechat.official_account'); $apis = [ 'updateAppMessageShareData', 'updateTimelineShareData', // 'showOptionMenu', // 'showMenuItems', 'showAllNonBaseMenuItem', ]; $app->jssdk->setUrl($url); $cog = $app->jssdk->buildConfig($apis); return $this->success($cog); } /** * Notes: 获取小程序openid * * @Author: 玄尘 * @Date: 2022/9/26 14:17 * @return mixed|void */ public function getMiniOpenid(Request $request) { $validator = \Validator::make($request->all(), [ 'code' => 'required', ], [ 'code.required' => '缺少参数:code', ]); if ($validator->fails()) { return $this->failed($validator->errors()->first()); } $weChat = app('wechat.mini_program'); $session = $weChat->auth->session($request->code); if (isset($session->errcode)) { return $this->failed($session->errmsg); } return $this->success($session->openid); } /** * Notes: 获取公众号openid * * @Author: 玄尘 * @Date: 2022/9/26 14:21 */ public function getOfficialOpenid() { try { $weUser = $this->getUserFromCode(); return $this->success([ 'openid' => $weUser->getId() ]); } catch (\Exception $exception) { return $this->failed($exception->getMessage()); } } }