Rumah  >  Artikel  >  php教程  >  微信判定用户是否关注

微信判定用户是否关注

PHP中文网
PHP中文网asal
2016-05-25 16:58:181388semak imbas

跳至

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

                   

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn