/** * 根据账户ID获得access token 如果过期 再重新获取一下 * @param $accountID 账号ID * @param $filePath 文件绝对路径 * @return $accsess_token token */ static function uploadWxMedia($accountID, $type, $filePath) { //允许的类型及大小(KB) $access_media = array('image' => 128, 'voice' => 256, 'video' => 1024, 'thumb' => 64); switch (true) { case !isset($access_media[$type]): throw new THttpException("media type not allow"); break; case !file_exists($filePath): throw new THttpException("file not exists"); break; case filesize($filePath) >= $access_media[$type] * 1024: throw new THttpException("file is too large"); break; } $token = WxApi::getAccessToken($accountID); $postData = array('media' => '@' . $filePath); $url = str_replace('[TOKEN]', $token, WX_UPLOAD_MEDIA_URL); $url = str_replace('[TYPE]', $type, $url); $request = Yii::app()->curl->run($url, $postData); $aResponse = WeixinApi::parseResponse($request, __FILE__, __LINE__); $model_media = new UploadMediaFile(); $model_media->accountid = $accountID; $model_media->mediaid = $aResponse['media_id']; $model_media->create_time = $aResponse['created_at']; $model_media->filepath = $filePath; $model_media->type = $type; $model_media->expire_time = $aResponse['created_at'] + 3600 * 24 * 3; $model_media->save(); return $model_media->ID; }
<?php include_once '../common/include-file.php'; include_once '../core/model.php'; include_once '../wxapi/WxApi.class.php'; $wxAccount = new Account(); $wxAccount = $wxAccount->getSingleAccount(); $appId = $wxAccount['appid']; $appSecret = $wxAccount['appsecret']; $rst = WxApi::delete_menu($appId, $appSecret); if ($rst->errcode == 0) { header("Location:" . $CONTEXT_PATH . "/wxcms/success.php?type=2"); } else { header("Location:" . $CONTEXT_PATH . "/wxcms/failure.php?type=2&errcode=" . $rst->errcode); }
public function sendMsg($request, $response) { /*{{{*/ $msg = $request->msg; DBC::requireNotEmptyString($msg, "消息不能为空!!!"); $wxUser = DAL::get()->find('WxUser', $request->wxUserId); DBC::requireTrue($wxUser instanceof WxUser, "WxUser不存在!!!"); WxApi::kefuTextMsg($wxUser, $msg); $toUser = $wxUser->nickname; WxMgrClient::getInstance()->addAdminReplyMsg($msg, $toUser); $response->setRedirect($_SERVER["HTTP_REFERER"]); }
<?php include_once '../common/include-file.php'; include_once '../wxapi/wxconsts.php'; include_once '../wxapi/WxApi.class.php'; $wxAccount = new Account(); $wxAccount = $wxAccount->getSingleAccount(); $appId = $wxAccount['appid']; $appSecret = $wxAccount['appsecret']; $gid = $_GET['gid']; $accountMenu = new AccountMenu(); $sql = ' select * from t_wxcms_account_menu where gid = ' . $gid . ' order by parentId , sort '; $querySet = $accountMenu->queryBySql($sql); $menuStr = prepareMenu($querySet); $rst = WxApi::create_menu($appId, $appSecret, $menuStr); if ($rst->errcode == 0) { $wxAccountGroup = new AccountMenuGroup(); $wxAccountGroup->updateById(array("id" => $gid, "enable" => 1)); header("Location:" . $CONTEXT_PATH . "/wxcms/success.php?type=1"); } else { header("Location:" . $CONTEXT_PATH . "/wxcms/failure.php?type=1&errcode=" . $rst->errcode); } function prepareMenu($querySet) { $menuArr = array(); $subMenuArr = array(); foreach ($querySet as $item) { if ($item['parentId'] == 0) { array_push($menuArr, $item); } else { if (empty($subMenuArr[$item['parentId']])) {
public function actionTest() { return; $request = Yii::app()->curl->run("http://clk.optaim.com/event.ng/Type=click&FlightID=201309&TargetID=sohu&Values=4960caa5,d64a93f7,0bd7d879,040f2666&AdID=1023788"); var_dump($request->getInfo()); $at = WxApi::getAccessToken(1); $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token={$at}"; $data = ' { "button":[ { "name":"车型选择", "sub_button":[ { "type":"view", "name":"全部车型", "url":"http://weixin.optaim.com/tpl/allcars.html" }, { "type":"view", "name":"尊选二手车", "url":"http://weixin.optaim.com/tpl/scar.html" }, { "type":"view", "name":"照片展示", "url":"http://weixin.optaim.com/tpl/pics.html" } ] }, { "name":"在线服务", "sub_button":[ { "type":"view", "name":"车主关怀", "url":"http://weixin.optaim.com/tpl/care.html" }, { "type":"view", "name":"预约保养", "url":"http://weixin.optaim.com/tpl/baoyang.html" }, { "type":"click", "name":"预约试驾", "key":"14_1_6" }] }, { "type":"view", "name":"进入官网", "url":"http://weixin.optaim.com/tpl/auto.html" }] } '; $a = Yii::app()->curl->run($url, $data); var_dump($a->getBody()); /* $abc = array('app_id'=>'1922874','app_secret'=>'40eae2780e80243bf0324b4557ee2fd8'); $request = Yii::app()->curl->run("http://adp.optaim.com/api/auth/access_token", $abc); $date = $request->getBody(); $a = json_decode($date, true); $abc = array('date'=>'2014-04-08','access_token'=>'4bf4ea6f23ef1df5df7f18878237752e9dac199ca42dced5c446ccf25eb5919a4ee19d228e7c844e26390a35b25d19d1789013c60cd2f6508f39413025782322'); $request = Yii::app()->curl->run("http://adp.optaim.com/api/report/hour", $abc); var_dump($request->getBody()); */ }
public static function delete_menu($appId, $appSecret) { $token = WxApi::getToken($appId, $appSecret); $deleteMenuUrl = WxApi::getDeleteMenuUrl($token); return WxApi::https_request($deleteMenuUrl); }
$q = $_GET["q"]; set_time_limit(0); error_reporting(0); //禁用错误报告 header('Content-Type:text/html;charset=utf-8 '); //设置URL编码头信息 require 'D:/xampp/htdocs/Registration/Model/wxApi.php'; require 'D:/xampp/htdocs/Registration/Model/dbModel.php'; //配置部门映射信息 $noToDepartment = array('1' => '净水潜流', '2' => '接入网', '3' => 'MBB', '4' => '标准专利', '5' => '算法', '6' => '系统技术', '7' => '北研', '8' => '二部', '14' => '公共', '19' => '未关注', '20' => '测试组'); $noToGender = array('0' => '未定义', '1' => '男性', '2' => '女性'); $noToStatus = array('0' => '任意', '1' => '已关注', '2' => '已禁用', '4' => '未关注'); $corpid = 'wxf2c246cabf47faa1'; $corpsecret = 'fM7FbqZlW7qrV0jRJQfhcfoSB6dcPJZ_7m4ARi892MhLPokADn9dZ2EL9S2FTwkD'; //获取全局唯一凭据ACCESS_TOKEN $wxApi = new WxApi(); $accessToken = $wxApi->wxAccessToken($corpid, $corpsecret); //获取部门列表 $departmentList = $wxApi->wxGetDepartmentList($accessToken); $departmentList = json_decode($departmentList, true); $departmentArr = $departmentList['department']; $departCount = count($departmentArr); $departmentId = '1'; $userOfDepartment = $wxApi->wxGetUserOfDepartment($accessToken, $departmentId, 1, 0); $allUserOfDepart = json_decode($userOfDepartment, true); $userNum = count($allUserOfDepart['userlist']); if ($q = "Synchronize") { //执行更新 //数据库操作 $dbTasks = new dbModel(); //删除表
* Date: 2015/12/17 * Time: 17:47 */ error_reporting(0); //禁用错误报告 header('Content-Type:text/html;charset=utf-8 '); //设置URL编码头信息 require 'D:/xampp/htdocs/Registration/Model/wxApi.php'; require 'D:/xampp/htdocs/Registration/Model/dbModel.php'; $noToDepartment = array('1' => '净水潜流', '2' => '接入网', '3' => 'MBB', '4' => '标准专利', '5' => '算法', '6' => '系统技术', '7' => '北研', '8' => '二部', '14' => '公共', '19' => '未关注', '20' => '测试组'); $noToGender = array('0' => '未定义', '1' => '男性', '2' => '女性'); $noToStatus = array('0' => '任意', '1' => '已关注', '2' => '已禁用', '4' => '未关注'); $htmlNode = ""; $corpid = 'wxf2c246cabf47faa1'; $corpsecret = 'fM7FbqZlW7qrV0jRJQfhcfoSB6dcPJZ_7m4ARi892MhLPokADn9dZ2EL9S2FTwkD'; $wxApi = new WxApi(); $accessToken = $wxApi->wxAccessToken($corpid, $corpsecret); $ticket = $_GET['ticket']; //ticket必须存在,否则跳到失败页面 if (!isset($ticket)) { //打印失败页面 $htmlNode .= "<!DOCTYPE html>\r\n <html>\r\n <head>"; $htmlNode .= " <meta charset='utf-8'>\r\n <meta name='viewport' content='initial-scale=1, maximum-scale=1, user-scalable=no'>\r\n <meta name='format-detection' content='telephone=no'>\r\n <title>" . $task_name . "</title>\r\n <link rel='stylesheet' href='../frozenui/css/frozen.css'>\r\n </head>"; $htmlNode .= "<body ontouchstart='' style='background-image: url(../frozenui/img/h5BG3.png)'>"; $htmlNode .= "<header class='ui-header ui-header-positive ui-border-b'>\r\n <h1>抱歉,这次签到未成功</h1>\r\n </header>"; $htmlNode .= "<section class='ui-container ui-center' style='margin-top: 20%'>"; $htmlNode .= "<div class='ui-avatar-lg'>\r\n <span style='background-image:url(" . $avatar . ")'></span>\r\n </div>"; $htmlNode .= "<div class='okToast'>\r\n <img src='../frozenui/img/warning.png'>\r\n </div>"; $htmlNode .= " <div class='ui-whitespace'>\r\n <p class='ui-txt-highlight'>Sorry~ " . $userName . ",请再试一次!</p>\r\n </div>"; $htmlNode .= "</section>\r\n <script src='../frozenui/lib/zepto.min.js'></script>\r\n <script src='../frozenui/js/frozen.js'></script>\r\n </body>\r\n </html>"; echo $htmlNode;
public function wxSubsCribedNoActionCrontab($request, $response) { /*{{{*/ $wxUserAdZeros = DAL::get()->find_all_by_activedegree('WxUser', '0'); foreach ($wxUserAdZeros as $wxUser) { $interval = time() - $wxUser->subscribe_time; error_log(print_r($interval, true) . " 111\n", 3, "/tmp/myerror.log"); if ($interval >= 21600 && $interval < 86400) { $wxArticle = DAL::get()->find_by_code('WxArticle', '1003'); echo WxApi::kefuNewsMsg($wxUser, array($wxArticle)); // WxClient::getInstance()->modifyWxUserActiveDegree($wxUser->id,'1'); } } $wxUserAdOnes = DAL::get()->find_all_by_activedegree('WxUser', '1'); foreach ($wxUserAdOnes as $wxUser) { $interval = time() - $wxUser->subscribe_time; error_log(print_r($interval, true) . " 222\n", 3, "/tmp/myerror.log"); if ($interval >= 86400 && $interval < 86400 * 2) { $wxArticle = DAL::get()->find_by_code('WxArticle', '1009'); echo WxApi::kefuNewsMsg($wxUser, array($wxArticle)); // WxClient::getInstance()->modifyWxUserActiveDegree($wxUser->id,'2'); } // error_log(print_r($wxUser->ctime, true)." 222\n",3,"/tmp/myerror.log"); } exit; }