private function getJsApiTicket() { // jsapi_ticket 应该全局存储与更新,以下代码以写入到文件中做示例 $data = json_decode(file_get_contents($GLOBALS['mypath'] . '/tokens/' . $this->weixinId . '_jsapi_ticket.dat')); if ($data->expire_time < time()) { // wxlog('ticket timeout: '.(time()-$data->expire_time)); // 如果是企业号用以下 URL 获取 ticket // $url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=$accessToken"; $this->mInterfaceHander->reflashAccessToken(); $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=" . $this->mInterfaceHander->currentToken; $res = json_decode($this->mInterfaceHander->getByCurl($url)); $ticket = $res->ticket; if ($ticket) { $data->expire_time = time() + 7000; $data->jsapi_ticket = $ticket; $data = json_encode($data); file_put_contents($GLOBALS['mypath'] . '/tokens/' . $this->weixinId . '_jsapi_ticket.dat', $data); } wxlog('get jsapiTicketOnLine'); } else { $ticket = $data->jsapi_ticket; // wxlog('get jsapiTicket from file'); } return $ticket; }
function deleteButton($weixinId = 0) { $itfc = $GLOBALS['ready'] ? $GLOBALS['mInterface'] : new interfaceHandler($weixinId); $data = $itfc->sendGet('https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=ACCESS_TOKEN'); echo $data; echo 'delete ok'; wxlog('delete all button'); }
public function getTokenOnLine() { include_once $GLOBALS['mypath'] . '/includes/db.inc.php'; $appinf = pdoQuery('user_tbl', null, array('weixin_id' => $this->weixinId), null); $data = $appinf->fetch(); $jsonToken = file_get_contents('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $data['app_id'] . '&secret=' . $data['app_secret']); $geted = json_decode($jsonToken, true); $geted['gettedTime'] = time(); $this->currentToken = $geted['access_token']; $this->gettedTime = $geted['gettedTime']; $this->expiresIn = $geted['expires_in']; $reJson = json_encode($geted); file_put_contents($GLOBALS['mypath'] . '/tokens/' . $this->weixinId . '.token', $reJson); // wxlog($reJson); // wxlog($GLOBALS['mypath'] . '/tokens/'.$this->weixinId.'.token'); wxlog($this->weixinId . ': getTokenOnLine'); }
public function receiverFilter_o() { $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; if (!empty($postStr)) { libxml_disable_entity_loader(true); $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); $msg['from'] = $postObj->FromUserName; $msg['me'] = $postObj->ToUserName; $msg['type'] = $postObj->MsgType; $msg['msgId'] = $postObj->MsgId; // wxlog('basic msginf ok,type: '.$msg['type']); switch ($msg['type']) { case 'text': $msg['content'] = trim($postObj->Content); break; case 'image': $msg['PicUrl'] = $postObj->PicUrl; // wxlog('geturl' . $msg['PicUrl']); $msg['MediaId'] = $postObj->MediaId; // wxlog('getMediaId:' . $msg['MediaId']); break; case 'voice': $msg['MediaId'] = $postObj->MediaId; $msg['Format'] = $postObj->Format; break; case 'video': $msg['MediaId'] = $postObj->MediaId; $msg['ThumbMediaId'] = $postObj->ThumbMediaId; break; case 'shortvideo': $msg['MediaId'] = $postObj->MediaId; $msg['ThumbMediaId'] = $postObj->ThumbMediaId; break; case 'event': $msg['Event'] = $postObj->Event; $msg['EventKey'] = $postObj->EventKey; break; } } $this->msg = $msg; wxlog(json_encode($msg)); return $msg; // } // echo 'error'; // exit; }
private function uploadImg() { if (isset($_POST['upfile']) || $_FILES['upfile']) { header("Content-Type:text/html;charset=utf-8"); error_reporting(E_ERROR | E_WARNING); $config = array("savePath" => imgPath, "maxSize" => maxSize, "allowFiles" => array(".gif", ".png", ".jpg", ".jpeg", ".bmp")); $up = new uploader($_SESSION['weixinId'], $this->newsId, "upfile", $config); $type = $_REQUEST['type']; $callback = $_GET['callback']; $info = $up->getFileInfo(); wxlog(json_encode($info)); /** * 返回数据 */ if ($callback) { echo '<script>' . $callback . '(' . json_encode($info) . ')</script>'; } else { echo json_encode($info); } } }
<?php /** * Created by PhpStorm. * User: godlee * Date: 2015/5/25 * Time: 13:29 */ include_once $mypath . '/class/interfaceHandler.php'; wxlog('include default ok'); $query = pdoQuery('default_reply_tbl', null, array('weixin_id' => $weixinId), ' order by key_word desc limit 10'); //$queryArray=$query->fetchAll(); foreach ($query as $row) { if (preg_match('/' . $row['key_word'] . '/', $msg['Content'])) { switch ($row['reply_type']) { case 'text': $weixin->replyMsg(array('Content' => $row['content'], 'MsgType' => 'text')); // $response=$weixin->prepareTextMsg($msg['from'],$msg['me'],$row['content']); // echo $response; exit; break; case 'news': $response = $weixin->prepareNewsMsg($msg['from'], $msg['me'], $row['content']); echo $response; exit; break; } } } //$response = $weixin->prepareTextMsg($msg['from'], $msg['me'], ); $response = '';
<?php //$mypath = $_SERVER['DOCUMENT_ROOT'] . '/wechat'; //include_once $mypath . '/includes/magicquotes.inc.php'; //include_once $mypath . '/includes/db.inc.php'; //include_once $mypath . '/includes/helpers.inc.php'; //include_once $mypath . '/class/wechat.php'; include_once $mypath . '/contrller/serveManager.php'; wxlog('include wechatWall ok'); $userInf = getUnionId($msg['from'], $msg['me']); $userName = $userInf['nickname']; $userIcon = $userInf['headimgurl']; $sex = $userInf['sex']; $url = 'insert into wechat_wall_tbl set user_name="' . $userName . '",sex="' . $sex . '",user_icon="' . $userIcon . '",content=:content,img_url=:imgUrl,upload_time=:uploadTime'; if ($msg['type'] == 'text') { pdoInsert('wechat_wall_tbl', array('owner' => $msg['me'], 'user_name' => $userName, 'sex' => $sex, 'user_icon' => $userIcon, 'content' => $msg['content'], 'upload_time' => time())); } if ($msg['type'] == 'image') { pdoInsert('wechat_wall_tbl', array('owner' => $msg['me'], 'user_name' => $userName, 'sex' => $sex, 'user_icon' => $userIcon, 'img_url' => $msg['PicUrl'], 'upload_time' => time())); } $echoMsg = $weixin->prepareTextMsg($msg['from'], $msg['me'], '收到了'); echo $echoMsg; exit;
<?php $mypath = $_SERVER['DOCUMENT_ROOT'] . '/wechat'; include_once $mypath . '/includes/magicquotes.inc.php'; include_once $mypath . '/includes/db.inc.php'; include_once $mypath . '/includes/helpers.inc.php'; include_once $mypath . '/class/wechat.php'; if (isset($_GET['id'])) { wxlog('fetch,to:' . $_GET['id']); $weixinId = $_GET['id']; $query = pdoQuery('duty_tbl', array('duty'), array('weixin_id' => $weixinId), ' limit 1'); $data = $query->fetch(); $decodeData = json_decode($data['duty'], true); $weixin = new wechat($weixinId); $weixin->valid(); $msg = $weixin->receiverFilter(); foreach ($decodeData['dutyContent'] as $row) { // wxlog('include:'.$mypath.'/'.$row); $query = pdoQuery('module_config_tbl', array('config'), array('weixin_id' => $weixinId, 'module_path' => $row), ' limit 1'); if ($config = $query->fetch()) { $config = json_decode($config['config'], true); $config = $config['config']; } include_once $mypath . '/' . $row; } echo ''; eixt; } header('location: admin/index.php');
<?php /** * Created by PhpStorm. * User: godlee * Date: 2015/5/26 * Time: 17:12 */ wxlog('include mobilePhone ok'); if (count($msg['content']) < 10 && count($msg['content']) > 0) { include_once $mypath . '/class/mobilePhoneQuery.php'; $phoneQuery = new mobilePhoneQuery(); $response = $phoneQuery->getPrice($msg['content']); if ($response != '以上报价由慈溪兄弟数码提供,仅供参考,详情请咨询店家') { $response = $weixin->prepareTextMsg($msg['from'], $msg['me'], $response); echo $response; exit; } }
/** * 比对上传文件的Md5值,如与已上传文件重复则直接返回已上传的文件 * @param $news_id 图文信息名 * @param $md5 上传文件的md5值 */ private function checkFileMd5($news_id, $md5) { $query = pdoQuery('img_tbl', null, array('md5' => $md5), 'limit 1'); // wxlog('query'); if ($row = $query->fetch()) { wxlog('match'); $this->fileName = $row['name']; $this->fullName = $row['url']; $this->addImgToNews($news_id, $md5); return true; } else { wxlog('not match'); return false; } // wxlog('nomatch'); }
$position++; } $response = 'sorry,您的成绩未在前' . $rank . '名以内'; $re = $weixin->prepareTextMsg($msg['from'], $msg['me'], $response); echo $re; exit; } $query = pdoQuery('guess_tbl', null, array('open_id' => $msg['from'], 'weixin_id' => $weixinId), ' limit 1'); // wxlog('query guess_tbl ok'); if ($row = $query->fetch()) { $songList = json_decode($row['answer'], true); $correctLast = count($songList); reset($songList); // wxlog('has intent'); if ($row['total_try'] > $totalTry - 1) { wxlog('try max'); $response = '您已达到最大答题次数,回复“排名”即可查看当前您的成绩排名'; $res = $weixin->prepareTextMsg($msg['from'], $msg['me'], $response); echo $res; exit; } if ($correctLast < 2) { $response = '恭喜您,您全部猜对了,回复“排名”可查看成绩排名'; $res = $weixin->prepareTextMsg($msg['from'], $msg['me'], $response); echo $res; exit; } // wxlog('totalTry:'.$row['total_try']); if ($key = array_search($msg['Content'], $songList)) { array_splice($songList, $key, 1); $jsonList = json_encode($songList);