Exemplo n.º 1
0
 private function genImage($weapi, $scene_id, $channel, $from_user)
 {
     global $_W;
     $rand_file = $from_user . rand() . '.jpg';
     $att_target_file = 'qr-image-' . $rand_file;
     $att_head_cache_file = 'head-image-' . $rand_file;
     $target_file = ATTACH_DIR . $att_target_file;
     $target_file_url = $_W['attachurl'] . $att_target_file;
     $head_cache_file = ATTACH_DIR . $att_head_cache_file;
     $qr_file = $weapi->getLimitQR($scene_id);
     $ch = pdo_fetch("SELECT * FROM " . tablename(self::$t_channel) . " WHERE channel=:channel AND weid=:weid", array(":channel" => $channel, ":weid" => $_W['weid']));
     $ch = WechatUtil::decode_channel_param($ch, $ch['bgparam']);
     $enableHead = $ch['avatarenable'];
     $enableName = $ch['nameenable'];
     if (empty($ch)) {
         $ret = $weapi->sendText($from_user, "您所请求的专属海报二维码已经失效, 请联系客服人员");
         exit(0);
     } else {
         if (empty($ch['bg'])) {
             $bg_file = APP_PHP . 'images/bg.jpg';
         } else {
             $bg_file = $_W['attachurl'] . $ch['bg'];
         }
     }
     // 基础模式
     WeUtility::logging('step merge 1', "merge bgfile {$bg_file} and qrfile {$qr_file}");
     $this->mergeImage($bg_file, $qr_file, $target_file, array('left' => $ch['qrleft'], 'top' => $ch['qrtop'], 'width' => $ch['qrwidth'], 'height' => $ch['qrheight']));
     WeUtility::logging('step merge 1 done', '');
     // 扩展功能:昵称、图像
     if (1) {
         $fans = WechatUtil::fans_search($from_user, array('nickname', 'avatar'));
         if (!empty($fans)) {
             // 昵称
             if ($enableName) {
                 if (strlen($fans['nickname']) > 0) {
                     WeUtility::logging('step wirte text 1', $fans);
                     // $this->writeText($target_file, $target_file, '我是' . $fans['nickname'], array('size'=>30, 'left'=>150, 'top'=>50));
                     $this->writeText($target_file, $target_file, $fans['nickname'], array('size' => $ch['namesize'], 'left' => $ch['nameleft'], 'top' => $ch['nametop']));
                     WeUtility::logging('step wirte text 1 done', '');
                 }
             }
             // 头像
             if ($enableHead) {
                 if (strlen($fans['avatar']) > 10) {
                     $head_file = $fans['avatar'];
                     $head_file = preg_replace('/\\/0$/i', '/96', $head_file);
                     WeUtility::logging('step merge 2', $head_file);
                     $this->mergeImage($target_file, $head_file, $target_file, array('left' => $ch['avatarleft'], 'top' => $ch['avatartop'], 'width' => $ch['avatarwidth'], 'height' => $ch['avatarheight']));
                     WeUtility::logging('step merge 2 done', '');
                     WeUtility::logging('IamInMergeFile', $target_file . $head_file);
                 } else {
                     WeUtility::logging('NoAvatarFile', $fans['avatar']);
                 }
             }
         } else {
             WeUtility::logging('NOT merge avatar and nickname', $from_user);
         }
     }
     WeUtility::logging('step upload 1', '');
     $media_id = $weapi->uploadImage($target_file);
     WeUtility::logging('step upload 1 done', '');
     WeUtility::logging('genImage', $media_id);
     if (!empty($media_id)) {
         $nowtime = time();
         pdo_query("INSERT INTO " . tablename('core_attachment') . " (uniacid,uid,filename,attachment,type,createtime) VALUES " . "({$_W['weid']}, {$_W['weid']}, 'head_cache', '{$att_head_cache_file}', 1, {$nowtime})," . "({$_W['weid']}, {$_W['weid']}, 'post_cache', '{$att_target_file}', 1, {$nowtime})");
     } else {
         // in case 45009, api freq out of limit ;
         $ret = $weapi->sendText($from_user, "专属二维码已经生成, 点击这里:<a href='{$target_file_url}'>查看您的专属二维码</a>, 保存到手机后转发给好友就能拿话费!");
     }
     return array($media_id, $target_file_url);
 }
