dongxing4196
2019-03-05 09:52
浏览 238

Laravel 5.6如何重定向到移动应用程序URL?

I am having difficulties to implement a redirect with Laravel 5.6 to a mobile app url. So the idea is that API handles a request and based on user agent it redirects to either android or ios app.

Controller

/**
* Reset password redirect logic.
* Redirect user to either android or iphone app based on http user agent.
*
* @param RedirectRequest $request
* @return RedirectResponse
*/
public function redirect(RedirectRequest $request): RedirectResponse
{
    $email = $request->get('email');
    $rememberToken = $request->get('rememberToken');
    $userAgent = $request->server('HTTP_USER_AGENT');

    if (strpos(strtolower( $userAgent ), 'iphone' ) !== false) {
        return redirect()->to(
            env('FORGET_PASSWORD_IOS_URL') . '?$email=' . $email . '&rememberToken=' . $rememberToken
        );
    } else if (strpos(strtolower( $userAgent ), 'android' ) !== false) {
        return redirect()->to(
            env('FORGET_PASSWORD_ANDROID_URL') . '?$email=' . $email . '&rememberToken=' . $rememberToken
        );
    }
}

.env

# URL SCHEMA FROM MOBILE APP DEVELOPERS.
FORGET_PASSWORD_IOS_URL=mobileapp://
FORGET_PASSWORD_ANDROID_URL=mobileapp://

So the idea behind this, is that when a user requests a password reset from the mobile app, they get an email and that email will contain a link to api. Once user visits a link, they will be redirected to either android or ios app to continue.

The link user receives in email looks like this. http://api.url.com/password-reset?email=<email>&rememberToken=<TOKEN>

After user visits the url I expect the result to be in the browser.

mobileapp://?email=me@email.com&rememberToken=<TOKEN>

The actual result.

http://api.url.com/mobileapp:?email=me@email.com&rememberToken=<TOKEN>

Anyone encountered this before? Or any advices?

图片转代码服务由CSDN问答提供 功能建议

我很难用 Laravel 5.6 实现重定向到移动应用网址。 因此, API 处理请求并基于用户代理重定向到 android ios app。 \ n

控制器

  / ** 
 *重置密码重定向逻辑。
 *基于http用户代理将用户重定向到android或iphone应用程序。  n * 
 * @param RedirectRequest $ request 
 * @return RedirectResponse 
 * / 
 npublic function redirect(RedirectRequest $ request):RedirectResponse 
 {
 $ email = $ request-&gt; get('email')  ; 
 $ rememberToken = $ request-&gt; get('rememberToken'); 
 $ userAgent = $ request-&gt; server('HTTP_USER_AGENT'); 
 
 if(strpos(strtolower($ userAgent),'  iphone')!== false){
返回redirect() - &gt;到(
 env('FORGET_PASSWORD_IOS_URL')。'?$ email ='。$ email。'&amp; rememberToken ='。$ rememberToken 
  ); 
}否则if(strpos(strto。)  lower($ userAgent),'android')!== false){
 return redirect() - &gt; to(
 env('FORGET_PASSWORD_ANDROID_URL')。  '?$ email ='。  $ email。  '&amp; rememberToken ='。  $ rememberToken 
); 
} 
} 
   
 
 

.env

  #URL SCHEMA FROM MOBILE  APP开发者。
 
NFORGET_PASSWORD_IOS_URL = mobileapp:// 
FORGET_PASSWORD_ANDROID_URL = mobileapp:// 
   
 
 

因此,这背后的想法是当用户请求密码重置时 移动应用程序,他们收到一封电子邮件,该电子邮件将包含api的链接。 一旦用户访问链接,他们将被重定向到android或ios应用程序以继续。

用户在电子邮件中收到的链接如下所示。 http://api.url.com/password-reset?email=<email>&rememberToken=<TOKEN>

用户访问后 url我希望结果在浏览器中。

mobileapp://?email = me@email.com&amp; rememberToken =&lt; TOKEN&gt;

实际结果。

http://api.url.com/mobileapp:?email=me@email.com&rememberToken= &lt; TOKEN&gt;

以前有人遇到过这个吗? 或者任何建议?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doudao0660 2019-03-05 10:05

    you should use this method:

    $url = env('FORGET_PASSWORD_IOS_URL') . '?$email=' . $email . '&rememberToken=' . $rememberToken;
    
    return redirect()->away($url);
    
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题