Ejemplo n.º 1
0
function getToken()
{
    require_once 'comm.php';
    $currnet = time();
    $Token_result = new connect();
    $sql = "SELECT * FROM options where type='token'";
    $result = $Token_result->query($sql);
    $arr = mysql_fetch_array($result);
    $time_token = $arr['value'];
    if ($currnet >= $time_token) {
        $appid = "wxa2986e7d8863b2ab";
        $secret = "08d000097799e646d11b57e0acd71a9f";
        $access_token = file_get_contents("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}");
        $access_token = json_decode($access_token);
        $access_token = $access_token->{'access_token'};
        //修改新的token信息
        $time = $currnet + 7200;
        $sql = "UPDATE options SET title='" . $access_token . "',value='" . $time . "' where type='token'";
        $Token_result->query($sql);
    } else {
        $access_token = $arr['title'];
        //$access_token ="48QToD2xXqQSwSNF8uqn6iF3o3P4yDEqvrrxaDDO0nxqcZFgg95IwA_xAafzwhsVxcM4Hh0tQTtwIcTqFxEa_B1IUpXE67cVUmpBnq_09rE";
    }
    return $access_token;
}
Ejemplo n.º 2
0
<?php

header("Content-type:text/html;charset=utf-8");
require_once 'comm.php';
$page = 0;
$pagesize = 20;
if ($_POST['page']) {
    $page = $_POST['page'];
}
$start = $pagesize * $page;
echo "<form action='sendMessage.php' method='post'>\n\t\t\t<table>\t\n\t\t\t\t<input type='hidden' name='page' id='page' value=" . ($page + 1) . " />\n\t\t\t\t<input type='submit' value='NextPage' />\n\t\t\t</table>\n\t </form>";
$connect = new connect();
$list = $connect->query("SELECT * FROM ecs_chat_log ORDER BY time DESC LIMIT {$start},{$pagesize}");
while ($arr = mysql_fetch_array($list)) {
    echo $arr['time'] . "=>" . $arr['nickname'] . ":" . $arr['message'] . "<br />";
    echo "<form action='sendMessage.php' method='post'>\n\t\t\t<table>\n\t\t\t\t<input type='text' name='message' id='message' />\n\t\t\t\t<input type='hidden' name='openid' id='openid' value=" . $arr['openid'] . " />\n\t\t\t\t<input type='hidden' name='page' id='page' value=" . $page . "/>\n\t\t\t\t<input type='submit' value='send' />\n\t\t\t</table>\n\t </form>";
}
//$result = $connect->query("INSERT INTO ecs_chat_log (openid,message,nickname,time) VALUES('".$openid."','".$Content."','".$nickname."','".$CreateTime."')");
if ($_POST['message'] && $_POST['openid']) {
    require_once 'getTokenMessage.php';
    $message = $_POST['message'];
    $openid = $_POST['openid'];
    unset($_POST['message']);
    $access_token = getToken();
    $content = '{
		"touser":"******",
		"msgtype":"text",
		"text":
		{
			 "content":"' . $message . '"
		}