配置微信公眾號 關(guān)注/取消關(guān)注時間操作

 $appId = 'wx7d44aa9edbaae28e';
        $appSecret = 'f2c86c9b3bd1db6e816ac218dfe75076';
        // 獲取推送過來的加密參數(shù)
        $data = file_get_contents('php://input');
        // $this->db->insert('t_test',array('data'=>$data));
        // 解析JSON數(shù)據(jù)
        $jsonData = $this->XmlToArr($data);
        if($jsonData['Event'] != "subscribe"){
            // 非用戶關(guān)注
            return false;
        }
        // $this->db->insert('t_test',array('data'=>json_encode($jsonData)));
        // 獲取加密參數(shù)
        $openid = $jsonData['FromUserName']; // 公眾號openid
        // 獲取access_token
        $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appId}&secret={$appSecret}";
        $response = file_get_contents($url);
        $accessToken = json_decode($response, true)['access_token'];
        // 解密參數(shù)
        $urls = "https://api.weixin.qq.com/cgi-bin/user/info?access_token={$accessToken}&openid={$openid}&lang=zh_CN&appid={$appId}";
        $responses = file_get_contents($urls);
        $this->db->insert('t_test',array('data'=>$responses));
        $decryptedData = json_decode($responses, true);
        // 獲取解密后的用戶參數(shù)
        $openId = $decryptedData['openid'];
        $unionid = $decryptedData['unionid'];
        if(!empty($openId) && !empty($unionid)){
            $this->db->update('t_user',array('wechat_openid'=>$openId),array('unionid'=>$unionid));
        }
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容