Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

CI framework development Sina Weibo login interface source code writing tutorial

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "CI framework development Sina Weibo login interface source code preparation tutorial", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn the "CI framework development Sina Weibo login interface source code preparation tutorial" it!

First, let's take a look at the process:

Process principle:

1. Obtain access_token authorization through code, and obtain user information (including user u_id) (this u_id is called sina_id in the following third-party login form, which needs to be built by yourself)

two。 To query the third-party login form, if there is no user sina_id, there are two situations: one: if the user already has an account on the platform, you need to bind the platform (for example, the user table of the platform is: user_reg) to the user id of the third-party login form (for example, the third_login table), and then let the customer log in.

Second, the user does not have an account on the platform and jumps to the registration page to register. At the same time, the information is written to the uer_reg table and the user sina_id is written to the third-party login table for binding.

3. Query the third-party login form (third_login). If there is a user sina_id, query the user table (user_reg). If the mailbox has been activated, log in directly. If not, prompt the user to go to the mailbox to activate the account.

Let's start with the steps:

Step 1: apply for App key and App secret Application address: http://open.weibo.com/ click on the website to access WEB on the page, and then go in to apply. After passing the application, you will get App Key and App Secret as follows:

App Key:1428003339

App Sercet:f1c6177a38b39f764c76a1690720a6dc

Callback address: http://test.com/callback.php

Description: after applying down, your Sina account is a test account. You can use this account to debug when you are developing. Other accounts cannot log in and cannot return information. Before development, it is best to go to the official website to take a look at the development process, which is the most important. As long as the train of thought is clear, the rest is to use code to achieve what you want.

Step 2: download SDK, download php version, download address (official website): http://code.google.com/p/libweibo/downloads/list, download there are 5 files, one of which is saetv2.ex.class.php, I only need this file.

Step 3: code

1. Create a third-party login form to store third-party login information (Sina is openid QQ, they are all unique, used to identify users, and we store them according to this):

The copy code is as follows:

CREATE TABLE IF NOT EXISTS `third_ login` (

`user_ id` INT (6) NOT NULL

`sina_ id` BIGINT (16) NULL

`qq_ id` varchar (64) NULL

PRIMARY KEY (`user_ id`)

UNIQUE INDEX `user_id_ Unique` (`user_ id` ASC)

INDEX `sina_ id` (`sina_ id` ASC)

INDEX `index4` (`index4` ASC))

ENGINE = MyISAM

DEFAULT CHARACTER SET = utf8

COLLATE = utf8_bin

COMMENT = 'third party login form'

Note: the platform returns u_id, which is the unique identity of the user. I save it as sina_id,user_id, which is the id of the platform user table user_reg. I do not list the user_reg table here. You can build the table according to the actual project requirements. The recommended operation tool is phpmyadmin,MySQL Workbench, which is easy to operate.

If you only need to do the Sina login interface, you can remove the qq_id field.

two。 Write the configuration file, create a new file sina_conf.php under application, and write in the newly applied App Key and App Secret. The code is as follows:

The copy code is as follows:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report