Sina, Tencent, Taobao login_PHP tutorial
You can use it directly
<?<span php </span><span session_start</span><span (); </span><span class</span><span openlogin{ </span><span public</span> <span $_URL</span> = ""<span ; </span><span public</span> <span $config</span> = <span array</span><span (); </span><span public</span> <span function</span><span __construct(){ </span><span $this</span>-><span openlogin(); } </span><span function</span><span openlogin(){ } </span><span /*</span><span 获取登陆页面URL</span><span */</span> <span public</span> <span function</span><span login_url(){ </span><span if</span>(<span empty</span>(<span $this</span>-><span config)){ </span><span return</span> <span false</span><span ; } </span><span $config</span> = <span $this</span>-><span config; </span><span $login_url</span> = <span $config</span>['login_url'<span ]; </span><span $_SESSION</span>['state'] = <span $state</span> = <span md5</span>(<span uniqid</span>(<span rand</span>(), <span TRUE</span><span )); </span><span $array</span> = <span array</span><span ( </span>"response_type"=>"code", "state" => <span $state</span>, "client_id"=><span $config</span>['appkey'], "redirect_uri"=><span urlencode</span>( <span $config</span>['redirect_uri'<span ] ) ); </span><span $this</span>->set(<span $array</span><span ); </span><span $url</span> = <span $this</span>->combineURL(<span $login_url</span> , <span $this</span>-><span _param); </span><span if</span>(<span $url</span><span ){ @</span><span header</span>("Location:".<span $url</span><span ); }</span><span else</span><span { </span><span return</span> <span false</span><span ; } } </span><span /*</span><span 获取access_token</span><span */</span> <span public</span> <span function</span><span get_access_token(){ </span><span if</span>(<span empty</span>(<span $this</span>-><span config)){ </span><span return</span> <span false</span><span ; } </span><span $config</span> = <span $this</span>-><span config; </span><span if</span>(! <span $config</span>['code'] = <span $_REQUEST</span>['code'<span ] ){ </span><span return</span> <span false</span><span ; } </span><span $url</span> = <span $config</span>['authorization_url'<span ]; </span><span $state</span> = <span $_SESSION</span>['state'<span ]; </span><span $array</span> = <span array</span><span ( </span>"grant_type"=>"authorization_code", "client_id" => <span $config</span>['appkey'], "client_secret"=><span $config</span>['appsecret'], "code"=><span $config</span>['code'], "redirect_uri"=><span urlencode</span>( <span $config</span>['redirect_uri'] ), "state"=><span $state</span><span ); </span><span $this</span>->set(<span $array</span><span ); </span><span return</span> <span $this</span>->post_contents(<span $url</span><span ); } </span><span /*</span><span set $this->_param 数组</span><span */</span> <span public</span> <span function</span> set(<span $array</span><span ) { </span><span if</span>(<span empty</span>(<span $array</span><span )){ </span><span return</span> <span false</span><span ; } </span><span $this</span>->_param = <span array</span><span (); </span><span foreach</span>(<span $array</span> <span as</span> <span $name</span>=><span $value</span><span ){ </span><span $this</span>->_param[<span $name</span>] = <span $value</span><span ; } } </span><span /*</span><span * * post_contents * 服务器通过post请求获得内容 * @param string $url 请求的url,拼接后的 * @return string 请求返回的内容 </span><span */</span> <span public</span> <span function</span> post_contents(<span $url</span><span ){ </span><span if</span>(<span empty</span>(<span $url</span><span )){ </span><span return</span> <span false</span><span ; } </span><span $param</span> = <span $this</span>->combineURL("" , <span $this</span>-><span _param); </span><span $ch</span> =<span curl_init(); </span><span //</span><span 设置URL和相应的选项</span> curl_setopt(<span $ch</span>, CURLOPT_URL, <span $url</span><span ); curl_setopt(</span><span $ch</span>, CURLOPT_FAILONERROR, <span false</span><span ); curl_setopt(</span><span $ch</span>, CURLOPT_RETURNTRANSFER, <span true</span><span ); curl_setopt (</span><span $ch</span>, CURLOPT_SSL_VERIFYPEER, 0<span ); curl_setopt (</span><span $ch</span>, CURLOPT_SSL_VERIFYHOST, 0<span ); curl_setopt(</span><span $ch</span>, CURLOPT_POST, 1<span ); curl_setopt(</span><span $ch</span>, CURLOPT_POSTFIELDS, <span $param</span><span ); </span><span //</span><span 抓取URL并把它传递给浏览器</span> <span $reponse</span> = curl_exec(<span $ch</span><span ); curl_close(</span><span $ch</span><span ); </span><span return</span> <span $reponse</span><span ; } </span><span /*</span><span * * get_contents * 服务器通过get请求获得内容 * @param string $url 请求的url,拼接后的 * @return string 请求返回的内容 </span><span */</span> <span public</span> <span function</span> get_contents(<span $url</span><span ){ </span><span $ch</span> =<span curl_init(); curl_setopt(</span><span $ch</span>, CURLOPT_SSL_VERIFYPEER, <span FALSE</span><span ); curl_setopt(</span><span $ch</span>, CURLOPT_RETURNTRANSFER, <span TRUE</span><span ); curl_setopt(</span><span $ch</span>, CURLOPT_URL, <span $url</span><span ); </span><span $response</span> = curl_exec(<span $ch</span><span ); curl_close(</span><span $ch</span><span ); </span><span //</span><span -------请求为空</span> <span if</span>(<span empty</span>(<span $response</span><span )){ </span><span return</span> <span false</span><span ; } </span><span return</span> <span $response</span><span ; } </span><span /*</span><span * * combineURL * 拼接url * @param string $baseURL 基于的url * @param array $keysArr 参数列表数组 * @return string 返回拼接的url </span><span */</span> <span public</span> <span function</span> combineURL(<span $baseURL</span>,<span $keysArr</span><span ){ </span><span if</span>( <span $baseURL</span>==""<span ){ </span><span $combined</span> = ""<span ; }</span><span else</span><span { </span><span $combined</span> = <span $baseURL</span>."?"<span ; } </span><span $valueArr</span> = <span array</span><span (); </span><span foreach</span>(<span $keysArr</span> <span as</span> <span $key</span> => <span $val</span><span ){ </span><span $valueArr</span>[] = "<span $key</span>=<span $val</span>"<span ; } </span><span $keyStr</span> = <span implode</span>("&",<span $valueArr</span><span ); </span><span $combined</span> .= (<span $keyStr</span><span ); </span><span return</span> <span $combined</span><span ; } } </span><span class</span> qq_openlogin <span extends</span><span openlogin{ </span><span private</span> <span $openname</span> = "qq"<span ; </span><span public</span> <span $config</span> = <span array</span><span ( </span>"appkey"=>"your appkey", "appsecret"=>"your appsecret", "redirect_uri"=>"XXXXX", "login_url" => "https://graph.qq.com/oauth2.0/authorize", "scope"=>"get_user_info,add_share,list_album,add_album,upload_pic,add_topic,add_one_blog,add_weibo,check_page_fans,add_t,add_pic_t,del_t,get_repost_list,get_info,get_other_info,get_fanslist,get_idolist,add_idol,del_idol,get_tenpay_addr", "authorization_url"=>"https://graph.qq.com/oauth2.0/token"<span ); </span><span function</span><span __construct() { </span><span $this</span>-><span qq_openlogin(); } </span><span function</span><span qq_openlogin(){ parent</span>::<span __construct(); } </span><span function</span><span get_access_token(){ </span><span $response</span> = parent::<span get_access_token(); </span><span /*</span><span 检测错误是否发生</span><span */</span> <span if</span>(<span strpos</span>(<span $response</span>, "callback") !== <span false</span><span ){ </span><span $lpos</span> = <span strpos</span>(<span $response</span>, "("<span ); </span><span $rpos</span> = <span strrpos</span>(<span $response</span>, ")"<span ); </span><span $response</span> = <span substr</span>(<span $response</span>, <span $lpos</span> + 1, <span $rpos</span> - <span $lpos</span> -1<span ); </span><span $msg</span> = json_decode(<span $response</span><span ); </span><span if</span>(<span isset</span>(<span $msg</span>-><span error)){ </span><span return</span> <span false</span><span ; } } </span><span $params</span> = <span array</span><span (); </span><span parse_str</span>(<span $response</span>, <span $params</span><span ); </span><span /*</span><span access_token == $params[access_token]</span><span */</span> <span /*</span><span 获取 openid </span><span */</span> <span $response</span> = <span $this</span>->get_contents("https://graph.qq.com/oauth2.0/me?access_token=".<span $params</span>['access_token'<span ]); </span><span //</span><span --------检测错误是否发生</span> <span if</span>(<span strpos</span>(<span $response</span>, "callback") !== <span false</span><span ){ </span><span $lpos</span> = <span strpos</span>(<span $response</span>, "("<span ); </span><span $rpos</span> = <span strrpos</span>(<span $response</span>, ")"<span ); </span><span $response</span> = <span substr</span>(<span $response</span>, <span $lpos</span> + 1, <span $rpos</span> - <span $lpos</span> -1<span ); } </span><span $user</span> = json_decode(<span $response</span><span ); </span><span if</span>(<span isset</span>(<span $user</span>-><span error)){ </span><span return</span> <span false</span><span ; } </span><span /*</span><span 获取用户信息需要参数:openid(用户的ID,与QQ号码一一对应),access_token(可通过使用Authorization_Code获取Access_Token 或来获取access_token有3个月有效期),oauth_consumer_key(用户appid),format(返回格式) </span><span */</span> <span /*</span><span 数据库保存</span><span */</span> <span $open_param</span> = <span array</span><span ( </span>"openid"=><span $user</span>->openid, "access_token"=><span $params</span>['access_token'<span ] ); </span><span // </span> <span $open_param</span>['oauth_consumer_key'] = <span $this</span>->config['appkey'<span ]; </span><span $open_param</span>['format'] = "json"<span ; </span><span /*</span><span 拼接url</span><span */</span> <span $get_user_url</span> = <span $this</span>->combineURL("https://graph.qq.com/user/get_user_info",<span $open_param</span><span ); </span><span //</span><span 猎取用户信息</span> <span $userinfo</span> = <span $this</span>->get_contents(<span $get_user_url</span><span ); </span><span $userinfo</span> = json_decode(<span $userinfo</span><span ); </span><span return</span> <span $userinfo</span><span ; } } </span><span class</span> weibo_openlogin <span extends</span><span openlogin{ </span><span private</span> <span $openname</span> = "weibo"<span ; </span><span public</span> <span $config</span> = <span array</span><span ( </span>"appkey"=>"your appkey", "appsecret"=>"your appsecret", "login_url" => "https://api.weibo.com/oauth2/authorize", "redirect_uri"=>"XXXXXXX", "authorization_url"=>"https://api.weibo.com/oauth2/access_token"<span ); </span><span function</span><span __construct() { </span><span $this</span>-><span qq_openlogin(); } </span><span function</span><span qq_openlogin(){ parent</span>::<span __construct(); } </span><span function</span><span get_access_token(){ </span><span $response</span> = parent::<span get_access_token(); </span><span $userinfo</span> = json_decode(<span $response</span><span ); </span><span return</span> <span $userinfo</span><span ; } } </span><span class</span> taobao_openlogin <span extends</span><span openlogin{ </span><span private</span> <span $openname</span> = "taobao"<span ; </span><span public</span> <span $config</span> = <span array</span><span ( </span>"appkey"=>"your appkey", "appsecret"=>"your appsecret", "redirect_uri"=>"XXXXX", "authorization_url"=>"https://oauth.taobao.com/token", "login_url"=>"https://oauth.taobao.com/authorize"<span ); </span><span function</span><span __construct() { </span><span $this</span>-><span qq_openlogin(); } </span><span function</span><span qq_openlogin(){ parent</span>::<span __construct(); } </span><span function</span><span get_access_token(){ </span><span $response</span> = parent::<span get_access_token(); </span><span $userinfo</span> = json_decode(<span $response</span><span ); </span><span return</span> <span $userinfo</span><span ; } } </span><span if</span>(<span $_GET</span>['openname'<span ]){ </span><span $openname</span> = <span $_GET</span>['openname']."_openlogin"<span ; </span><span $openlogin</span> = <span new</span> <span $openname</span><span (); </span><span if</span>(!<span isset</span>(<span $_REQUEST</span>['code'<span ])){ </span><span //</span><span 请求url</span> <span $url</span> = <span $openlogin</span>-><span login_url(); </span><span if</span>(!<span $url</span><span ){ </span><span echo</span> "0"<span ; </span><span exit</span><span (); } }</span><span else</span><span { </span><span if</span>(<span isset</span>(<span $_REQUEST</span>["state"]) && (<span $_SESSION</span>['state'] != <span $_REQUEST</span>["state"<span ] )){ </span><span echo</span> "1"<span ; </span><span exit</span><span (); } </span><span $rs</span> = <span $openlogin</span>-><span get_access_token(); </span><span print_r</span>( <span $rs</span><span ); } } </span>?>
Add a Renren login
<span class</span> renren_openlogin <span extends</span><span openlogin{ </span><span private</span> <span $openname</span> = "renren"<span ; </span><span public</span> <span $config</span> = <span array</span><span ( </span>"appid"=>"your appid", "appkey"=>"your appkey", "appsecret"=>"your secret key", "redirect_uri"=>"XXXXXX", "authorization_url"=>"https://graph.renren.com/oauth/token", "login_url"=>"https://graph.renren.com/oauth/authorize"<span ); </span><span function</span><span __construct() { </span><span $this</span>-><span qq_openlogin(); } </span><span function</span><span qq_openlogin(){ parent</span>::<span __construct(); } </span><span function</span><span get_access_token(){ </span><span $response</span> = parent::<span get_access_token(); </span><span $userinfo</span> = json_decode(<span $response</span><span ); </span><span return</span> <span $userinfo</span><span ; </span><span /*</span><span access_token:获取的Access Token; expires_in:Access Token的有效期,以秒为单位; refresh_token:用于刷新Access Token 的 Refresh Token,长期有效,不会过期; scope:Access Token最终的访问范围,既用户实际授予的权限列表(用户在授权页面时,有可能会取消掉某些请求的权限)。关于权限的具体信息请参考 </span><span */</span><span } </span><span /*</span><span 获取登陆页面URL</span><span */</span> <span public</span> <span function</span><span login_url(){ </span><span if</span>(<span empty</span>(<span $this</span>-><span config)){ </span><span return</span> <span false</span><span ; } </span><span $config</span> = <span $this</span>-><span config; </span><span $login_url</span> = <span $config</span>['login_url'<span ]; </span><span $array</span> = <span array</span><span ( </span>"response_type"=>"code", "client_id"=><span $config</span>['appid'], "redirect_uri"=><span urlencode</span>( <span $config</span>['redirect_uri'<span ] ) ); </span><span $this</span>->set(<span $array</span><span ); </span><span $url</span> = <span $this</span>->combineURL(<span $login_url</span> , <span $this</span>-><span _param); </span><span if</span>(<span $url</span><span ){ @</span><span header</span>("Location:".<span $url</span><span ); }</span><span else</span><span { </span><span return</span> <span false</span><span ; } } }</span>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

On May 30, Tencent announced a comprehensive upgrade of its Hunyuan model. The App "Tencent Yuanbao" based on the Hunyuan model was officially launched and can be downloaded from Apple and Android app stores. Compared with the Hunyuan applet version in the previous testing stage, Tencent Yuanbao provides core capabilities such as AI search, AI summary, and AI writing for work efficiency scenarios; for daily life scenarios, Yuanbao's gameplay is also richer and provides multiple features. AI application, and new gameplay methods such as creating personal agents are added. "Tencent does not strive to be the first to make large models." Liu Yuhong, vice president of Tencent Cloud and head of Tencent Hunyuan large model, said: "In the past year, we continued to promote the capabilities of Tencent Hunyuan large model. In the rich and massive Polish technology in business scenarios while gaining insights into users’ real needs

The 2024 Taobao free order event will be held three times a day. Everyone needs to place an order and pay for the corresponding amount of goods at the corresponding time. The free order amount will be distributed in the form of red envelopes of equal amounts. Next, we will bring you how to receive the Taobao free order red envelope in 2024: grab it For users who are free of charge, the red envelope qualification will be issued to the card and coupon package, which is in a state of activation; the web version of Taobao currently does not have the card and coupon package, and only displays the winning records of the free order event; the card and coupon package is in [Taobao APP-My Taobao] -My Rights-Red Envelope]. How to get red envelopes for free orders on Taobao 20241. For users who grab free orders, the red envelope qualifications will be distributed to the card and coupon packages, which are in a state of waiting for activation; 2. The web version of Taobao currently does not have card and coupon packages, and only displays the winning records of the free order activities. ;3. The card coupon package is in [Taobao APP-My Taobao-My Rights-Red Envelope]

1. Open the Taobao app, click [My Taobao] in the lower right corner, and click [Settings] in the upper right corner. 2. Select [Merchant Settlement], click [Open Taobao Store], and select [General Merchant]. 3. In the [Free Store Opening] interface, users can see the specific process of opening a [Personal Merchant] store. 4. Name your store, then click [Open a store], check all three items, and click [Open a store for 0 yuan]. 5. Finally complete [Real Person Authentication] and complete [Basic Store Information] to successfully open a store.

Taobao is a commonly used online shopping software for many friends. You usually place orders and purchase many things from Taobao. It provides users with a red envelope reminder function. Some friends want to turn it off, so hurry up and check out the PHP Chinese website. Take a look. List of steps to turn off red envelope reminders on Taobao 1. Open the personal center of Taobao APP and select the [Settings] button to enter the page. 2. Find the [Message Notification] option. Here you can select the message push switch. Find the red envelope message and turn off the switch. 3. Or you can turn off the notification permission of Taobao APP through the settings page of your mobile phone, so that all messages from Taobao will not enter the push and can only be seen after turning it on. 4. Users can set what types of messages they want to receive, which makes it easier to use.

When shopping on Taobao, we often use free red envelopes to enjoy discounts. But if we need a refund, will these free red envelopes be returned? Let's take a look at the answer to this question. Will Taobao's free red envelopes be refunded? Depending on the situation, when you receive a red envelope, the red envelope is in a pending activation state. Before redeeming the product, the to-be-activated red envelope is not activated and cannot be used temporarily. You will wait until receipt of the purchased goods is confirmed. , the red envelope that needs to be activated can be used. If there is a problem with the product after using the free red envelope and it needs to be returned, the return of the red envelope needs to be judged according to the actual situation: 1. Refund Rules 11. If a refund occurs after the red envelope is used, the red envelope will be returned in proportion. 2. If the red envelope is not overdue, the period of use of the returned red envelope is the original period of use. If it is overdue, it will be issued within 7 days.

How to use Taobao 510 free red envelope? Taobao recently launched a free order event to celebrate its 510th anniversary. This event allows you to get free order red envelopes, and there are many benefits. I believe many friends want to participate in this event. Some friends have already received free order red envelopes, but they are not. If you know the specific usage, let’s take a look at the relevant introduction today. Instructions for using Taobao’s 510th Anniversary Free Order Red Packet: The free order red pack can be used after all orders placed for guessing questions have been confirmed and received. 1. Users can issue and recover free red envelopes through the web version of Taobao. Currently, there is no card and coupon package, but it can be viewed at [Taobao APP-My Taobao-My Rights-Red Envelopes]. For users who grab the free order, the red envelope qualification will be distributed to the card and coupon package, which is in a state of activation; the card and coupon package is in progress for winning prizes.

AniPortrait models are open source and can be played with freely. "A new productivity tool for Xiaopozhan Ghost Zone." Recently, a new project released by Tencent Open Source received such evaluation on Twitter. This project is AniPortrait, which generates high-quality animated portraits based on audio and a reference image. Without further ado, let’s take a look at the demo that may be warned by a lawyer’s letter: Anime images can also speak easily: The project has already received widespread praise after just a few days since it was launched: the number of GitHub Stars has exceeded 2,800. Let’s take a look at the innovations of AniPortrait. Paper title: AniPortrait:Audio-DrivenSynthesisof

Taobao Winner’s March 31 question: In the Tang Dynasty, what could people still call their father? Many users don’t know what they could call their father in the Tang Dynasty? Then the editor will bring you the 3.31 Taobao Winner Daily I guess today’s answer is shared, if you are interested, come and find out. Taobao Daily Guess Answers Taobao Big Winner March 31: In the Tang Dynasty, could people still call their father? Question: In the Tang Dynasty, could people still call their father? Answer: B. Brother’s answer analysis: 1. Click here to find clues. You can find the answer to the question on the page as shown below; 2. People in the Tang Dynasty can call their father brother. In "Old Book of Tang·Biography of Wang Ju", "Xuanzong said: The fourth brother is benevolent and filial"; 3. The "fourth brother" here refers to Xuanzong's father, Ruizong, was at the same time
