Home > php教程 > PHP源码 > body text

微信判定用户是否关注

PHP中文网
Release: 2016-05-25 16:58:18
Original
1392 people have browsed it

跳至

	if (empty($openid)){
			if (empty($_REQUEST["code"])) {
				$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$APPID."&redirect_uri=".$redirect_url."&response_type=code&scope=snsapi_base&state=blinq#wechat_redirect";
				echo $this->assign('url', $url)->fetch('redirect');
				return;
			}else{
				$code = $_REQUEST['code'];
			
				$APPID = C("APPID");
				$SECRET = C("SECRET");
				$accessTokenUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . $APPID . "&secret=" . $SECRET . "&code=$code&grant_type=authorization_code";
				$ch = curl_init($accessTokenUrl);
				curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
				curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1; rv:21.0) Gecko/20100101 Firefox/21.0');
				curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
				$info = curl_exec($ch);
				$dataJson = json_decode($info, true);
				$openid = $dataJson['openid'];
				$userdata = $table->get_subscribe_res($openid);
				$subscribed = $userdata['data']['subscribed'];
				if($subscribed){
					session("openid", $openid);	
				
				}else{
					$url="http://www.oschina.net/code/step1?catalog=";
					echo $this->assign('url', $url)->fetch('redirect');
					return;
				}
			}
		}
Copy after login

                   

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!