private static function init_user_info() { $userinit = get_user_auth(); if (empty($userinit['id'])) { //注册用户 $userinit = empty(self::$weixin_post['fromusername']) ? wx_error('Sorry!用户标识为空') : register_weixin(true, self::$weixin_post['fromusername']); } //用户关注状态 if (empty($userinit['follow'])) { change_user_follow($userinit['fromusername']); } //注册用户昵称 if (preg_match("/^我叫/", self::$weixin_post['content'])) { $str = str_replace(" ", '', self::$weixin_post['content']); $nickname = str_replace('我叫', '', $str); set_nickname(self::$weixin_post['fromusername'], $nickname); } //强制绑定昵称 if (empty($userinit['nickname'])) { wx_success('发送“我叫”+您的昵称,交朋友更方便哦~'); } if ($userinit['status'] == 0) { wx_error('Sorry!您的账号已被冻结,请联系管理员......'); } if ($userinit['followercate_status'] == 0) { wx_error('Sorry!您所在的用户组【' . $userinit['followercate_title'] . '】已被冻结,请联系管理员......'); } /*用户资料初始化*/ global $_P; $_P = $userinit; }
private static function init_user_info() { $userinit = WxuserApi::get_infos_openid(self::$weixin_post['fromusername']); if (empty($userinit['id'])) { //注册用户 if (empty(self::$weixin_post['fromusername'])) { wx_error('Sorry!用户标识为空'); } else { $regStatus = WxuserApi::register_weixin(true, self::$weixin_post['fromusername']); if (false === $regStatus[0]) { wx_error($regStatus[1]); } else { $userinit = $regStatus[1]; } //新关注用户 Credits::ag_weixin_newregister($userinit['id']); } } //判断用户公众号归属 if (empty($userinit['tousername'])) { WxuserApi::update_info_openid($userinit['fromusername'], array('account_union' => self::$weixin_post['tousername'])); } //用户调试状态 if (in_array($userinit['followercate_title'], self::$admin_group)) { defined('WEIXIN_TRACE', TRUE); } //用户关注状态 if (empty($userinit['follow'])) { WxuserApi::update_follow($userinit['fromusername']); } //注册用户昵称 if (preg_match("/^我叫/", self::$weixin_post['content'])) { $nickname = str_replace('我叫', '', str_replace(" ", '', self::$weixin_post['content'])); //set_nickname(self::$weixin_post['fromusername'],$nickname ); $setStatus = WxuserApi::set_nickname(array(self::$weixin_post['fromusername'] => $nickname)); if ($setStatus) { wx_success($nickname . '小主,更新昵称成功!'); } else { wx_error('更新昵称失败!'); } } //强制绑定昵称 if (empty($userinit['nickname'])) { wx_success('发送“我叫”+您的昵称,交朋友更方便哦~'); } if ($userinit['status'] == 0) { wx_error('Sorry!您的账号已被冻结,请联系管理员......'); } if ($userinit['followercate_status'] == 0) { wx_error('Sorry!您所在的用户组【' . $userinit['followercate_title'] . '】已被冻结,请联系管理员......'); } /*用户资料初始化*/ global $_P; $_P = $userinit; //用户自动升级 Credits::init($userinit['id']); }
public function index($param) { global $_W, $_P; //获取插件配置 $config = Amango_Addons_Config('Sharephotos'); $nowtime = time(); if (!empty($_W['picurl'])) { //限制每天分享的图片数量 $todaystart = strtotime(date('Y-m-d 00:00:00', $nowtime)); $todayend = strtotime(date('Y-m-d 23:59:59', $nowtime)); $condition = array('from' => $_P['fromusername'], 'sharetime' => array('egt', $todaystart), 'sharetime' => array('elt', $todayend)); $hassharenums = M('Addonssharepics')->where($condition)->count(); if ($hassharenums >= $config['shareitmes']) { $this->assign('Text', "[可怜]亲~您今天已分享了" . $config['shareitmes'] . "次\n请明天再分享吧!"); $this->display(); } $article[0] = array('Title' => "分享图片成功", 'Description' => "请回复下你对这张照片的评价吧~", 'PicUrl' => $_W['picurl'], 'Url' => $_W['picurl']); //锁定图片分享模式 $this->lock('model', 'Sharephotos'); //缓存微信图片链接 $this->cache('sharepicurl', $_W['picurl']); $this->assign('Duotw', $article); $this->display(); } else { //判断是否存在模式锁定 $lastmodel = $this->locked('model'); $urlcache = $this->cache('sharepicurl'); if (!empty($lastmodel) && !empty($_W['content']) && !empty($urlcache)) { //远程保存图片至本地数据库 $urldown = $this->savepics($urlcache); //将照片地址写入数据库 初始化浏览量为1 $data = array('from' => $_P['fromusername'], 'nickname' => $_P['nickname'], 'picurl' => $urldown, 'sharetime' => $nowtime, 'content' => $_W['content'], 'views' => 1, 'status' => $config['random']); M('Addonssharepics')->add($data); //清除缓存 $this->cache('sharepicurl', NULL); //清除模块锁定 $this->lock('model', ''); //评价照片 $commonurl = $this->create_loginurl('index'); $article[0] = array('Title' => "分享图片成功", 'Description' => "分享理由:" . $_W['content'], 'PicUrl' => $urlcache, 'Url' => $commonurl); $this->assign('Duotw', $article); $this->display(); } else { //展示图片分享内容 底部附带分享方法 $article[0] = array('Title' => "精彩美图,随手分享", 'Description' => "", 'PicUrl' => str_replace('./', 'http://' . $_SERVER['HTTP_HOST'] . '/', ONETHINK_ADDON_PATH . 'Sharephotos/Public/banner.jpg'), 'Url' => $this->create_loginurl('index')); $gebi = array_merge($article, $this->show(6)); $this->assign('Duotw', $gebi); $this->display(); } } wx_error(json_encode($_W)); die; wx_success('Hello World!这是图吧的微信Bundle!'); }
public function _empty($type) { wx_error('请联系管理员添加【' . $type . '】请求类型吧~'); }
/** * 执行行为 * @return echo id */ function excute_behavior($behavior) { if (!empty($behavior)) { wx_error('执行行为'); } }
protected function train($param) { global $_W; $_W['content'] = str_replace('公交', '', $_W['content']); $_W['content'] = str_replace(' ', '', $_W['content']); $userpost = explode('到', $_W['content']); $userfrom = empty($userpost[0]) ? $config['origin'] : $userpost[0]; $userto = empty($userpost[1]) ? $config['region'] : $userpost[1]; if (empty($userto)) { wx_error("亲:目的地不能为空哦\n公交查询格式\n公交**到**"); } //获取该插件配置参数 $config = Amango_Addons_Config(); $config['trainak'] || wx_error('请联系站长填写公交API的密匙'); $config['where'] || wx_error('请联系站长填写一个默认所在的省市,例如:石狮,厦门'); $direc = 'http://api.map.baidu.com/direction/v1?mode=transit&origin=' . urlencode($userfrom) . '&destination=' . urlencode($userto) . '®ion=' . urlencode($config['where']) . '&output=json&ak=' . $config['trainak']; $Fisr_result = file_get_contents($direc); $Fisrresult = json_decode($Fisr_result, true); $errorMsg[2] = '参数错误'; $errorMsg[5] = '权限或配额校验失败'; if ($Fisrresult['status'] != 0) { wx_error($errorMsg[$Fisrresult['status']]); } if ($Fisrresult['type'] == 1) { $resultStr = ''; foreach ($Fisrresult['result']['origin'] as $key => $value) { $result .= $value['name'] . "\n"; } wx_error("亲:公交查询格式\n********到********\n出发地不明确,请输入下列地址\n" . $result); } if ($Fisrresult['type'] == 2) { $resultStr = ''; $resultinfo = ''; foreach ($Fisrresult['result']['routes'] as $key => $value) { $result .= "--路线" . ($key + 1) . "-----\n"; $resultinfo = ''; foreach ($value['scheme'][0]['steps'] as $ke => $va) { $resultinfo .= $ke + 1 . "):" . strip_tags($va[0]['stepInstruction']) . "\n"; } $result .= $resultinfo; if ($key == 1) { break; } } $replycontext['Content'] = "【公交】" . $userfrom . "=>" . $userto . "\n" . $result; $this->assign('Text', $replycontext); $this->display(); } wx_error("亲:目的地不能为空哦\n公交查询格式\n公交**到**"); }
public function sendOther($school, $to) { //$to 可能为多用户 return true; wx_error($school . '|' . $to); }
public function setCloud($apiinfo) { global $_W; global $_K; $header[] = "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"; $header[] = "Content-Type: text/xml; charset=utf-8"; // 定义content-type为xml $ch = curl_init(); // 初始化curl //判断提交方式 //POST远程 if ($apiinfo['webuntil_type'] == 'post') { if ($apiinfo['webuntil_backtype'] == 'string') { $post_data = http_build_query($apiinfo['webuntil_param']); } else { $post_data = $GLOBALS['HTTP_RAW_POST_DATA']; //判断是否过滤关键词 仅对文本请求 匹配规则为开头匹配 if ($_W['msgtype'] == 'text' && $apiinfo['webuntil_sigtype'] == 'yes') { $content = trim(str_replace($_K['keyword_content'], '', $_W['content'])); $post_data = str_replace('<Content><![CDATA[' . $_W['content'] . ']]></Content>', '<Content><![CDATA[' . $content . ']]></Content>', $post_data); } } $url = $apiinfo['webuntil_url']; curl_setopt($ch, CURLOPT_POST, 1); // 设置为POST方式 curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); // POST数据 } else { //GET 请求 $getinfo = $apiinfo['webuntil_param']; $getinfo['keyword'] = $_W['msgtype'] == 'text' && $apiinfo['webuntil_sigtype'] == 'yes' ? trim(str_replace($_K['keyword_content'], '', $_W['content'])) : $_W['content']; //参数 $get_data = http_build_query($getinfo); $blindurl = false === strpos($apiinfo['webuntil_url'], '?') ? '?' . $get_data : $get_data; $url = $apiinfo['webuntil_url'] . $blindurl; curl_setopt($ch, CURLOPT_POST, 0); // 设置为POST方式 } curl_setopt($ch, CURLOPT_URL, $apiinfo['webuntil_url']); // 设置链接 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 设置是否返回信息 curl_setopt($ch, CURLOPT_HTTPHEADER, $header); // 设置HTTP头 $response = curl_exec($ch); // 接收返回信息 // if($apiinfo['webuntil_tag']==0){ // echo $response;die; // } if (curl_errno($ch)) { // 出错则显示错误信息 wx_error(curl_error($ch)); } curl_close($ch); $response = str_replace("<Content><![CDATA[]]></Content>", '', $response); //回复处理 判断是否是XML $string = simplexml_load_string($response, 'SimpleXMLElement', LIBXML_NOCDATA); if (!empty($string)) { // //XML转成完整数组 $data = json_decode(json_encode($string, JSON_FORCE_OBJECT), TRUE); foreach ($data as $key => $value) { $packet[strtolower($key)] = $value; } $type = $packet['msgtype']; unset($packet['fromusername'], $packet['tousername'], $packet['createtime'], $packet['msgtype']); //支持多图文的TAG switch (strtolower($type)) { case 'news': $xmlarray = $packet['articles']['item']; $nums = $packet['articlecount']; if ($nums == 1) { if (!is_string($xmlarray['PicUrl'])) { $xmlarray['PicUrl'] = ''; } $rearray[0] = $xmlarray; $info = $apiinfo['webuntil_tag'] == 1 ? Factory('Dantw')->load($rearray)->select() : Factory('Dantw')->load($rearray)->deltag('*')->select(); $infotype = 'Dantw'; } else { $info = $apiinfo['webuntil_tag'] == 1 ? Factory('Duotw')->load($xmlarray)->select() : Factory('Duotw')->load($xmlarray)->deltag('*')->select(); $infotype = 'Duotw'; } break; case 'text': $xmlarray['Content'] = $packet['content']; $info = $apiinfo['webuntil_tag'] == 1 ? Factory('Text')->load($xmlarray)->select() : Factory('Text')->load($xmlarray)->deltag('*')->select(); $infotype = 'Text'; break; default: $info = $xml; $infotype = ''; break; } $xmlinfo = array('type' => $infotype, 'info' => $info); } else { $newresponse = self::is_json($response); if (is_array($newresponse)) { $type = ucfirst($newresponse['msgtype']); unset($newresponse['msgtype']); //$info = Factory($type)->load($newresponse)->select(); $info = $apiinfo['webuntil_tag'] == 1 ? Factory($type)->load($newresponse)->select() : Factory($type)->load($newresponse)->deltag('*')->select(); $xmlinfo = array('type' => $type, 'info' => $info); } else { //$info = Factory('Text')->load($response)->select(); $info = $apiinfo['webuntil_tag'] == 1 ? Factory('Text')->load($response)->select() : Factory('Text')->load($response)->deltag('*')->select(); $xmlinfo = array('type' => 'text', 'info' => $info); } } //设置缓存 if ($apiinfo['webuntil_cache'] > 0) { excute_cache($apiinfo['id'], $xmlinfo, $apiinfo['webuntil_cache'], $is_echo = false); } return $xmlinfo; }
public final function trace($errormsg) { global $_G; if ($_G['Weixin_trace']) { wx_error($errormsg); } else { $this->autoreply('auto'); } }
public function setInfo($type, $detail, $originalxml, $denytag, $otherparam) { $arraydetail = unserialize($detail); $readparam = explode(',', $arraydetail['neiron']); switch ($arraydetail['type']) { case 'fastarticles': $readfields = D('Flycloud')->where(array('data_type' => 'category', 'data_table' => $readparam[0]))->find(); //读取详情 判断是否为最新或随机 if (strtolower($readparam[1]) == 'rand') { $lists = api('Category/get_category_rand', array('cateid' => $readparam[0], 'field' => $readfields['data_fields'], 'limit' => $arraydetail['num'])); } if (strtolower($readparam[1]) == 'news') { $lists = api('Category/get_category_news', array('cateid' => $readparam[0], 'field' => $readfields['data_fields'], 'limit' => $arraydetail['num'])); } $newlist = array(); foreach ($lists as $key => $value) { $newlist[] = array_values($value); } $hassource = count($newlist); if ($hassource === 0) { wx_error('Sorry!暂无相关内容'); } $writetype = strtoupper($readparam[1]); $replacedate = array(); for ($i = 0; $i <= $arraydetail['num'] - 1; $i++) { $replacedate[$writetype . $i . '0'] = $newlist[$i][0]; $replacedate[$writetype . $i . '1'] = get_cover_pic($newlist[$i][1]); $replacedate[$writetype . $i . '2'] = $newlist[$i][2]; $replacedate[$writetype . $i . '3'] = Amango_U('Article/detail?id=' . $newlist[$i][3]); } $newcontent = strtr($originalxml, $replacedate); //wx_error(base64_encode($newcontent)); //wx_error(json_encode($replacedate)); return array('type' => 'Duotw', 'info' => $newcontent); break; case 'articles': $newcontent = self::creatArticles($type, $detail, $originalxml, $denytag, $otherparam); return array('type' => 'Duotw', 'info' => $newcontent); break; default: wx_error('多图文回复中未知类型~'); break; } }