Exemplo n.º 2
0
 private function notifyUpLevel($weapi, $this_level_openid)
 {
     global $_W;
     WeUtility::logging('notifyUpLevel begin', $this_level_openid);
     $uplevel = pdo_fetch("SELECT * FROM " . tablename(self::$t_follow) . " WHERE weid=:weid AND follower=:follower", array(":weid" => $_W['weid'], ":follower" => $this_level_openid));
     WeUtility::logging('notifyUpLevel begin2', $this_level_openid);
     if (!empty($uplevel)) {
         $fans = WechatUtil::fans_search($this_level_openid, array('nickname'));
         WeUtility::logging('notifyUpLevel sendText begin', $uplevel['leader']);
         $weapi->sendText($uplevel['leader'], '您的朋友' . $fans['nickname'] . '又获得了一个新的支持者,您也得到了相应积分奖励,请注意查收!');
     }
     WeUtility::logging('notifyUpLevel', $uplevel);
 }
Exemplo n.º 3
0
 public function doWebSpread()
 {
     global $_W, $_GPC;
     $op = empty($_GPC['op']) ? 'leaflet' : $_GPC['op'];
     if ($op == 'delete') {
         $ret = pdo_query("DELETE FROM " . tablename(self::$t_channel) . " WHERE weid=:weid AND channel=:channel", array(":weid" => $_W['weid'], ":channel" => intval($_GPC['channel'])));
         message("删除成功", referer(), "success");
     } else {
         if ($op == 'leaflet') {
             $mylist = pdo_fetchall("SELECT * FROM " . tablename(self::$t_channel) . " WHERE weid=:weid", array(":weid" => $_W['weid']));
         } else {
             if ($op == 'active') {
                 $channel = intval($_GPC['channel']);
                 $item = pdo_fetch("SELECT * FROM " . tablename(self::$t_channel) . " WHERE weid=:weid AND active=1", array(":weid" => $_W['weid']));
                 // 若为激活新频道,则清空QR缓存
                 if (!empty($item) and $item['channel'] != $channel) {
                     // $this->clearQRCache($item['channel']);
                     pdo_update(self::$t_channel, array('active' => 0));
                     pdo_update(self::$t_channel, array('createtime' => time()), array('weid' => $_W['weid'], 'channel' => $item['channel']));
                     pdo_update(self::$t_channel, array('createtime' => time(), 'active' => 1), array('weid' => $_W['weid'], 'channel' => $channel));
                     message('重新设定当前活跃传单成功', referer(), 'success');
                 }
                 message('设定当前活跃传单成功', referer(), 'success');
             } else {
                 if ($op == 'post') {
                     load()->func('tpl');
                     $item = array();
                     if (!empty($_GPC['channel'])) {
                         $item = pdo_fetch("SELECT * FROM " . tablename(self::$t_channel) . " WHERE weid=:weid AND channel=:channel", array(":weid" => $_W['weid'], ":channel" => $_GPC['channel']));
                     }
                     $item = WechatUtil::decode_channel_param($item, $item['bgparam']);
                     if (checksubmit('submit')) {
                         $path_parts = explode('.', $_GPC['bg']);
                         $suffix = end($path_parts);
                         if (strcasecmp('jpg', $suffix) != 0) {
                             message('传单背景图必须是jpg格式。不支持png等其他格式。', referer(), 'error');
                         }
                         if (strpos($_GPC['bg'], 'http://') === FALSE) {
                             // valid
                         } else {
                             message('传单背景图必须从本地上传,不能使用网络图片。您可以先将网络图片保存到本地,然后再上传。', referer(), 'error');
                         }
                         $bgparam = WechatUtil::encode_channel_param($_GPC);
                         if (!empty($_GPC['channel'])) {
                             pdo_update(self::$t_channel, array('createtime' => time(), 'title' => $_GPC['title'], 'thumb' => $_GPC['thumb'], 'bg' => $_GPC['bg'], 'bgparam' => $bgparam, 'desc' => $_GPC['desc'], 'url' => $_GPC['url'], 'click_credit' => $_GPC['click_credit'], 'sub_click_credit' => $_GPC['sub_click_credit'], 'newbie_credit' => $_GPC['newbie_credit'], 'weid' => $_W['weid']), array('channel' => $_GPC['channel']));
                             // 清空QR缓存
                             $this->clearQRCache($_GPC['channel']);
                             message('更新传单成功', referer(), 'success');
                         } else {
                             $list_count = pdo_fetchcolumn("SELECT COUNT(*) FROM " . tablename(self::$t_channel) . " WHERE weid=:weid", array(":weid" => $_W['weid']));
                             $active = $list_count == 0;
                             pdo_insert(self::$t_channel, array('title' => $_GPC['title'], 'createtime' => time(), 'thumb' => $_GPC['thumb'], 'bg' => $_GPC['bg'], 'bgparam' => $bgparam, 'active' => $active, 'desc' => $_GPC['desc'], 'url' => $_GPC['url'], 'click_credit' => $_GPC['click_credit'], 'sub_click_credit' => $_GPC['sub_click_credit'], 'newbie_credit' => $_GPC['newbie_credit'], 'weid' => $_W['weid']));
                             message('新建传单成功', referer(), 'success');
                         }
                     }
                 } else {
                     if ($op == 'log' or $op == 'qualitylog') {
                         $pindex = max(1, intval($_GPC['page']));
                         $psize = 20;
                         $mgr = new UserManager('');
                         $keyword = $_GPC['keyword'];
                         if ($op == 'qualitylog') {
                             $mylist = $mgr->getQualityUser($pindex, $psize, $keyword);
                             $total = $mgr->getQualityUserCount($keyword);
                         } else {
                             if ($op == 'log') {
                                 $mylist = $mgr->getAllUser($pindex, $psize, $keyword);
                                 $total = $mgr->getAllUserCount($keyword);
                             }
                         }
                         $pager = pagination($total, $pindex, $psize);
                     } else {
                         if ($op == 'user') {
                             // 下线详情+二级下线详情
                             $from_user = $_GPC['from_user'];
                             $uplevel = pdo_fetch("SELECT * FROM " . tablename(self::$t_follow) . " WHERE weid=:weid AND follower=:follower", array(":weid" => $_W['weid'], ":follower" => $from_user));
                             $fans = WechatUtil::fans_search($from_user, array('avatar', 'nickname', 'createtime', 'credit1'));
                             $mgr = new UserManager('');
                             $mylist = $mgr->getFollowList($from_user);
                             $mylist2 = $mgr->getFollowList2($mylist);
                         } else {
                             if ('black_remove' == $op) {
                                 $from_user = $_GPC['from_user'];
                                 pdo_delete(self::$t_black, array('from_user' => $from_user, 'weid' => $_W['weid']));
                                 message('删除成功', $this->createWebUrl('Spread', array('op' => 'black')), 'success');
                             } else {
                                 if ('black' == $op) {
                                     if (!empty($_GPC['from_user'])) {
                                         $from_user = $_GPC['from_user'];
                                         $b = pdo_fetch("SELECT * FROM " . tablename(self::$t_black) . " WHERE from_user=:f AND weid=:w LIMIT 1", array(':f' => $from_user, ':w' => $_W['weid']));
                                         if (empty($b)) {
                                             pdo_insert(self::$t_black, array('from_user' => $from_user, 'weid' => $_W['weid'], 'access_time' => time()));
                                         }
                                         message('添加黑名单成功', referer(), 'success');
                                     }
                                     $list = pdo_fetchall("SELECT * FROM " . tablename(self::$t_black) . " WHERE weid=:w", array(':w' => $_W['weid']));
                                 } else {
                                     message('error!', '', 'error');
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     include $this->template('spread');
 }
Exemplo n.º 4
0
 public function getUserInfo($from_user)
 {
     $fans = WechatUtil::fans_search($from_user, array('nickname', 'avatar'));
     return $fans;
 }
Exemplo n.º 5
0
 private function getQRTicket($token, $data)
 {
     $url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token={$token}";
     WeUtility::logging('QR data', json_encode($data));
     $ret = WechatUtil::http_request($url, json_encode($data));
     $content = @json_decode($ret['content'], true);
     WeUtility::logging('QR content', $content);
     return $content;
 }