function send_text($text, $touser) { $access_token = use_token(); $send_url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" . $access_token; $content = '{ "touser": "******", "toparty": "", "totag": "", "msgtype": "text", "agentid": 2, "text": { "content": "' . $text . '" }, "safe":"1" }'; echo http_post($send_url, $content); }
<?php header("Access-Control-Allow-Origin: *"); if (!empty($_SERVER['HTTP_X_REQUESTED_WITH'])) { if (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { if (!empty($_GET['t']) && $_GET['t'] == 'get') { $t = create_token(); $html = '<table id="butttton-' . $t . '"><tr> <td align="center" valign="middle"><button id="butttton"></button></td></tr> </table>'; echo json_encode(array('html' => $html, 't' => $t)); } else { if (!empty($_POST['t'])) { $t = $_POST['t']; if (use_token($t)) { add_click(); } } } exit; } } function use_token($token) { $found = false; $filename = 'tokens.php'; if (!@file_exists($filename)) { $handle = @fopen($filename, 'wb'); if (!$handle) { exit('Uh. Error creating file: ' . $filename); }