配置微信公众号 关注/取消关注时间操作

 $appId = 'wx7d44aa9edbaae28e';
        $appSecret = 'f2c86c9b3bd1db6e816ac218dfe75076';
        // 获取推送过来的加密参数
        $data = file_get_contents('php://input');
        // $this->db->insert('t_test',array('data'=>$data));
        // 解析JSON数据
        $jsonData = $this->XmlToArr($data);
        if($jsonData['Event'] != "subscribe"){
            // 非用户关注
            return false;
        }
        // $this->db->insert('t_test',array('data'=>json_encode($jsonData)));
        // 获取加密参数
        $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'];
        // 解密参数
        $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);
        // 获取解密后的用户参数
        $openId = $decryptedData['openid'];
        $unionid = $decryptedData['unionid'];
        if(!empty($openId) && !empty($unionid)){
            $this->db->update('t_user',array('wechat_openid'=>$openId),array('unionid'=>$unionid));
        }
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容