public function getAccessToken() { global $_W; load()->classs('weixin.account'); $accObj = new WeixinAccount(); $access_token = $accObj->fetch_available_token(); return $access_token; }
private function getAccessToken() { load()->func('communication'); load()->classs('weixin.account'); $accObj = new WeixinAccount(); $access_token = $accObj->fetch_available_token(); return $access_token; }
public function fetchAccess($force = false) { global $_W; if ($force) { $row = array(); $row['access_token'] = ''; pdo_update('account_wechats', $row, array('acid' => $_W['acid'])); } load()->classs('weixin.account'); $accObj = WeixinAccount::create($this->account['acid']); return $accObj->fetch_token(); }
public function doMobileNew() { global $_W, $_GPC; $a = !empty($_GPC['a']) ? $_GPC['a'] : 'rent'; load()->func('file'); load()->func('tpl'); $setting = $this->get_sysset($weid); $wxid = !empty($_GPC['wxid']) ? $_GPC['wxid'] : $_W['fans']['from_user']; $data = array('weid' => $_W['uniacid'], 'title' => trim($_GPC['title']), 'price' => trim($_GPC['price']), 'square_price' => trim($_GPC['square_price']), 'area' => trim($_GPC['area']), 'house_type' => $_GPC['house_type'], 'floor' => trim($_GPC['floor']), 'orientation' => $_GPC['orientation'], 'createtime' => TIMESTAMP, 'type' => trim($_GPC['type']), 'recommed' => 0, 'contacts' => trim($_GPC['contacts']), 'phone' => trim($_GPC['phone']), 'introduction' => trim($_GPC['introduction']), 'openid' => $wxid, 'thumb1' => $_GPC['thumb1'], 'thumb2' => $_GPC['thumb2'], 'thumb3' => $_GPC['thumb3'], 'thumb4' => $_GPC['thumb4'], 'brokerage' => $_GPC['brokerage'], 'location_p' => trim($_GPC['location_p']), 'location_c' => trim($_GPC['location_c']), 'location_a' => trim($_GPC['location_a']), 'place' => trim($_GPC['place']), 'lng' => trim($_GPC['lng']), 'lat' => trim($_GPC['lat'])); if ($setting && $setting['isadjuest'] == 0) { $data['status'] = 1; } else { $data['status'] = 0; } if ($a == 'rent') { load()->classs('weixin.account'); $accObj = WeixinAccount::create($_W['acid']); if ($_W['ispost']) { pdo_insert('amouse_house', $data); if ($setting && !empty($setting['openid'])) { $orderinfo .= '--------------------\\n'; $orderinfo .= "您有一条新的租售房产提交信息\n"; $orderinfo .= "房产名称:{$data['title']}\n"; $orderinfo .= "房产地址:{$data['place']}\n"; $orderinfo .= "联系电话:{$data['phone']}\n"; $send['msgtype'] = 'text'; $send['text'] = array('content' => urlencode($orderinfo)); $send['touser'] = trim($setting['openid']); $accObj->sendCustomNotice($send); } message('提交房产信息成功!', $this->createMobileUrl('index', array('type' => $_GPC['type'])), 'success'); } include $this->template('house/rent_new'); } elseif ($a = 'house') { if ($_W['ispost']) { pdo_insert('amouse_house', $data); if ($setting && !empty($setting['openid'])) { $orderinfo .= '--------------------\\n'; $orderinfo .= "您有一条新的出售,求购房产提交信息\n"; $orderinfo .= "房产名称:{$data['title']}\n"; $orderinfo .= "房产地址:{$data['place']}\n"; $orderinfo .= "联系电话:{$data['phone']}\n"; $send['msgtype'] = 'text'; $send['text'] = array('content' => urlencode($orderinfo)); $send['touser'] = trim($setting['openid']); $accObj->sendCustomNotice($send); } message('提交房产信息成功!', $this->createMobileUrl('index', array('type' => $_GPC['type'])), 'success'); } include $this->template('house/house_new'); } }
private function getUserInfo($o) { global $_W, $_GPC; $user = ''; load()->model('account'); load()->func('communication'); if (empty($o)) { message('重要参数丢失..', '', 'error'); exit; } if (empty($_W['account']['key']) || empty($_W['account']['secret'])) { return $user; } else { //$access_token = account_weixin_token($_W['account']); load()->classs('weixin.account'); $access_token = WeixinAccount::create($_W['uniacid'])->fetch_token(); $content = ihttp_get(sprintf('https://api.weixin.qq.com/cgi-bin/user/info?access_token=%s&openid=%s&lang=zh_CN', $access_token, $o)); if ($content['code'] != 200) { //网络异常.. //message('抱歉网络不稳..'); return $user; } else { $record = @json_decode($content['content'], true); if ($record['errcode'] != 0) { //各种传参错误造成的不能拉取用户信息直接返回fans表用户信息 //message('拉取失败..');//调试用查看报错提示 return $user; } } $record = @json_decode($content['content'], true); $user = $record; unset($record); $user['nickname'] = emoji_html_to_unified($user['nickname']); return $user; } }
public function getClientUserInfo($openid) { global $_W; if (!empty($openid) && ($_W['account']['level'] == 3 || $_W['account']['level'] == 4)) { load()->classs('weixin.account'); $accObj = WeixinAccount::create($_W['acid']); $access_token = $accObj->fetch_token(); if (empty($access_token)) { message("获取accessToken失败"); } $userInfo = $this->oauth->getUserInfo($access_token, $openid); MonUtil::setClientCookieUserInfo($userInfo, $this::$USER_COOKIE_KEY); return $userInfo; } }
private function copyMedia($type, $arg) { global $_GPC, $_W; load()->func('file'); load()->func('communication'); if (empty($arg) || empty($type)) { return ''; } if (empty($arg) || empty($type)) { return ''; } if (strtoupper($type) == 'IMG') { $dat = ihttp_get($arg); if ($dat['code'] == 200) { $imgtype = '.' . substr($dat['headers']['Content-Type'], intval(strpos($dat['headers']['Content-Type'], '/')) + 1); if (!empty($imgtype)) { $filename = TIMESTAMP . $imgtype; $bool = file_write('/on3_voxpic/img/' . $filename, $dat['content']); if ($bool) { return 'on3_voxpic/img/' . $filename; } } } return ''; } elseif (strtoupper($type) == 'VOX') { load()->classs('weixin.account'); $wxObj = WeixinAccount::create($_W['uniacid']); $access_token = $wxObj->fetch_token(); $url = 'http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=%s&media_id=%s'; $source = sprintf($url, $access_token, $arg); $dat = ihttp_get($source); if ($dat['code'] == 200) { $filename = TIMESTAMP . '.amr'; if (!empty($dat['content'])) { $bool = file_write('/on3_voxpic/vox/' . $filename, $dat['content']); if ($bool) { return 'on3_voxpic/vox/' . $filename; } } } return ''; } return ''; }
$sql = "SELECT * FROM " . tablename('meepo_begging') . " WHERE uid = :uid limit 1"; $params = array(':uid' => $uid); $begging = pdo_fetch($sql, $params); if (empty($begging)) { pdo_insert('meepo_begging', array('uid' => $uid, 'uniacid' => $_W['uniacid'], 'money' => 0, 'createtime' => time())); } } $user = mc_fetch($uid); if (empty($user['avatar'])) { load()->func('communication'); if (empty($_W['acid'])) { $_W['acid'] = pdo_fetchcolumn("SELECT acid FROM " . tablename('mc_mapping_fans') . " WHERE uniacid='{$_W['uniacid']}' AND openid = '{$_W['openid']}'"); } $account = account_fetch($_W['acid']); load()->classs('weixin.account'); $accObj = WeixinAccount::create($_W['account']['acid']); $account['access_token']['token'] = $accObj->fetch_token(); if (empty($account['access_token']['token'])) { return false; } $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $account['access_token']['token'] . "&openid=" . $_W['openid'] . "&lang=zh_CN"; $re = ihttp_get($url); if ($re['code'] == 200) { $userinfo = json_decode($re['content'], true); if ($userinfo['errcode'] == '41001') { return $this->respText($userinfo['errmsg']); } $user['nickname'] = stripslashes($userinfo['nickname']); $user['avatar'] = rtrim($userinfo['avatar'], '0') . 132; $user['gender'] = $userinfo['sex']; $user['nationality'] = $userinfo['country'];
/** * * @param $openid */ public function setClientUserInfo($openid) { global $_W; if (!empty($openid)) { load()->classs('weixin.account'); $accObj = WeixinAccount::create($_W['account']); $access_token = $accObj->fetch_token(); if (empty($access_token)) { message("获取accessToken失败"); } $userInfo = $this->oauth->getUserInfo($access_token, $openid); if (!empty($userInfo)) { $cookie = array(); $cookie['openid'] = $userInfo['openid']; $cookie['nickname'] = $userInfo['nickname']; $cookie['headimgurl'] = $userInfo['headimgurl']; $session = base64_encode(json_encode($cookie)); isetcookie('__singnuser', $session, 24 * 3600 * 365); } return $userInfo; } }
public function getAccessToken() { global $_W; load()->classs('weixin.account'); $accObj = WeixinAccount::create($_W['acid']); $access_token = $accObj->fetch_token(); return $access_token; }
public function sendmessage($content, $openid) { global $_W, $_GPC; $weid = $_W['weid']; $cfg = $this->module['config']; $appid = $cfg['appid']; $secret = $cfg['secret']; $img = $_W['attachurl'] . $cfg['kefuimg']; $id = $_W['openid']; //当前粉丝$openid为发送者 $res = $this->getusers($weid, $id); load()->classs('weixin.account'); $accObj = WeixinAccount::create($_W['account']['acid']); $access_token = $accObj->fetch_token(); $token2 = $access_token; $title = $res['nickname'] . '给你发来新消息了!'; $fans = pdo_fetch('SELECT salt,acid,openid FROM ' . tablename('mc_mapping_fans') . ' WHERE uniacid = :uniacid AND openid = :openid', array(':uniacid' => $weid, ':openid' => $openid)); $pass['time'] = TIMESTAMP; $pass['acid'] = $fans['acid']; $pass['openid'] = $fans['openid']; $pass['hash'] = md5("{$fans['openid']}{$pass['time']}{$fans['salt']}{$_W['config']['setting']['authkey']}"); $auth = base64_encode(json_encode($pass)); $vars = array(); $vars['__auth'] = $auth; $vars['forward'] = base64_encode($this->createMobileUrl('hitmail', array('toname' => $res['nickname'], 'toopenid' => $id))); $url2 = $_W['siteroot'] . 'app/' . murl('auth/forward', $vars); $data = '{ "touser":"******", "msgtype":"news", "news":{ "articles": [ { "title":"' . $title . '", "description":"' . $title . '", "url":"' . $url2 . '", "picurl":"' . $img . '", } ] } }'; $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" . $token2; load()->func('communication'); $it = ihttp_post($url, $data); }
public function doMobileindex() { global $_GPC, $_W; $rid = intval($_GPC['rid']); $uniacid = $_W['uniacid']; $acid = $_W['acid']; $fansID = $_W['member']['uid']; $running = true; if ($_W['account']['level'] < 4) { $from_user = authcode(base64_decode($_GPC['from_user']), 'DECODE'); } else { $from_user = $_W['openid']; } $page_from_user = base64_encode(authcode($from_user, 'ENCODE')); if (empty($rid)) { message('抱歉,参数错误!', '', 'error'); } $reply = pdo_fetch("select * from " . tablename('stonefish_planting_reply') . " where rid = :rid order by `id` desc", array(':rid' => $rid)); if ($reply == false) { message('抱歉,活动已经结束,下次再来吧!', '', 'error'); } //种子ID $seedid = $reply['seedid']; //种子ID //兑奖参数重命名 $isfansname = explode(',', $reply['isfansname']); //兑奖参数重命名 $share = pdo_fetch("select * from " . tablename('stonefish_planting_share') . " where rid = :rid and acid = :acid", array(':rid' => $rid, ':acid' => $acid)); //首页广告显示控制 if ($reply['homepictime'] > 0) { if ($_COOKIE["stonefish_planting_homepictime"] <= time()) { setcookie("stonefish_planting_homepictime", time() + 3600 * 24, time() + 3600 * 24); include $this->template('homepictime'); exit; } } //首页广告显示控制 if (empty($from_user)) { //301跳转 if (!empty($share['share_url'])) { header("HTTP/1.1 301 Moved Permanently"); header("Location: " . $share['share_url'] . ""); exit; } echo "系统出错:无法获取Openid,也没有设置关注引导页"; exit; } else { //查询是否为关注用户 if ($_W['account']['level'] < 4) { $follow = pdo_fetchcolumn("SELECT follow FROM " . tablename('mc_mapping_fans') . " Where openid=:openid and uniacid=:uniacid and acid=:acid ORDER BY `fanid` DESC", array(":openid" => $from_user, ":uniacid" => $uniacid, ":acid" => $acid)); } else { load()->classs('weixin.account'); $accObj = WeixinAccount::create($acid); $access_token = $accObj->fetch_token(); load()->func('communication'); $oauth2_code = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $access_token . "&openid=" . $from_user . "&lang=zh_CN"; $content = ihttp_get($oauth2_code); $token = @json_decode($content['content'], true); $follow = $token['subscribe']; } if ($follow == 0) { if (!empty($share['share_url'])) { header("HTTP/1.1 301 Moved Permanently"); header("Location: " . $share['share_url'] . ""); exit; } echo "系统出错:没有关注,也没有设置关注引导页"; exit; } //获得用户资料 if (empty($fansID)) { $fansID = pdo_fetchcolumn("SELECT uid FROM " . tablename('mc_mapping_fans') . " Where openid=:openid and uniacid=:uniacid and acid=:acid ORDER BY `fanid` DESC", array(":openid" => $from_user, ":uniacid" => $uniacid, ":acid" => $acid)); } $profile = mc_fetch($fansID, array('avatar', 'nickname', 'realname', 'mobile', 'qq', 'email', 'address', 'gender', 'telephone', 'idcard', 'company', 'occupation', 'position')); if ($_W['account']['level'] < 4) { if (empty($profile['avatar'])) { $profile['avatar'] = '../addons/stonefish_planting/template/images/avatar.jpg'; } if (empty($profile['nickname'])) { $profile['nickname'] = '匿名'; } } else { if (empty($profile['avatar'])) { $profile['avatar'] = $token['headimgurl']; mc_update($fansID, array('avatar' => $token['headimgurl'])); } if (empty($profile['nickname'])) { $profile['nickname'] = $token['nickname']; mc_update($fansID, array('nickname' => $token['nickname'])); } } //获得用户资料 //是否领取种子 $fans = pdo_fetch("SELECT * FROM " . tablename('stonefish_planting_fans') . " WHERE rid = '" . $rid . "' and fansID='" . $fansID . "' and from_user='******'"); if (empty($fans)) { $running = false; $msg = '还没有领取过种子'; $isfansh = 260; $ziduan = array('realname', 'mobile', 'qq', 'email', 'address', 'gender', 'telephone', 'idcard', 'company', 'occupation', 'position'); foreach ($ziduan as $ziduans) { if ($reply['is' . $ziduans]) { ${$ziduans} = true; $isfansh += 50; } } if ($realname || $mobile || $qq || $email || $address || $gender || $telephone || $idcard || $company || $occupation || $position) { $isfans = true; $isfansh += 72; } else { $isfansh = 260; } } else { //查询种子状态并更新一下助力量 $sharenum = pdo_fetchcolumn("SELECT sum(viewnum) FROM " . tablename('stonefish_planting_data') . " WHERE rid = '" . $rid . "' and fromuser='******'"); if (empty($sharenum)) { $sharenum = 0; } $seed = pdo_fetch("SELECT * FROM " . tablename('stonefish_planting_seed') . " WHERE id = '" . $seedid . "'"); for ($i = 1; $i <= 8; $i++) { if ($seed['seed0' . $i] <= $sharenum) { $seednum = $i - 1; $seedimg = toimage($seed['seedimg0' . $i]); $seed_num = $i; } } pdo_update('stonefish_planting_fans', array('sharenum' => $sharenum), array('id' => $fans['id'])); //查询种子状态并更新一下助力量 } //是否领取种子 //查询种子生长级别以及是否有机会抽奖 $choujiang = 0; //默认没有抽奖机会 $award = pdo_fetch("SELECT * FROM " . tablename('stonefish_planting_award') . " WHERE rid = '" . $rid . "' and fid = '" . $fans['id'] . "' and from_user='******' and shengzhangid = '" . $seed_num . "'"); if ($seed_num >= $reply['award_times'] && empty($award) && $fans['choujiang'] != $seed_num) { $choujiang = pdo_fetchcolumn("SELECT count(id) FROM " . tablename('stonefish_planting_prize') . " WHERE prizetotal>prizedraw and sharenum <= '" . $seed_num . "'"); } //查询种子生长级别以及是否有机会抽奖 //是否中奖 $myaward = pdo_fetch("SELECT * FROM " . tablename('stonefish_planting_award') . " WHERE rid = '" . $rid . "' and fid = '" . $fans['id'] . "' and from_user='******'"); //是否中奖 //增加浏览次数 pdo_update('stonefish_planting_reply', array('viewnum' => $reply['viewnum'] + 1), array('id' => $reply['id'])); //查询是活动定义的次数还是商户赠送次数 if ($reply['opportunity'] == 1) { //商家赠送机会 if (empty($profile['mobile'])) { message('还没有注册成为会员,无法进入活动', url('entry//member', array('m' => 'stonefish_member', 'url' => url('entry//index', array('m' => 'stonefish_planting', 'rid' => $rid)))), 'error'); exit; } $doings = pdo_fetch("SELECT awardcount,districtid,status FROM " . tablename('stonefish_branch_doings') . " WHERE rid = " . $rid . " and mobile='" . $profile['mobile'] . "' and uniacid='" . $uniacid . "'"); if (!empty($doings)) { if ($doings['status'] < 2) { $running = false; $msg = '抱歉,您的领取种子资格正在审核中'; } else { if ($doings['awardcount'] == 0) { $running = false; $msg = '抱歉,您的领取种子资格正在加急审核中'; } } //查询网点资料 $business = pdo_fetch("SELECT * FROM " . tablename('stonefish_branch_business') . " WHERE id=" . $doings['districtid'] . ""); //更新网点记录到会员中心表 pdo_update('mc_members', array('districtid' => $doings['districtid']), array('uid' => $fansID)); } else { $running = false; $msg = '抱歉,您的还未获得领取种子资格'; } } elseif ($reply['opportunity'] == 2) { $creditnames = array(); $unisettings = uni_setting($uniacid, array('creditnames')); foreach ($unisettings['creditnames'] as $key => $credit) { if ($reply['credit_type'] == $key) { $creditnames = $credit['title']; break; } } //积分购买机会 $credit = mc_credit_fetch($fansID, array($reply['credit_type'])); $credit_times = intval($credit[$reply['credit_type']] / $reply['credit_times']); if ($credit_times == 0) { $running = false; $msg = '抱歉,您的' . $creditnames . '不足以购买领取种子资格'; } } //查询是活动定义的次数还是商户赠送次数 } //查询种子总数以及可中奖总数 是否还有奖品 $prizenum = pdo_fetchcolumn("SELECT count(id) FROM " . tablename('stonefish_planting_award') . " WHERE uniacid='" . $uniacid . "' AND rid= '" . $rid . "' and status>0"); if ($prizenum >= $reply['total_num']) { //已没有奖品可发放了 $running = false; $msg = '所有奖品都发放完了,下次早点来哟!'; } //查询种子总数以及可中奖总数 是否还有奖品 //中奖用户列表 $zjmd = pdo_fetchall("SELECT prizetype,prizename,from_user FROM " . tablename('stonefish_planting_award') . " WHERE uniacid= :uniacid AND rid = :rid order by `id` desc LIMIT " . $reply['awardnum'] . '', array(':uniacid' => $uniacid, ':rid' => $rid)); foreach ($zjmd as &$zjmds) { $zjmds['realname'] = pdo_fetchcolumn("SELECT realname FROM " . tablename('stonefish_planting_fans') . " WHERE rid = :rid and uniacid=:uniacid and from_user = :from_user", array(':rid' => $rid, ':uniacid' => $uniacid, ':from_user' => $zjmds['from_user'])); $seedid = pdo_fetchcolumn("SELECT seedid FROM " . tablename('stonefish_planting_reply') . " WHERE rid = :rid and uniacid=:uniacid", array(':rid' => $rid, ':uniacid' => $uniacid)); $zjmds['zhongzi'] = pdo_fetchcolumn("SELECT seedname FROM " . tablename('stonefish_planting_seed') . " WHERE id = :id", array(':id' => $seedid)); } //中奖用户列表 //分享信息 $sharelink = $_W['siteroot'] . 'app/' . $this->createMobileUrl('share', array('rid' => $rid, 'uid' => $fans['id'])); $sharetitle = empty($share['share_title']) ? '欢迎参加种植活动' : $share['share_title']; $sharedesc = empty($share['share_desc']) ? '亲,欢迎参加种植活动,祝您好运哦!!' : str_replace("\r\n", " ", $share['share_desc']); $sharetitle = $this->get_share($uniacid, $rid, $from_user, $sharetitle); $sharedesc = $this->get_share($uniacid, $rid, $from_user, $sharedesc); if (!empty($share['share_imgurl'])) { $shareimg = toimage($share['share_imgurl']); } else { $shareimg = toimage($reply['start_picurl']); } include $this->template('index'); }
public function doMobileRegistMember() { global $_W; load()->func('communication'); if (empty($_W['acid'])) { $_W['acid'] = pdo_fetchcolumn("SELECT acid FROM " . tablename('mc_mapping_fans') . " WHERE uniacid='{$_W['uniacid']}' AND openid = '{$_W['openid']}'"); } $account = account_fetch($_W['acid']); load()->classs('weixin.account'); $accObj = WeixinAccount::create($_W['account']['acid']); $account['access_token']['token'] = $accObj->fetch_token(); if (empty($account['access_token']['token'])) { return false; } $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $account['access_token']['token'] . "&openid=" . $_W['openid'] . "&lang=zh_CN"; $re = ihttp_get($url); if ($re['code'] == 200) { $userinfo = json_decode($re['content'], true); if ($userinfo['errcode'] == '41001') { } } $rec['tag'] = base64_encode($userinfo); $default_groupid = pdo_fetchcolumn('SELECT groupid FROM ' . tablename('mc_groups') . ' WHERE uniacid = :uniacid AND isdefault = 1', array(':uniacid' => $_W['uniacid'])); $data = array('uniacid' => $_W['uniacid'], 'email' => md5($_W['openid']) . '@012wz.com', 'salt' => random(8), 'groupid' => $default_groupid, 'createtime' => TIMESTAMP, 'nickname' => stripslashes($userinfo['nickname']), 'avatar' => trim($userinfo['headimgurl']), 'gender' => $userinfo['sex'], 'nationality' => $userinfo['country'], 'resideprovince' => $userinfo['province'] . '省', 'residecity' => $userinfo['city'] . '市'); $data['password'] = md5($message['from'] . $data['salt'] . $_W['config']['setting']['authkey']); pdo_insert('mc_members', $data); $rec['uid'] = pdo_insertid(); pdo_update('mc_mapping_fans', $rec, array('uniacid' => $_W['uniacid'], 'openid' => $_W['openid'])); _mc_login(array('uid' => intval($rec['uid']))); if (empty($_W['member']['uid'])) { return false; } else { return $_W['member']['uid']; } }
public function doMobileAdd() { global $_W, $_GPC; load()->func('file'); load()->func('tpl'); $categorys = pdo_fetchall("SELECT * FROM" . tablename($this->table_category) . "WHERE weid='{$_W['weid']}'"); $data = array('weid' => $_W['weid'], 'openid' => $_W['fans']['from_user'], 'title' => $_GPC['title'], 'rolex' => $_GPC['rolex'], 'price' => $_GPC['price'], 'realname' => $_GPC['realname'], 'sex' => $_GPC['sex'], 'mobile' => $_GPC['mobile'], 'description' => $_GPC['description'], 'createtime' => TIMESTAMP, 'pcate' => $_GPC['pcate'], 'status' => 0, 'thumb1' => $_GPC['thumb1'], 'thumb2' => $_GPC['thumb2'], 'thumb3' => $_GPC['thumb3']); if (!empty($_GPC['id'])) { $good = pdo_fetch("SELECT * FROM" . tablename($this->table_goods) . "WHERE id='{$_GPC['id']}'"); } if (!empty($_GPC['image'])) { load()->classs('weixin.account'); $accObj = new WeixinAccount(); $access_token = $accObj->fetch_available_token(); $images = explode(",", $_GPC['image']); foreach ($images as $key => $image) { //下载图片 $url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token={$access_token}&media_id={$image}"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_NOBODY, 0); //只取body头 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $package = curl_exec($ch); $httpinfo = curl_getinfo($ch); curl_close($ch); $fileInfo = array_merge(array('header' => $httpinfo), array('body' => $package)); $rand = rand(100, 999); $filename = date("YmdHis") . $rand . ".jpg"; $filepath = ATTACHMENT_ROOT . "/images/thinkidea_secondmarket/" . $filename; $filecontent = $fileInfo["body"]; $dir_name = ATTACHMENT_ROOT . "/images/thinkidea_secondmarket"; if (!is_dir($dir_name)) { $dir = mkdir($dir_name, 0777, true); } if (false !== $dir) { $local_file = fopen($filepath, 'w'); if (false !== $local_file) { if (false !== fwrite($local_file, $filecontent)) { fclose($local_file); $info['img'] = "/images/thinkidea_secondmarket/" . $filename; if ($key <= 2) { $data['thumb' . ($key + 1)] = $info['img']; } } } else { message("图片上传失败,请联系管理员!", "javascript:WeixinJSBridge.call('closeWindow');", "error"); } } else { message("目录创建失败!", "javascript:WeixinJSBridge.call('closeWindow');", "error"); } } } if ($_W['ispost']) { if (empty($_GPC['id'])) { pdo_insert($this->table_goods, $data); message('发布成功', $this->createMobileUrl('list'), 'success'); } else { pdo_update($this->table_goods, $data, array('id' => $_GPC['id'])); message('更新成功', $this->createMobileUrl('list'), 'success'); } } include $this->template('add'); }
public function sendMessage($data, $notice = false) { global $_W; $reply = pdo_fetch('select * from ' . tablename('xwz_queue_reply') . ' where uniacid=:uniacid and rid=:rid limit 1', array(':uniacid' => $_W['uniacid'], ':rid' => $data['rid'])); $type = pdo_fetch('select * from ' . tablename('xwz_queue_type') . ' where uniacid=:uniacid and rid=:rid and id=:id limit 1', array(':uniacid' => $_W['uniacid'], ':rid' => $data['rid'], ':id' => $data['typeid'])); $number = pdo_fetchcolumn('select count(*) from ' . tablename('xwz_queue_data') . ' where uniacid=:uniacid and rid=:rid and typeid=:typeid and openid<>:openid and status=0 and id<:id ', array(':uniacid' => $_W['uniacid'], ':rid' => $reply['rid'], ':typeid' => $data['typeid'], ':openid' => $data['openid'], ':id' => $data['id'])); //发送通知 $sendtype = 0; // 0不发送 1 模板消息 2 客服消息 //如果是认证服务号模板消息,如果认证号订阅号,客服消息 load()->model('account'); $account = account_fetch($_W['uniacid']); if ($account['level'] == 4) { //认证服务号 $template_id = $reply['templateid']; if (!empty($template_id)) { $sendtype = 1; } else { $sendtype = 2; } } else { if ($account['level'] == 3) { //认证订阅号 $sendtype = 2; } } $url = $_W['siteroot'] . 'app/index.php?i=' . $_W['uniacid'] . '&c=entry&m=xwz_queue&do=index&rid=' . $data['rid']; if ($sendtype == 1) { $data = json_encode(array('keyword1' => array('value' => $type['tag'] . $data['number']), 'keyword2' => array('value' => $type['title']), 'keyword3' => array('value' => $number . '位'), 'keyword4' => array('value' => $reply['heading']), 'keyword5' => array('value' => date('Y-m-d H:i', $data['createtime'])))); load()->classs('weixin.account'); $accObj = WeixinAccount::create($_W['uniacid']); $access_token = $accObj->fetch_token(); if (!empty($access_token)) { load()->func('communication'); $postarr = '{"touser":"******","template_id":"' . $template_id . '","url":"' . $url . '","data":' . $data . '}'; $res = ihttp_post('https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' . $access_token, $postarr); } } else { if ($sendtype == 2) { $content = $notice ? "排号进度通知" : "取号成功通知\n\n"; $content .= "号码:" . $type['tag'] . $data['number'] . "\n"; $content .= "类型:" . $type['title'] . "\n"; $content .= "前面还有:" . $number . "位\n"; $content .= "商家:" . $reply['heading'] . "\n"; $content .= "取号时间:" . date('Y-m-d H:i', $data['createtime']) . "\n\n"; $content .= "<a href='{$url}'>点击查看详情</a>"; $data = array("touser" => $data['openid'], "msgtype" => "text", "text" => array('content' => urlencode($content))); load()->classs('weixin.account'); $accObj = WeixinAccount::create($_W['uniacid']); $access_token = $accObj->fetch_token(); if (!empty($access_token)) { $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={$access_token}"; load()->func('communication'); $res = ihttp_request($url, urldecode(json_encode($data))); } } } }
public function doMobileindex() { global $_GPC, $_W; $rid = intval($_GPC['rid']); $fansID = $_W['member']['uid']; $from_user = $_W['fans']['from_user']; $uniacid = $_W['uniacid']; $acid = $_W['acid']; $running = true; $page_from_user = base64_encode(authcode($from_user, 'ENCODE')); if (empty($rid)) { message('抱歉,参数错误!', '', 'error'); } $reply = pdo_fetch("select * from " . tablename('stonefish_redenvelope_reply') . " where rid = :rid order by `id` desc", array(':rid' => $rid)); if ($reply == false) { message('抱歉,活动已经结束,下次再来吧!', '', 'error'); } //兑奖参数重命名 $isfansname = explode(',', $reply['isfansname']); //兑奖参数重命名 if (empty($acid)) { $acid = pdo_fetchcolumn("select share_acid from " . tablename('stonefish_redenvelope_reply') . " where rid = :rid order by `id` desc", array(':rid' => $rid)); } $share = pdo_fetch("select * from " . tablename('stonefish_redenvelope_share') . " where rid = :rid and acid = :acid", array(':rid' => $rid, ':acid' => $acid)); //首页广告显示控制 if ($reply['homepictime'] > 0) { if ($_COOKIE["stonefish_redenvelope_homepictime"] <= time()) { setcookie("stonefish_redenvelope_homepictime", mktime(23, 59, 59, date('d'), date('m'), date('Y')), mktime(23, 59, 59, date('d'), date('m'), date('Y'))); include $this->template('homepictime'); exit; } } //首页广告显示控制 //获得关键词 $keyword = pdo_fetch("select content from " . tablename('rule_keyword') . " where rid=:rid and type=1", array(":rid" => $rid)); $reply['keyword'] = $keyword['content']; //获得关键词 if (empty($from_user)) { //301跳转 if (!empty($share['share_url'])) { header("HTTP/1.1 301 Moved Permanently"); header("Location: " . $share['share_url'] . ""); exit; } //message('抱歉,参数错误!','', 'error'); $isshare = 1; $running = false; $msg = '请先关注公共号。'; } else { //查询是否为关注用户 load()->classs('weixin.account'); $accObj = WeixinAccount::create($_W['acid']); $access_token = $accObj->fetch_token(); load()->func('communication'); $oauth2_code = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $access_token . "&openid=" . $from_user . "&lang=zh_CN"; $content = ihttp_get($oauth2_code); $token = @json_decode($content['content'], true); $follow = $token['subscribe']; if ($follow == 0) { if (!empty($share['share_url'])) { header("HTTP/1.1 301 Moved Permanently"); header("Location: " . $share['share_url'] . ""); exit; } $isshare = 1; $running = false; $msg = '请先关注公共号。'; } //获得用户资料 $profile = mc_fetch($fansID, array('avatar', 'nickname', 'realname', 'mobile', 'qq', 'email', 'address', 'gender', 'telephone', 'idcard', 'company', 'occupation', 'position')); if (empty($profile['avatar'])) { $profile['avatar'] = $token['headimgurl']; mc_update($fansID, array('avatar' => $token['headimgurl'])); } if (empty($profile['nickname'])) { $profile['nickname'] = $token['nickname']; mc_update($fansID, array('nickname' => $token['nickname'])); } if (empty($profile['avatar'])) { $profile['avatar'] = '../addons/stonefish_redenvelope/template/images/avatar.jpg'; } if (empty($profile['nickname'])) { $profile['nickname'] = '匿名'; } $fans = pdo_fetch("SELECT * FROM " . tablename('stonefish_redenvelope_fans') . " WHERE rid = '" . $rid . "' and fansID='" . $fansID . "' and from_user='******'"); if (empty($fans)) { $running = false; $msg = '还没有领取过红包'; $isfansh = 180; $ziduan = array('realname', 'mobile', 'qq', 'email', 'address', 'gender', 'telephone', 'idcard', 'company', 'occupation', 'position'); foreach ($ziduan as $ziduans) { if ($reply['is' . $ziduans]) { ${$ziduans} = true; $isfansh += 38; } } if ($realname || $mobile || $qq || $email || $address || $gender || $telephone || $idcard || $company || $occupation || $position) { $isfans = true; $isfansh += 50; } else { $isfansh = 180; } } //增加浏览次数 pdo_update('stonefish_redenvelope_reply', array('viewnum' => $reply['viewnum'] + 1), array('id' => $reply['id'])); //查询是活动定义的次数还是商户赠送次数 if ($reply['opportunity'] == 1) { //商家赠送机会 if (empty($profile['mobile'])) { message('还没有注册成为会员,无法进入刮奖', url('entry//member', array('m' => 'stonefish_member', 'url' => url('entry//index', array('m' => 'stonefish_redenvelope', 'rid' => $rid)))), 'error'); exit; } $doings = pdo_fetch("SELECT awardcount,districtid,status FROM " . tablename('stonefish_branch_doings') . " WHERE rid = " . $rid . " and mobile='" . $profile['mobile'] . "' and uniacid='" . $uniacid . "'"); if (!empty($doings)) { if ($doings['status'] < 2) { $running = false; $msg = '抱歉,您的领取红包资格正在审核中'; } else { if ($doings['awardcount'] == 0) { $running = false; $msg = '抱歉,您的领取红包资格正在加急审核中'; } } //查询网点资料 $business = pdo_fetch("SELECT * FROM " . tablename('stonefish_branch_business') . " WHERE id=" . $doings['districtid'] . ""); //更新网点记录到会员中心表 pdo_update('mc_members', array('districtid' => $doings['districtid']), array('uid' => $fansID)); } else { $running = false; $msg = '抱歉,您的还未获得领取红包资格'; } } elseif ($reply['opportunity'] == 2) { $creditnames = array(); $unisettings = uni_setting($uniacid, array('creditnames')); foreach ($unisettings['creditnames'] as $key => $credit) { if ($reply['credit_type'] == $key) { $creditnames = $credit['title']; break; } } //积分购买机会 $credit = mc_credit_fetch($fansID, array($reply['credit_type'])); $credit_times = intval($credit[$reply['credit_type']] / $reply['credit_times']); if ($credit_times == 0) { $running = false; $msg = '抱歉,您的' . $creditnames . '不足以购买领取红包资格'; } } } //查询红包总数以及可中奖总数 是否还有奖品 if ($reply['countlimit'] != 0 && $reply['countlimit'] <= $reply['fansnum']) { //已没有奖品可发放了 $running = false; $msg = '所有红包都发放完了,下次早点来哟!'; } $prizenum = pdo_fetchcolumn("SELECT count(id) FROM " . tablename('stonefish_redenvelope_award') . " WHERE uniacid='" . $uniacid . "' AND rid= '" . $rid . "' and status>0"); if ($prizenum >= $reply['total_num']) { //已没有奖品可发放了 $running = false; $msg = '所有红包都发放完了,下次早点来哟!'; } //好友助力 $firendlist = pdo_fetchall("SELECT sum(point) as tpoint,nickname,avatar FROM " . tablename('stonefish_redenvelope_data') . " where fromuser=:fromuser group by fromuser order by visitorstime desc limit 0,10", array(":fromuser" => $from_user)); //好友助力 //分享信息 $sharelink = $_W['siteroot'] . 'app/' . $this->createMobileUrl('share', array('rid' => $rid, 'uid' => $fans['id'])); $sharetitle = empty($share['share_title']) ? '欢迎参加全民抢红包活动' : $share['share_title']; $sharedesc = empty($share['share_desc']) ? '亲,欢迎参加全民抢红包活动,祝您好运哦!!' : str_replace("\r\n", " ", $share['share_desc']); $sharetitle = $this->get_share($uniacid, $rid, $from_user, $sharetitle); $sharedesc = $this->get_share($uniacid, $rid, $from_user, $sharedesc); if (!empty($share['share_imgurl'])) { $shareimg = toimage($share['share_imgurl']); } else { $shareimg = toimage($reply['start_picurl']); } include $this->template('index'); }
public function getAccessToken() { global $_W; $account = $_W['account']; if ($this->_accountlevel < 4) { if (!empty($this->_account)) { $account = $this->_account; } } load()->classs('weixin.account'); $accObj = WeixinAccount::create($account['acid']); $access_token = $accObj->fetch_token(); return $access_token; }
public function doMobileEntry() { global $_GPC, $_W; $rid = intval($_GPC['rid']); $entrytype = $_GPC['entrytype']; $uniacid = $_W['uniacid']; $acid = $_W['acid']; $reply = pdo_fetch("select * from " . tablename('stonefish_bigwheel_reply') . " where rid = :rid order by `id` desc", array(':rid' => $rid)); //活动状态 $this->check_reply($reply); //活动状态 //虚拟人数 $this->xuni_time($reply); //虚拟人数 //获取openid $openid = $this->get_openid(); $from_user = $openid['openidtrue']; //获取openid //广告显示控制 if ($reply['homepictime'] > 0) { if ($reply['homepictype'] == 1 && $_GPC['homepic'] != "yes") { include $this->template('homepictime'); exit; } if ((empty($_COOKIE['stonefish_bigwheel_hometime' . $rid]) || $_COOKIE["stonefish_bigwheel_hometime" . $rid] <= time()) && $_GPC['homepic'] != "yes") { switch ($reply['homepictype']) { case 2: setcookie("stonefish_bigwheel_hometime" . $rid, strtotime(date("Y-m-d", strtotime("+1 day"))), strtotime(date("Y-m-d", strtotime("+1 day")))); break; case 3: setcookie("stonefish_bigwheel_hometime" . $rid, strtotime(date("Y-m-d", strtotime("+1 week"))), strtotime(date("Y-m-d", strtotime("+7 week")))); break; case 4: setcookie("stonefish_bigwheel_hometime" . $rid, strtotime(date("Y-m-d", strtotime("+1 year"))), strtotime(date("Y-m-d", strtotime("+1 year")))); break; } include $this->template('homepictime'); exit; } } //广告显示控制 if (!empty($_COOKIE['stonefish_userinfo']) && $_W['account']['level'] < 4) { $appUrl = $this->createMobileUrl($entrytype, array('rid' => $rid, 'fromuser' => $_GPC['from_user']), true); $appUrl = substr($appUrl, 2); $url = $_W['siteroot'] . "app/" . $appUrl; header("location: {$url}"); exit; } else { $setting = $this->module['config']; //认证服务号 //认证服务号 if ($_W['account']['level'] == 4) { $fans = pdo_fetch("select * from " . tablename('mc_mapping_fans') . " where uniacid = :uniacid and acid = :acid and openid = :openid order by `fanid` desc", array(':uniacid' => $uniacid, ':acid' => $acid, ':openid' => $from_user)); if (empty($fans) || empty($_COOKIE['stonefish_userinfo'])) { $appid = $_W['account']['key']; $secret = $_W['account']['secret']; load()->classs('weixin.account'); $accObj = WeixinAccount::create($acid); $access_token = $accObj->fetch_token(); load()->func('communication'); $oauth2_code = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $access_token . "&openid=" . $from_user . "&lang=zh_CN"; $content = ihttp_get($oauth2_code); $token = @json_decode($content['content'], true); setcookie("stonefish_userinfo", iserializer($token), time() + 3600 * 24 * $setting['stonefish_oauth_time']); setcookie("stonefish_userinfo_power", $reply['power'], time() + 3600 * 24 * $setting['stonefish_oauth_time']); //判断是否关注 if ($token['subscribe'] == 1) { //平台没有此粉丝数据重新写入数据,一般不会出现这个问题 $rec = array(); $rec['acid'] = $acid; $rec['uniacid'] = $uniacid; $rec['uid'] = 0; $rec['openid'] = $token['openid']; $rec['salt'] = random(8); $rec['follow'] = 1; $rec['followtime'] = $token['subscribe_time']; $rec['unfollowtime'] = 0; $settings = uni_setting($uniacid, array('passport')); if (!isset($settings['passport']) || empty($settings['passport']['focusreg'])) { $default_groupid = pdo_fetchcolumn('SELECT groupid FROM ' . tablename('mc_groups') . ' WHERE uniacid = :uniacid AND isdefault = 1', array(':uniacid' => $uniacid)); $data = array('uniacid' => $uniacid, 'email' => md5($token['openid']) . '@00393.com', 'salt' => random(8), 'groupid' => $default_groupid, 'avatar' => rtrim($token['headimgurl'], '0') . '132', 'createtime' => TIMESTAMP); $data['password'] = md5($token['openid'] . $data['salt'] . $_W['config']['setting']['authkey']); pdo_insert('mc_members', $data); $rec['uid'] = pdo_insertid(); $fans['uid'] = $rec['uid']; } pdo_insert('mc_mapping_fans', $rec); //平台没有此粉丝数据重新写入数据,一般不会出现这个问题 } $appUrl = $this->createMobileUrl($entrytype, array('rid' => $rid, 'fromuser' => $_GPC['from_user']), true); $appUrl = substr($appUrl, 2); $url = $_W['siteroot'] . "app/" . $appUrl; header("location: {$url}"); exit; } if (!empty($_COOKIE['stonefish_userinfo'])) { $appUrl = $this->createMobileUrl($entrytype, array('rid' => $rid, 'fromuser' => $_GPC['from_user']), true); $appUrl = substr($appUrl, 2); $url = $_W['siteroot'] . "app/" . $appUrl; header("location: {$url}"); exit; } elseif ($reply['power'] == 2) { $appUrl = $this->createMobileUrl('auth2', array('entrytype' => $entrytype, 'rid' => $rid, 'from_user' => $_GPC['from_user'], 'power' => $reply['power']), true); $appUrl = substr($appUrl, 2); $redirect_uri = $_W['siteroot'] . "app/" . $appUrl; //snsapi_base为只获取OPENID,snsapi_userinfo为获取头像和昵称 $scope = $reply['power'] == 1 ? 'snsapi_base' : 'snsapi_userinfo'; $oauth2_code = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . $appid . "&redirect_uri=" . urlencode($redirect_uri) . "&response_type=code&scope=" . $scope . "&state=1#wechat_redirect"; header("location: {$oauth2_code}"); exit; } } //认证服务号 //非认证服务号和认证服务号未关注粉丝 //不是认证号又没有借用服务号获取头像昵称可认证服务号未关注用户 if ($setting['stonefish_bigwheel_oauth'] == 0) { if (!isset($_COOKIE["user_oauth2_wuopenid"]) && $_W['account']['level'] != 4) { //设置cookie信息 setcookie("user_oauth2_wuopenid", time(), time() + 3600 * 24 * $setting['stonefish_oauth_time']); } $appUrl = $this->createMobileUrl($entrytype, array('rid' => $rid, 'fromuser' => $_GPC['from_user']), true); $appUrl = substr($appUrl, 2); $url = $_W['siteroot'] . "app/" . $appUrl; header("location: {$url}"); exit; } //不是认证号又没有借用服务号获取头像昵称可认证服务号未关注用户 //不是认证号 借用服务号获取头像昵称 if ($setting['stonefish_bigwheel_oauth'] == 1 && !empty($_W['oauth_account']['key']) && !empty($_W['oauth_account']['secret'])) { // 判断是否是借用设置 $appid = $_W['oauth_account']['key']; $secret = $_W['oauth_account']['secret']; } if ($setting['stonefish_bigwheel_oauth'] == 2 && !empty($setting['appid']) && !empty($setting['secret'])) { // 判断是否是借用设置 $appid = $setting['appid']; $secret = $setting['secret']; } $appUrl = $this->createMobileUrl('auth2', array('entrytype' => $entrytype, 'rid' => $rid, 'from_user' => $_GPC['from_user'], 'power' => $reply['power']), true); $appUrl = substr($appUrl, 2); $redirect_uri = $_W['siteroot'] . "app/" . $appUrl; //snsapi_base为只获取OPENID,snsapi_userinfo为获取头像和昵称 $scope = $reply['power'] == 1 ? 'snsapi_base' : 'snsapi_userinfo'; $oauth2_code = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . $appid . "&redirect_uri=" . urlencode($redirect_uri) . "&response_type=code&scope=" . $scope . "&state=1#wechat_redirect"; header("location: {$oauth2_code}"); exit; //不是认证号 借用服务号获取头像昵称 //非认证服务号和认证服务号未关注粉丝 } }
public function doMobileSave_user() { global $_W, $_GPC; $openid = $_W['openid']; $acid = $_W['acid']; load()->classs('weixin.account'); $accObj = WeixinAccount::create($acid); $access_token = $accObj->fetch_token(); $userInfo = $this->getUserInfo($access_token, $openid); $uniacid = $_W['uniacid']; $user_name = $userInfo['nickname']; $user_photo = $userInfo['headimgurl']; $user_score = $_GPC['user_score']; $user_phone = $_GPC['user_phone']; $info = pdo_fetch("SELECT * FROM " . tablename('tim_cowuser') . " WHERE user_name = :user_name", array(':user_name' => $user_name)); if (empty($info)) { $data = array('uniacid' => $uniacid, 'user_name' => $user_name, 'user_photo' => $user_photo, 'user_score' => $user_score, 'user_phone' => $user_phone); pdo_insert('tim_cowuser', $data); echo '{"msg" : "success"}'; } elseif (intval($user_score) > intval($info['user_score'])) { $user_id = $info['user_id']; $data = array('user_id' => $user_id, 'uniacid' => $uniacid, 'user_name' => $user_name, 'user_photo' => $user_photo, 'user_score' => $user_score, 'user_phone' => $user_phone); pdo_update('tim_cowuser', $data, array('user_id' => $user_id)); echo '{"msg" : "You have played"}'; } }