public function isguanzhu(){
$user_id = input('user_id');
$user = Huashiusers::where('id',$user_id)->find();
$token = $this->access_token();
$subscribe_msg = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=$token&openid=".$user['openid'];
$subscribe = json_decode($this->curl_get($subscribe_msg));
$gzxx = $subscribe->subscribe;
if($gzxx === 1){
return $this->ajaxReturn($this->successCode,'返回成功',1); //关注
}else {
return $this->ajaxReturn($this->successCode,'返回成功',0); //未关注
}
}
//获取access_token
public function access_token(){
$token = Huashibili::find(1);
$access_token = $token['access_token'];
if(time() > $token['time']){
$url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.Config::get('app.appid').'&secret='.Config::get('app.secret');
$data = json_decode($this->curl_get($url),true);
$access_token = $data['access_token'];
$token->access_token = $data['access_token'];
$token->time = time() + 3600;
$token->save();
}
return $access_token;
}
protected function curl_get($url)
{
//初始化
$curl = curl_init();
$removeBom = function($url) { return preg_replace('/\\0/', "", $url); };
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
//设置抓取的url
curl_setopt($curl,CURLOPT_URL,$removeBom($url));
//设置获取的信息以文件流的形式返回,而不是直接输出。
curl_setopt($curl,CURLOPT_RETURNTRANSFER, 1);
//执行命令
$data = curl_exec($curl);
//关闭URL请求
curl_close($curl);
//显示获得的数据
return $data;
}
检查用户是否关注微信公众号
最新推荐文章于 2024-06-03 01:15:05 发布