美文网首页
配置微信公众号 关注/取消关注时间操作

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

作者: 风度翩翩的程序猿 | 来源:发表于2023-08-24 18:01 被阅读0次
     $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));
            }
    

    相关文章

      网友评论

          本文标题:配置微信公众号 关注/取消关注时间操作

          本文链接:https://www.haomeiwen.com/subject/ctfvmdtx.html