WeChat development Limit page can only be opened in WeChat how to implement?

Source: Internet
Author: User
Recently in the development, but has been ignoring a problem how to restrict the page to open only in?

In PHP scripts, you can determine whether the browser is a built-in browser by judging Http_user_agent

But today, watching the pudding move under the micro-car public platform Many page restrictions can only be opened in the method should not be judged by the script in the browser's header information, now ask the micro-car limit page only open in the browser idea is what?

Reply content:

Recently in the development, but has been ignoring a problem how to restrict the page to open only in?

In PHP scripts, you can determine whether the browser is a built-in browser by judging Http_user_agent

But today, watching the pudding move under the micro-car public platform Many page restrictions can only be opened in the method should not be judged by the script in the browser's header information, now ask the micro-car limit page only open in the browser idea is what?

There will be micromessenger in the open navigator.useragent.

OAuth2.0 Authorization for the micro-car call

There are many built-in JS built-in APIs that can be used to determine if these APIs exist.
Http://www.baidufe.com/item/f07a3be0b23b4c9606bb.html

I am now doing the project, is the public number, users click on our site, will go to the server to obtain user OpenID, if not obtained, it is not open browser. So that users can enter the system only when the browser is opened

It's basically all answered.

1, JS or program judgment, useragent, whether it contains Micromessenger

2. js to judge the relevant specific functions

3, call the OAuth interface, if you do not want user-aware, you can call the Scope=snsapi_base way, this finally can only get user OpenID. Scope=snsapi_userinfo mode, the user will see an authorization page, click on the authorization, you can get all the user information.

The front end is best not to use UA to determine whether it is a built-in browser, because it is too easy to forge.
So to judge

if( typeof WeixinJSBridge !== "undefined" ) {  return true;}

Web page with open must have to do oauth page authorization?

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.