Table of Contents
回复内容:
Home Backend Development PHP Tutorial 微信开发 微信扫描登陆

微信开发 微信扫描登陆

Jun 06, 2016 pm 08:38 PM
php WeChat Micro-channel public platform

网站中集成微信扫描登陆 直接使用微信账号登陆 减去注册 登陆麻烦只需要微信扫描二维码登陆,有哪位小伙伴 遇到这样类似的需要 类似的场景吗??

给一个网站的例子链接(非广告推广..)微信扫码登陆

回复内容:

网站中集成微信扫描登陆 直接使用微信账号登陆 减去注册 登陆麻烦只需要微信扫描二维码登陆,有哪位小伙伴 遇到这样类似的需要 类似的场景吗??

给一个网站的例子链接(非广告推广..)微信扫码登陆

我已经做了一个简单的封装的api。通过微信的网页授权获取用户信息,来实现登录、验证、注册等功能。但是这个网页授权获取用户基本信息,需要认证过的服务号才能具备此功能,手中刚好有一个,就用来做了一个API,可以供大家一起使用。

这个API的具体逻辑就是,网站在登陆页面上显示内容为A链接的二维码,引导用户使用微信扫描该二维码。A链接的格式应当为:https://wenfan.cn/wechat/api.php?token=xxxxxx&key=xxxxxx。这个链接包括 token和tkey两个变量,前者用于识别用户是否已经扫描该页面,后者用于双向验证交换信息;

用户如果使用其他工具打开这个链接,是不会有任何反应的,只有在微信中扫描才会有所反应;

用户在微信中扫描以后,首先会验证APIKEY是否存在,如果存在则获取callback回调地址。然后会继续向微信平台请求得到用户的唯一openid(程序会对openid进行一次加密,防止有人通过其他手段获得微信用户原始openid后进行攻击,确保得到的openid的绝对唯一性),得到openid以后,程序将token和openid以及APIKEY、secret四个变量通过POST方式传递给callback回调地址;

callback回调地址收到上述参数后,对APIKEY和secret进行验证(防止有人直接向callback地址进行POST),然后将token和openid写入数据库;

checkstatus.php?token=xxxxxx 是用来判断该token是否已经和openid组对写入了数据库中,如果数据库中存在了这个token,并且配对有一个openid,则说明用户已经扫码;

前端index.php通过轮询checkstatus.php,来获取数据库中是否存在这个token的状态,每隔3秒轮询一次,如果发现该token已存在于数据库中,则开始执行跳转(或者其他动作,比如写入session等等),至此,整个流程已经完成。

具体部署方法如下:

1、在本站申请一个API KEY:Wechat Scan Login API,请尽量勿使用QQ邮箱注册,可能收不到验证链接;
2、点击邮件验证链接以后,登陆后台可以得到一个API KEY;
3、下载DEMO.ZIP [https://wenfan.cn/wechat/demo.zip];
4、修改config.php里面的数据库连接信息;
5、在数据库里建立一个名称为“wechat”的表,必须至少包含两个字段:token 和 user。前者用来记录临时token,后者用来记录微信用户唯一id;
6、修改callback.php和index.php里对应的API KEY值以及secret值,改成第一步自己得到的API KEY和secret;
7、将文件上传至服务器,在第一步的API KEY信息后台,将callback.php的地址填入。
[可选]:根据自己的需求,优化二维码样式,及设定扫描成功后的动作代码。获取到的微信用户id为唯一id,所以该扫描登陆具备较强的唯一性,可以用来注册或者登陆,或者人机验证(代替验证码)。

[点击查看LIVE DEMO]

好吧 又是自问自答 发布问题后 问了一下 在腾讯工作的朋友.....然后得到了 如下链接

微信文档 无力吐槽...

实例

这个实现现在很多网站都加了……

如果有一个认证了的服务号可以自己做的。

生成带参数二维码。

1、在微信开放平台注册(open.weixin.qq.com)
2、申请开发者认证
3、认证后,即可使用微信登录功能,支持app web

去微信开入平台注册申请开发者,完了添加应用,添加完之后设置 callback ,扫码之后会跳转到你的 callback (并带上 code),通过 code 去换取 openid 和 accessToken。

在本站申请一个API KEY:Wechat Scan Login API
这个 KEY 怎么得到?

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP's Purpose: Building Dynamic Websites PHP's Purpose: Building Dynamic Websites Apr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

The Future of PHP: Adaptations and Innovations The Future of PHP: Adaptations and Innovations Apr 11, 2025 am 12:01 AM

The future of PHP will be achieved by adapting to new technology trends and introducing innovative features: 1) Adapting to cloud computing, containerization and microservice architectures, supporting Docker and Kubernetes; 2) introducing JIT compilers and enumeration types to improve performance and data processing efficiency; 3) Continuously optimize performance and promote best practices.

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

See all articles