php判斷用戶是否關注微信公衆號的方法

近期遇到的問題就是,客戶的需求是必須關注公衆號之後才能進行相關的操作,話不多說直接上代碼

     * 判斷用戶是否關注公衆賬號 function
     *
     * @Author yujiang [email protected]
     * @DateTime 2020-02-13
     * @param string $openid
     * @return boolean
     */
  function isFollow(){
        $openid=db('partner')->where('id',session('hmcuid'))->value('openid');
        $access_token = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxxxxxxxxxxx&secret=dxxxxxxxxxxxxxe56a118";
        $access_msg = json_decode(file_get_contents($access_token));
        $token = $access_msg->access_token;
		$url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=".$token."&openid=".$openid."&lang=zh_CN";
		$subscribe =getJson($url);
		$zyxx = $subscribe['subscribe'];//如果是1已關注
		return $zyxx;
    }
function getJson($url){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    curl_close($ch);
    return json_decode($output, true);
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章