- http_request(){
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- $output = curl_exec($ch);
- curl_close($ch);
- return $output;
- }
-
- function moban($name,$zu,$remain,$openid)
- {
-
- $appid="";
- $appsecret="";
-
- $sql="SELECT * FROM `tokentime` WHERE id='$appid'";
- $query=mysql_query($sql);
- $rk=mysql_fetch_array($query);
- $time=date('Y-m-d H:i:s',time());
- if($rk=="")
- {
-
- $TOKEN_URL="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$appsecret;
- $json=file_get_contents($TOKEN_URL);
- $result=json_decode($json,true);
- $ACCESS_TOKEN=$result['access_token'];
-
- $sql1="INSERT INTO `tokentime` (`id`,`access_token`,`time`) VALUES ('$appid','$ACCESS_TOKEN','$time')";
- $query1=mysql_query($sql1);
- }
- else
- { $time_b=$rk['time'];
- $time_n=date('Y-m-d H:i:s',time()-7200);
-
- if($rk['access_token']==""||$time_b<$time_n)
- {
- $TOKEN_URL="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$appsecret;
- $json=file_get_contents($TOKEN_URL);
- $result=json_decode($json,true);
- $ACCESS_TOKEN=$result['access_token'];
-
- $sql2="UPDATE tokentime SET access_token='$ACCESS_TOKEN',time='$time' WHERE id='$appid'";
- $query2=mysql_query($sql2);
- }
- else
- {
- $ACCESS_TOKEN=$rk['access_token'];
- }
- }
-
- $times= date('m月d日 H:i:s',time());
-
- $template=array(
- 'touser'=>$openid,
- 'template_id'=>"_0DQerSIqPZaB4vjQjjOIPRXZhcVooFT_390vDhHhVw",
- 'url'=>"http://weixin.qq.com/download",
- 'topcolor'=>"#FF0000",
- 'data'=>array(
- 'name'=>array('value'=>urlencode($name),'color'=>"#00008B"),
- 'zu'=>array('value'=>urlencode($zu),'color'=>'#00008B'),
- 'time'=>array('value'=>urlencode($times),'color'=>'#00008B'),
- 'remain'=>array('value'=>urlencode($remain),'color'=>'#00008B'),
- )
- );
- $json_template=json_encode($template);
- $url="https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$ACCESS_TOKEN;
- $res=http_request($url,urldecode($json_template));
- if ($res[errcode]==0) echo '消息发送成功!';
- }