PHP判斷字元類型 php判斷使用者是否關注微信公眾號

來源:互聯網
上載者:User
最近要做一個平台的投票活動,需要在關注公眾號之後才能參與投票,那麼,如何判斷使用者是否關注了公眾號呢?

第一想法是,通過擷取公眾號的關注列表,然後搜尋列表中是否有參與者的openid。

但是馬上發現一個問題,就是這種方法需要每次都要擷取一下關注列表,而且,當公眾號的粉絲比較多時,這種方法就比較吃力了。

下面使用php方法,判斷使用者是否關注了公眾號:

<?php    $access_token = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=XXXXXXXXXXXXXXXXXX&secret=XXXXXXXXXXXXXXXXXXXXXXXXXX";    $access_msg = json_decode(file_get_contents($access_token));    $token = $access_msg->access_token;    $subscribe_msg = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=$token&openid=$_GET[openid]";    $subscribe = json_decode(file_get_contents($subscribe_msg));    $gzxx = $subscribe->subscribe;    //    if($gzxx === 1){     echo "已關注";    }else{    echo "未關注";     }

下面是第二個代碼案例

< ? php$access_token = $this - > _getAccessToken();$subscribe_msg = 'https://api.weixin.qq.com/cgi-bin/user/info?access_token='.$access_token.'&openid='.$_SESSION['wecha_id'];$subscribe = json_decode($this - > curlGet($subscribe_msg));$zyxx = $subscribe - > subscribe;if ($zyxx !== 1) { echo'未關注!';}private function _getAccessToken() { $where = array('token' = > $this - > token); $this - > thisWxUser = M('Wxuser') - > where($where) - > find(); $url_get = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$this - > thisWxUser['appid'].'&secret='.$this - > thisWxUser['appsecret']; $json = json_decode($this - > curlGet($url_get)); if (!$json - > errmsg) { } else { $this - > error('擷取access_token發生錯誤:錯誤碼'.$json - > errcode.',返回錯誤資訊:'.$json - > errmsg); } return $json - > access_token;}? >

以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援本站。

以上就介紹了PHP判斷字元類型 php判斷使用者是否關注公眾號,包括了PHP判斷字元類型方面的內容,希望對PHP教程有興趣的朋友有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.