Home  >  Article  >  php教程  >  微信判定用户是否关注

微信判定用户是否关注

PHP中文网
PHP中文网Original
2016-05-25 16:58:181367browse

跳至

	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;
				}
			}
		}

                   

Statement:
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