在各厂商(腾讯云、阿里云)进行接入备案时,通过特定接口获取备案通过的时间来判断是否备案完成,并设置计划任务,定时访问此URL,如果备案完成,则使用企业微信的自建应用推送备案完成的信息。
主程序:
<?php
header("Access-Control-Allow-Origin:*");
header("Access-Control-Allow-Methods:GET");
header("Access-Control-Allow-Headers:x-requested-with,content-type");
header("Content-Type:text/html,application/json; charset=utf-8");
date_default_timezone_set("Asia/Shanghai");
$domain = 'xxxx.com.cn';
if (!$domain) {
exit(json_encode(array('msg' => '缺少参数','result' => 0,), JSON_UNESCAPED_UNICODE));
}
$timeStamp = time();
$authKey = md5("testtest" . $timeStamp);
$token = json_decode(curl_post("auth", "authKey=$authKey&timeStamp=$timeStamp", "application/x-www-form-urlencoded;charset=UTF-8", "0"));
$token = $token->params->bussiness;
$query = json_decode(curl_post("icpAbbreviateInfo/queryByCondition", '{"pageNum":"","pageSize":"","unitName":"' . $domain . '"}', "application/json;charset=UTF-8", $token));
$query = json_encode($query->params->list);
$query = str_replace("[", "", $query);
$query = json_decode(str_replace("]", "", $query));
$icp = $query->serviceLicence;
$domain1 =$query->domain;
$unitName = $query->unitName;
$natureName = $query->natureName;
$updateRecordTime = $query->updateRecordTime;
$limitAccess = $query->limitAccess;
if (!$token) {
$icp = "服务器请求频率过高,请稍后再试";
$msg = "查询失败";
$code = "0";
} elseif (!$icp) {
$icp = "未备案";
$msg = "查询成功";
$code = "1";
} else {
$msg = "查询成功";
$code = "1";
}
$json = array(
'icp' => $icp,
'domain'=>$domain,
'unitName' => $unitName,
'natureName' => $natureName,
'time' => $updateRecordTime,
'limitAccess'=>$limitAccess,
'msg' => $msg,
'result' => $code
);
$json1 = json_encode($json, JSON_UNESCAPED_UNICODE);
$beian = "备案号:".$icp."\n域名:".$domain."\n备案时间:".$updateRecordTime."\n查询时间:".date("Y-m-d H:i:s",time());
include "send.php";
$qy = new send();
$thisTime = date("Hi",time());
if($updateRecordTime>'2000-01-01'){
$qy->qysend($beian);
echo $json1;
}else{
echo $json1;
}
function curl_post($url, $data, $Content, $token) {
$ip = "101.".mt_rand(1,255).".".mt_rand(1,255).".".mt_rand(1,255);
$ch = curl_init();
$headers = array(
"Content-Type: $Content",
"Origin: https://beian.miit.gov.cn/",
"Referer: https://beian.miit.gov.cn/",
"token: $token",
"User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36",
"CLIENT-IP: $ip",
"X-FORWARDED-FOR: $ip"
);
curl_setopt($ch, CURLOPT_URL, "https://hlwicpfwc.miit.gov.cn/icpproject_query/api/" . $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
企业微信PHP接口:
qyToken.php
<?php
class qyToken{
function qyDes(){
$qyID="";//企业微信的企业ID
$qyYYSecret="";//企业微信的企业应用密钥
$agentid = "";//企业微信的企业应用ID
return array("qid"=>$qyID,"qys"=>$qyYYSecret,"aid"=>$agentid);
}
function qyTK(){
$qdDes = $this->qyDes();
$qyID=$qdDes['qid'];//企业微信的企业ID
$qyYYSecret=$qdDes['qys'];//企业微信的企业应用密钥
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$qyToken = $redis->exists("ICPToken");
if ($qyToken==0){
$url1 = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid='.$qyID.'&corpsecret='.$qyYYSecret;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$token = json_decode($output)->access_token;
$redis->set("ICPToken",$token);
$redis->expire("ICPToken","7200");
}
return $redis->get("ICPToken");
}
}
send.php
<?php
class send{
function qysend($test1){
include "qyToken.php";
$qy = new qyToken();
$token = $qy->qyTK();
$agentid = $qy->qyDes()['aid'];
$url1 = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token='.$token;
$ch = curl_init();
$data1 = array("content"=>$test1);
$data = json_encode(array("touser"=>"@all","msgtype"=>"text","agentid"=>$agentid,"text"=>$data1));
curl_setopt($ch, CURLOPT_URL, $url1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
// echo $output;
}
}