首頁  >  文章  >  php教程  >  微信判定用户是否关注

微信判定用户是否关注

PHP中文网
PHP中文网原創
2016-05-25 16:58:181403瀏覽

跳至

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

                   

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn