PHP code How to get the user's OpenID Web page

Source: Internet
Author: User
Tags openid

 Publicfunction Getopenid ($appid, $appsecret) {$SERVER _name= $_server['server_name']; $REQUEST _uri= $_server['Request_uri']; $redirect _uri= UrlEncode ('/ http'. $SERVER _name. $REQUEST _uri); $code= $_get['Code']; if(!$code) {            //website Authorization$autourl ="https://open.weixin.qq.com/connect/oauth2/authorize?appid= $appid &redirect_uri= $redirect _uri& Response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect"; Header ("Location : $autourl"); } Else {            //Get OpenID$url ="https://api.weixin.qq.com/sns/oauth2/access_token?appid= $appid &secret= $appsecret &code= $code & Grant_type=authorization_code"; $row= $ This-PostURL ($url); return($row ['OpenID']); }    }     Publicfunction PostURL ($url) {$ch=Curl_init ();        curl_setopt ($ch, Curlopt_url, $url);        curl_setopt ($ch, Curlopt_ssl_verifypeer, FALSE);        curl_setopt ($ch, Curlopt_ssl_verifyhost, FALSE); curl_setopt ($ch, Curlopt_returntransfer,1); $output=curl_exec ($ch);        Curl_close ($ch); $jsoninfo= Json_decode ($output,true); return$jsoninfo; }

Thank you very much for the guidance of the Great God, let me go a few detours, I also want to see friends less detours ha.

PHP code How to get the user's OpenID Web page

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.