微信公眾號判斷使用者是否已關注php代碼解析,公眾php_PHP教程

來源:互聯網
上載者:User

公眾號判斷使用者是否已關注php代碼解析,公眾php

現在的活動,很多都引導使用者關注公眾號,才能參與到活動當中,那如何才能判斷使用者關注了公眾號呢? 本文就為大家提供php代碼,解決問題。

官方介面說明
擷取使用者基本資料(包括UnionID機制)

http://mp.weixin.qq.com/wiki/14/bb5031008f1494a59c6f71fa0f319c66.html

1、只要有基礎的access_token和使用者openid就可以判斷使用者是否關注該公眾號
2、利用的介面url為:https://api.weixin.qq.com/cgi-bin/user/info?access_token=$token&openid=$openid
3、判斷介面返回的欄位subscribe是否為1.【1關注,0未關注】

註:
1、判斷使用者登入的方式為靜默授權,使用者無感知,從而得到使用者的openid;
2、判斷使用者登入,需要認證服務號的支援,訂閱號不行;

下面是代碼案例

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

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


http://www.bkjia.com/PHPjc/1138987.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1138987.htmlTechArticle公眾號判斷使用者是否已關注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.