一、文档
参考:https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html
二、代码
1 require_once('weixin.class.php'); 2 $weixin = new class_weixin(); 3 $openid = ""; 4 if(! isset($_GET["code"])){ 5 $redirect_url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; 6 $jumpurl = $weixin->oauth2_authorize($redirect_url, "snsapi_base", "123"); 7 Header("Location: $jumpurl"); 8 exit(); 9 }else{ 10 $access_token = $weixin->oauth2_access_token($_GET["code"]); 11 $openid = $access_token['openid']; 12 $info = $weixin->get_user_info($openid); 13 if($info["subscribe"] == 1){ 14 $href = "http://www.baidu.com/"; 15 }else{ 16 $href = "http://mp.weixin.qq.com/s? __biz=MzA5NzM2MTI4OA==&mid=203240737&idx=1&sn=007bbbe06fb89cbce76d6f8b619acc1a&scene=0#wechat_redirect"; 17 } 18 Header("Location: $href"); 19 exit(); 20 }