In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to achieve Wechat third-party login demo", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "how to achieve Wechat third-party login demo" bar!
First of all:
Data preparation: watermark picture 288 png format company logo high definition picture 108cm 108 png format company logo1. Fill in the basic information in the Wechat open platform https://open.weixin.qq.com/, 2. Complete mailbox verification, 3. And improve the developer information, register as a developer. 4. Complete the developer qualification certification in the account Center. 5. Enter the website application of the Wechat Open platform Management Center and click the "create Application" button. 6. Fill in the basic information and click on next step 7. Fill in the platform information application signature: the signature Generation tool can be downloaded from the Resource Center "Resource download" of the Wechat development platform, and users can obtain the signatures of third-party applications that have been installed on the phone. Enter the name of the application package to get the signature value of the application. 8. After submitting the review, Tencent will give the audit results within 7 working days. (usually faster, and the results can be fed back in a few hours)
Get the AppID,AppSecret, and then process it:
You need to give a link to the login page of the website you want to add: Wechat login
Start processing Wechat login
Define appid appsecert
Private $appid = "your appid"; private $appsecert = "your appsecert"; private $redirect_uri = http://www.sunmil.cn/wxGetCode;
Bind account page
Public function weixin () {/ / linked database $link = mysqli_connect (DB_HOST, DB_USER,DB_PASSWORD,DB_NAME) or die ('database connection failed 4'); $link = mysqli_connect (' 127.0.0.1 failed, 'root','root',' ec') or die ('database connection failed'); mysqli_set_charset ($link,'utf8'); / / receive openid $openid = $_ COOKIE ['openid'] $sql = "select * from sdb_trustlogin_trustinfo where openid ='$openid'"; $res = mysqli_query ($link, $sql); $row = mysqli_fetch_assoc ($res); $this- > pagedata ['realname'] = $row [' realname']; $this- > pagedata ['avatar'] = $row [' avatar']; $this- > page ("site/passport/weixin.html");}
When you log in to Wechat for the first time, deal with the binding account page
Public function handle ($url=null) {/ / $url= "http://www.sunmil.cn"; / / linked database $link = mysqli_connect (DB_HOST, DB_USER,DB_PASSWORD,DB_NAME) or die ('database connection failed 3'); mysqli_set_charset ($link,'utf8'); $post = utils::_filter_input ($_ POST) $userData = array ('login_account' = > $post [' uname'], 'login_password' = > $post [' password']); $member_id = kernel::single ('pam_passport_site_basic')-> login ($userData,$post [' verifycode'], $msg); $b2c_members_model = $this- > app- > model ('members'); $member_point_model = $this- > app- > model (' member_point') $member_data = $b2cmemorymembersmodels-> getList ('member_lv_id,experience,point', array (' member_id'= > $member_id)); $member_data = $member_data [0]; $member_data ['order_num'] = $this- > app- > model (' orders')-> count (array ('member_id'= > $member_id)); $b2cmemorymembers models-> update ($member_data,array (' member_id'= > $member_id)) $this- > userObject- > set_member_session ($member_id); $this- > bind_member ($member_id); $this- > set_cookie ('loginName',$post [' uname'], time () + 31536000); / / A parameter $aCart = array () is required to remember the password / / setCartNum (); $this- > app- > model ('cart_objects')-> setCartNum ($aCart); $url = $this- > userPassport- > get_next_page (' pc') If (! $url) {$url = kernel::single ('b2cregions frontpage')-> gen_url (array ('app'= >' b2cregions @ frontpage = > 'site_member','act'= >' index'));} / / query the database $uname = $_ POST ['uname']; $sql = "select * from sdb_pam_members where password_account =' $uname'"; $res = mysqli_query ($link, $sql) $row = mysqli_fetch_assoc ($res); $member_id = $row ['member_id']; / / Link database, insert data $openid = $_ COOKIE [' openid']; $sql = "update sdb_trustlogin_trustinfo set member_id = ('{$member_id}') where openid ='{$openid}'"; $res = mysqli_query ($link, $sql) If ($res & & mysqli_affected_rows ($link) > 0) {/ / delete cookie setcookie ("openid", $openid, time ()-3600); kernel::single ('pam_lock')-> flush_lock ($member_id); $this- > splash (' success',$url,app::get ('b2c')-> _ (' login successful'), true);} else {echo 'failed';}}
Process the binding registration page
Public function weixin1 () {/ / linked database $link = mysqli_connect (DB_HOST, DB_USER,DB_PASSWORD,DB_NAME) or die ('database connection failed 2'); mysqli_set_charset ($link,'utf8'); / / receive openid $openid = $_ COOKIE [' openid']; $sql = "select * from sdb_trustlogin_trustinfo where openid ='$openid'"; $res = mysqli_query ($link, $sql) $row = mysqli_fetch_assoc ($res); $this- > pagedata ['realname'] = $row [' realname']; $this- > pagedata ['avatar'] = $row [' avatar']; $this- > page ("site/passport/weixin1.html");}
Bind registration page
Public function handle1 ($url=null) {/ / linked database $link = mysqli_connect (DB_HOST, DB_USER,DB_PASSWORD,DB_NAME) or die ('database connection failed 1'); mysqli_set_charset ($link,'utf8'); $_ POST = utils::_filter_input ($_ POST); $saveData = $this- > userPassport- > pre_signup_process ($_ POST) If ($member_id = $this- > userPassport- > save_members ($saveData,$msg)) {$this- > userObject- > set_member_session ($member_id); $this- > bind_member ($member_id); foreach (kernel::servicelist ('b2csaved savegoat postgraduate') as $object) {$object- > set_arr ($member_id, 'member'); $refer_url = $object- > get_arr ($member_id,' member') } / * do something after registration! Begin*/ foreach (kernel::servicelist ('b2cregistered registerships) as $object) {$object- > registerActive ($member_id);} / * end*/ $data [' member_id'] = $member_id; $data ['uname'] = $saveData [' pam_account'] ['login_account']; $data [' passwd'] = $_ POST ['pam_account'] [' psw_confirm'] $data ['email'] = $_ POST [' contact'] ['email']; $data [' refer_url'] = $refer_url? $refer_url:'; $data ['is_frontend'] = true; $obj_account=$this- > app- > model (' member_account'); $obj_account- > fireEvent ('register',$data,$member_id) If (! strpos ($_ SESSION ['pc_next_page'],' cart')) {$url = $this- > gen_url (array ('app'= >' b2cgenes grammatical ctlands = > 'site_passport','act'= >' sign_tips'));} else {$url = $_ SESSION ['pc_next_page'] } / / member registration is successful, start processing member_id $login_name = $_ POST ["pam_account"] ["login_name"]; $sql = "select member_id from sdb_pam_members where password_account ='{$login_name}'"; / / echo $sql; $res = mysqli_query ($link, $sql); $row = mysqli_fetch_assoc ($res); $member_id = $row ['member_id'] / / Link database, insert data $openid = $_ COOKIE ['openid']; $sql = "update sdb_trustlogin_trustinfo set member_id = (' {$member_id}') where openid ='{$openid}'"; $res = mysqli_query ($link, $sql); if ($res & & mysqli_affected_rows ($link) > 0) {/ / Delete cookie setcookie ("openid", $openid, time ()-3600) $this- > splash ('success',$url,app::get (' b2c')-> _ ('registration successful'), $ajax_request);} / / member registration is successful, processing member_id ends with $this- > splash ('failed',$back_url,app::get (' b2c')-> _ (registration failed'), $ajax_request);}}
Temporary page
Public function linshi () {$code = $_ GET ['code']; $state = $_ GET [' state']; if ($state = 'STATE') {$this- > loginWeixin ($code);} elseif ($state =' wxBind') {$this- > bindWeixin ($code);} else {return redirect ("http://www.sunmil.cn");}})
LoginWeixin
Private function loginWeixin ($code) {/ / linked database $link = mysqli_connect ('127.0.0.1 database,' root','root', 'ec') or die (' database connection failed'); mysqli_set_charset ($link,'utf8'); $appid = $this- > appid; $appsecert = $this- > appsecert $url = "https://api.weixin.qq.com/sns/oauth3/access_token?appid=".$appid."&secret=".$appsecert."&code=".$code."&grant_type=authorization_code"; / / curl simulates the get request and gets the result $res = $this- > http_curl ($url); / / converts it into an array $result = json_decode ($res,true); $openid = $result ['openid'] / / openid exists, login directly, openid does not exist, register first and then log in $sql = "select openid from sdb_trustlogin_trustinfo"; $res = mysqli_query ($link, $sql); $row = mysqli_fetch_all ($res) / / foreach judges foreach ($row As $v) {if (in_array ($openid,$v,true)) {/ / missing login information $sql = "select member_id from sdb_trustlogin_trustinfo where openid ='{$openid}'"; / / finds member_id $res = mysqli_query ($link, $sql); $row = mysqli_fetch_assoc ($res) $member_id = $row ['member_id']; / / find out membership information $sql = "select * from sdb_pam_members where member_id =' {$member_id}'"; $res = mysqli_query ($link, $sql); $row = mysqli_fetch_assoc ($res); $login_name = $row ['login_account'] / / save to cookie setcookie ('UNAME',$login_name, time () + 360000); echo "_ window.location.href=' http://www.sunmil.cn'"; exit;}} $access_token = $result [' access_token'] / / get basic user information $getInfoUrl = "https://api.weixin.qq.com/sns/userinfo?access_token=".$access_token."&openid=".$openid."&lang=zh_CN"; $userInfo = $this- > http_curl ($getInfoUrl); $trustinfo = json_decode ($userInfo); / / determine whether the data exists in the trustinfo table $openid = $trustinfo- > openid; $nickname = $trustinfo- > nickname; $sex = $trustinfo- > sex $city = $trustinfo- > city; $province = $trustinfo- > province; $country = $trustinfo- > country; $avatar = $trustinfo- > headimgurl; $trust_source = 'trustlogin_plugin_weixin' / / Connect to the database and insert data $sql = "insert into sdb_trustlogin_trustinfo (openid,realname,avatar,gender,province,city,trust_source) values ('{$openid}','{$nickname}','{$avatar}','{$sex}','{$province}','{$city}','{$trust_source}')"; $res = mysqli_query ($link, $sql) If ($res & & mysqli_affected_rows ($link) > 0) {/ / save to cookie setcookie ('openid',$openid, time () + 3600); header ("Location: http://www.sunmil.cn/passport-weixin.html");} else {echo' failed';}}
Curl simulates a get request
Private function http_curl ($url) {$curlobj = curl_init (); curl_setopt ($curlobj, CURLOPT_URL, $url); curl_setopt ($curlobj, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($curlobj, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt ($curlobj, CURLOPT_SSL_VERIFYHOST, FALSE); $output = curl_exec ($curlobj); curl_close ($curlobj); return $output;}
Handle the end of Wechat login
You can achieve Wechat login, of course, a simple familiar with Wechat third login demo, have the opportunity to use the tp framework sub-package to improve a complete Wechat third-party login.
Thank you for your reading, the above is the content of "how to achieve Wechat third-party login demo". After the study of this article, I believe you have a deeper understanding of how to achieve Wechat third-party login demo, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.