|
- <?php
- require_once __DIR__.'/../Common/Config.php';
- require_once __DIR__.'/../Common/Function.php';
- $pdo = new PDO("sqlsrv:Server=".HOST.";Database=".DB, USER, PASSWORD);//5.6版本pdo连接sqlsrv
- $sql="SELECT DISTINCT openId FROM lottery_user";
- $result=$pdo->query($sql);
- $result->setFetchMode(PDO::FETCH_ASSOC); //数字索引方式
- while ($row = $result->fetch()){
- $data[]=$row['openId'];
-
- }
- $next_openid='';
- $n=0;
- $openid=array();
- a:
- $access_token=getAccesstoken();
- $url="https://api.weixin.qq.com/cgi-bin/user/get?access_token=".$access_token."&next_openid=".$next_openid;
- $response=http_request($url);
- $subData=(json_decode($response,true));
- $total=$subData['total'];
- $count=$subData['count'];
- $openid=array_merge($openid,$subData['data']['openid']);
- $next_openid=$subData['next_openid'];
- $n+=$count;
- if ($n < $total ){
- goto a;
- }
- $check=array_intersect($data,$openid);
- $where="";
- foreach ($check as $v){
- $where.="'".$v."',";
- }
- $where=rtrim($where,",");
- $updateSql="UPDATE lottery_user SET subscribe=1 WHERE openId IN(".$where.")";
- $updateResult=$pdo->exec($updateSql);
- $updateError=$pdo->errorInfo();
- $writeLogArr['lottery']=$data;
- $writeLogArr['subscribe']=$openid;
- $writeLogArr['intersect']=$check;
- write_log("checkSubscribe.php".json_encode($writeLogArr));
- ?>
|