示例#1
0
 /**
  *
  * @param string $type
  * @param int $shopId
  * @param int $catelogId
  * @param int $productId
  * @param array $options
  */
 public function &byType($type, $shopId, $catelogId = 0, $productId = 0, $options = array())
 {
     $fields = isset($options['fields']) ? $options['fields'] : '*';
     $cascaded = isset($options['cascaded']) ? $options['cascaded'] : 'Y';
     $q = array($fields, 'xxt_merchant_page', "sid={$shopId} and cate_id={$catelogId} and prod_id={$productId} and type='{$type}'");
     $q2 = array('o' => 'seq');
     $pages = $this->query_objs_ss($q, $q2);
     /*如果找不到定义,就从父资源中找定义*/
     if (count($pages) === 0) {
         if ($productId != 0) {
             $pages = $this->byType($type, $shopId, $catelogId, 0, $options);
         } else {
             if ($catelogId != 0) {
                 $pages = $this->byType($type, $shopId, 0, 0, $options);
             }
         }
     }
     if (count($pages) > 0 && $cascaded === 'Y') {
         $modelCode = \TMS_APP::M('code/page');
         foreach ($pages as &$page) {
             $code = $modelCode->byId($page->code_id);
             $page->html = $code->html;
             $page->css = $code->css;
             $page->js = $code->js;
             $page->ext_js = $code->ext_js;
             $page->ext_css = $code->ext_css;
         }
     }
     return $pages;
 }
示例#2
0
 /**
  *
  */
 public function &byId($id, $cascaded = 'N')
 {
     $q = array('*', 'xxt_lottery_log', "id='{$id}'");
     if ($log = $this->query_obj_ss($q)) {
         $log->award = \TMS_APP::M('app\\lottery\\award')->byId($log->aid);
     }
     return $log;
 }
示例#3
0
 public function __construct($mpid)
 {
     if (empty(self::$data)) {
         $mpa = \TMS_APP::M('mp\\mpaccount')->byId($mpid, 'wx_appid,wx_appsecret,wx_mchid');
         self::$data['APPID'] = $mpa->wx_appid;
         self::$data['MCHID'] = $mpa->wx_mchid;
         self::$data['KEY'] = $mpid;
         self::$data['APPSECRET'] = $mpa->wx_appsecret;
     }
 }
示例#4
0
 public function getMpid($data)
 {
     if (!empty($this->mpid)) {
         return $this->mpid;
     }
     $tradeNo = $data['out_trade_no'];
     $order = \TMS_APP::M('app\\merchant\\order')->byTradeNo($tradeNo);
     if ($order === false) {
         throw new \WxPayException('订单不存在');
     }
     $mpid = $order->mpid;
     return $mpid;
 }
示例#5
0
 /**
  *
  */
 public function handleRequest()
 {
     // init the destination file (format <filename.ext>.part<#chunk>
     // the file is stored in a temporary directory
     $temp_dir = $_POST['resumableIdentifier'];
     $dest_file = $temp_dir . '/' . $_POST['resumableFilename'] . '.part' . $_POST['resumableChunkNumber'];
     $content = base64_decode(preg_replace('/data:(.*?)base64\\,/', '', $_POST['resumableChunkContent']));
     // move the temporary file
     $fs = \TMS_APP::M('fs/saestore', $this->mpid);
     if (!$fs->write($dest_file, $content)) {
         return array(false, 'Error saving (move_uploaded_file) chunk ' . $_POST['resumableChunkNumber'] . ' for file ' . $_POST['resumableFilename']);
     } else {
         // check if all the parts present, and create the final destination file
         $this->createFileFromChunks($temp_dir, $_POST['resumableFilename'], $_POST['resumableChunkSize'], $_POST['resumableTotalSize']);
         return array(true);
     }
 }
示例#6
0
 /**
  * 创建订单
  *
  * @param string $mpid
  * @param object $user
  * @param object $info
  *
  * @return object $order
  */
 public function &create($mpid, $user, $info)
 {
     //订单号
     $trade_no = date('YmdHis') . mt_rand(100000, 999999);
     //库存信息
     $productIds = array();
     $skus = array();
     $totalPrice = 0;
     $modelSku = \TMS_APP::M('app\\merchant\\sku');
     foreach ($info->skus as $skuId => $skuInfo) {
         $sku = $modelSku->byId($skuId);
         $sku->__count = $skuInfo->count;
         $totalPrice += $skuInfo->count * $sku->price;
         $skus[] = $sku;
         $productIds[$sku->prod_id] = 1;
     }
     //商品信息
     $products = array();
     $modelProd = \TMS_APP::M('app\\merchant\\product');
     foreach ($productIds as $prodId => $v) {
         $product = $modelProd->byId($prodId);
         $products[] = array('id' => $product->id, 'cate_id' => $product->cate_id, 'name' => urlencode($product->name), 'main_img' => $product->main_img);
         /*更新商品定义状态*/
         if ($product->used === 'N') {
             $modelProd->refer($product->id);
         }
     }
     /*创建订单*/
     if (empty($info->extPropValues)) {
         $info->extPropValues = new \stdClass();
     }
     $epv = self::toJson($info->extPropValues);
     $order = array('trade_no' => $trade_no, 'mpid' => $mpid, 'sid' => $sku->sid, 'products' => urldecode(json_encode($products)), 'order_status' => 1, 'order_total_price' => $totalPrice, 'order_create_time' => time(), 'order_express_price' => 0, 'ext_prop_value' => $epv, 'buyer_openid' => $user->openid, 'buyer_nick' => $user->fan->nickname, 'receiver_name' => $info->receiver_name, 'receiver_mobile' => $info->receiver_mobile, 'receiver_email' => $info->receiver_email);
     $order['id'] = $this->insert('xxt_merchant_order', $order, true);
     $order['extPropValue'] = $info->extPropValues;
     $order = (object) $order;
     //订单包含的库存
     foreach ($skus as $sku) {
         $orderSku = array('mpid' => $mpid, 'sid' => $sku->sid, 'oid' => $order->id, 'cate_id' => $sku->cate_id, 'cate_sku_id' => $sku->cate_sku_id, 'prod_id' => $sku->prod_id, 'sku_id' => $sku->id, 'sku_price' => $sku->price, 'sku_count' => $sku->__count);
         $orderSku['id'] = $this->insert('xxt_merchant_order_sku', $orderSku, true);
         /*更新商品sku状态*/
         $modelSku->order($sku->id, $sku->__count);
     }
     return $order;
 }
示例#7
0
 /**
  *
  * $mpid
  * $id channel's id
  */
 public function mattersGet_action($mpid, $id, $orderby = 'time', $page = null, $size = null)
 {
     $vid = $this->getVisitorId($mpid);
     $params = new \stdClass();
     $params->orderby = $orderby;
     if ($page !== null && $size !== null) {
         $params->page = $page;
         $params->size = $size;
     }
     $matters = \TMS_APP::M('matter\\channel')->getMattersNoLimit($id, $vid, $params);
     $tagModel = $this->model('tag');
     foreach ($matters as $m) {
         $matterModel = \TMS_APP::M('matter\\' . $m->type);
         $m->url = $matterModel->getEntryUrl($mpid, $m->id);
         $m->tags = $tagModel->tagsByRes($m->id, 'article');
     }
     return new \ResponseData($matters);
 }
示例#8
0
/**
 * error and exception handle
 */
function show_error($message)
{
    require_once 'tms/tms_app.php';
    header("HTTP/1.1 500 Internal Server Error");
    header('Content-Type: text/plain; charset=utf-8');
    if ($message instanceof Exception) {
        $msg = $message->getMessage() . "\n";
        $trace = $message->getTrace();
        foreach ($trace as $t) {
            foreach ($t as $k => $v) {
                $msg .= $k . ':' . json_encode($v) . "\n";
            }
        }
    } else {
        $msg = $message;
    }
    echo $msg;
    TMS_APP::M('log')->log('error', 'error', $msg);
    exit;
}
示例#9
0
 /**
  *
  * @param string $type
  * @param int $shopId
  * @param int $catelogId
  * @param int $productId
  * @param array $options
  */
 public function &byType($type, $wallId, $options = array())
 {
     $fields = isset($options['fields']) ? $options['fields'] : '*';
     $cascaded = isset($options['cascaded']) ? $options['cascaded'] : 'Y';
     $q = array($fields, 'xxt_wall_page', "wid='{$wallId}' and type='{$type}'");
     $q2 = array('o' => 'seq');
     $pages = $this->query_objs_ss($q, $q2);
     if (count($pages) > 0 && $cascaded === 'Y') {
         $modelCode = \TMS_APP::M('code/page');
         foreach ($pages as &$page) {
             $code = $modelCode->byId($page->code_id);
             $page->html = $code->html;
             $page->css = $code->css;
             $page->js = $code->js;
             $page->ext_js = $code->ext_js;
             $page->ext_css = $code->ext_css;
         }
     }
     return $pages;
 }
示例#10
0
 /**
  * 获得定义的认证接口
  *
  * $mpid
  * $valid [null|Y|N]
  */
 public function &byMpid($mpid, $valid = null, $own = 'Y')
 {
     $where = "mpid='{$mpid}'";
     !empty($valid) && ($where .= " and valid='{$valid}'");
     $apis = $this->queryBy($where);
     if ($own === 'N') {
         $pmp = \TMS_APP::M('mp\\mpaccount')->byId($mpid);
         if (!empty($pmp->parent_mpid)) {
             $papis = $this->byMpid($pmp->parent_mpid, $valid);
         }
         if (!empty($papis)) {
             if (!empty($apis)) {
                 $apis = array_merge($papis, $apis);
             } else {
                 $apis = $papis;
             }
         }
     }
     return $apis;
 }
示例#11
0
 /**
  *
  */
 public function get_action($mpid, $id)
 {
     $data = array();
     $user = $this->getUser($mpid, array('verbose' => array('member' => true)));
     $data['user'] = $user;
     //
     $news = $this->model('matter\\news')->byId($id);
     if (isset($news->access_control) && $news->access_control === 'Y') {
         $this->accessControl($mpid, $id, $news->authapis, $user->openid, $news, false);
     }
     $matters = \TMS_APP::M('matter\\news')->getMatters($id);
     $modelAcl = \TMS_APP::M('acl');
     $matters2 = array();
     foreach ($matters as $m) {
         if ($m->access_control === 'Y' && $news->filter_by_matter_acl === 'Y') {
             $inacl = false;
             foreach ($user->members as $member) {
                 if ($modelAcl->canAccessMatter($mpid, $m->type, $m->id, $member, $m->authapis)) {
                     $inacl = true;
                     break;
                 }
             }
             if (!$inacl) {
                 continue;
             }
         }
         $m->url = \TMS_APP::M('matter\\' . $m->type)->getEntryUrl($mpid, $m->id, $user->openid);
         $matters2[] = $m;
     }
     if (count($matters2) === 0 && !empty($news->empty_reply_type) && !empty($news->empty_reply_id)) {
         $modelMatter = \TMS_APP::M('matter\\' . $news->empty_reply_type);
         $matter = $modelMatter->byId($news->empty_reply_id);
         $matter->url = $modelMatter->getEntryUrl($mpid, $news->empty_reply_id, $user->openid);
         $news->matters = array($matter);
     } else {
         $news->matters = $matters2;
     }
     $data['news'] = $news;
     return new \ResponseData($data);
 }
示例#12
0
 /**
  * 发送模板消息页面 
  *
  * $mpid
  * $authid 如果传递的消息中用户的ID需要翻译为openid,那么需要提供进行身份认证的接口
  */
 public function send_action($mpid, $auth_url = null)
 {
     $messages = $this->getPostJson();
     !is_object($messages) && ($messages = array($messages));
     $failed = array();
     if (!empty($auth_url)) {
         if (!($authapi = $this->model('user/authapi')->byUrl($mpid, $auth_url, 'authid'))) {
             return new \ResponseError('没有定义身份认证接口,无法进行身份转换,消息发送失败!');
         }
         $authid = $authapi->authid;
     }
     /**
      *
      */
     $mpproxy = \TMS_APP::M('mpproxy/wx', $mpid);
     foreach ($messages as $msg) {
         $msg = (object) $msg;
         if (isset($authid)) {
             $authuser = $msg->touser;
             $q = array('openid', 'xxt_member m', "m.forbidden='N' and m.authed_identity='{$authuser}'");
             if (!($openid = $this->model()->query_val_ss($q))) {
                 $msg->errmsg = '无法获得openid';
                 $failed[] = $msg;
             }
             $msg->touser = $openid;
         }
         $rst = $mpproxy->messageTemplateSend($msg);
         if ($rst[0] === false) {
             $msg->errmsg = $rst[1];
             $failed[] = $msg;
         }
     }
     if (empty($failed)) {
         return new \ResponseData('finish');
     } else {
         return new \ResponseError($failed);
     }
 }
示例#13
0
 /**
  * 根据邀请到的用户数量进行的排名
  */
 public function rankByFollower($mpid, $aid, $openid)
 {
     $modelRec = \TMS_APP::M('app\\enroll\\record');
     $last = $modelRec->getLast($mpid, $aid, $openid);
     $q = array('count(*)', 'xxt_enroll_record', "state=1 and aid='{$aid}' and follower_num>{$last->follower_num}");
     $rank = (int) $this->query_val_ss($q);
     return $rank + 1;
 }
示例#14
0
 /**
  * 群发消息日志查询
  *
  * $mpid 父账号或者子账号,父账号返回所有子账号的日志,子账号返回子账号的数据
  * $offset 相对于当前日期的偏移日期,以天为单位
  */
 public function massByMpid($mpid, $offset = 0)
 {
     $modelMp = \TMS_APP::M('mp\\mpaccount');
     $mpa = $modelMp->byId($mpid, 'mpid,mpsrc,asparent');
     if ($mpa->asparent === 'Y') {
         $mpset = "exists(select 1 from xxt_mpaccount m where m.parent_mpid='{$mpid}' and l.mpid=m.mpid)";
     } else {
         $mpset = "mpid='{$mpa->mpid}'";
     }
     $begin = mktime(0, 0, 0, date("m"), date("d") + $offset, date("Y"));
     $end = $begin + 86400;
     $q = array('l.id,l.mpid,l.matter_id,l.matter_type,result', 'xxt_log_massmsg l', "l.send_at>={$begin} and l.send_at<{$end} and {$mpset}");
     $q2 = array('o' => 'mpid,send_at desc');
     $logs = $this->query_objs_ss($q, $q2);
     return $logs;
 }
示例#15
0
<?php

/**
 * inside a mp.
 *
 * 在seesion中保留一些公众号的基本数据
 * 要考虑只能用那些不会变的属性
 */
$view['template'] = '/mp/frame';
$view['params']['layout-top'] = '/global/title-bar';
$view['params']['layout-left'] = '/mp/nav';
if (isset($_GET['mpid']) && ($mpid = $_GET['mpid'])) {
    $_SESSION['mpid'] = $mpid;
    if (!isset($_SESSION['mpaccount']) || !($mp = $_SESSION['mpaccount']) || $mp->mpid != $mpid) {
        $_SESSION['mpaccount'] = TMS_APP::M('mp\\mpaccount')->byId($mpid, 'name,mpid,mpsrc,asparent,parent_mpid,yx_joined,wx_joined,qy_joined');
        $_SESSION['authapis'] = TMS_APP::M('user/authapi')->byMpid($mpid, 'Y');
    }
}
示例#16
0
 /**
  * 活动登记(不包括登记数据)
  *
  * $mpid 运行的公众号,和openid和src相对应
  * $act
  * $mid
  */
 public function add($mpid, $act, $user, $referrer = '')
 {
     $ek = $this->genKey($mpid, $act->id);
     $i = array('aid' => $act->id, 'mpid' => $mpid, 'enroll_at' => time(), 'enroll_key' => $ek, 'openid' => $user->openid, 'nickname' => empty($user->nickname) ? '' : $user->nickname, 'vid' => $user->vid, 'mid' => '', 'referrer' => $referrer);
     $modelRou = \TMS_APP::M('app\\enroll\\round');
     if ($activeRound = $modelRou->getActive($mpid, $act->id)) {
         $i['rid'] = $activeRound->rid;
     }
     $this->insert('xxt_enroll_record', $i, false);
     return $ek;
 }
示例#17
0
 /**
  * 审核记录
  *
  * $mpid
  * $id article'id
  * $mid member's id
  * $phase
  */
 public function forward($mpid, $id, $mid, $phase, $remark = '')
 {
     $q = array('*', 'xxt_article_review_log', "mpid='{$mpid}' and article_id='{$id}'");
     $q2 = array('o' => 'seq desc', 'r' => array('o' => 0, 'l' => 1));
     $last = $this->query_objs_ss($q, $q2);
     if (!empty($last)) {
         $last = $last[0];
         $this->update('xxt_article_review_log', array('state' => 'F'), "id={$last->id}");
     }
     $member = \TMS_APP::M('user/member')->byId($mid);
     if (!empty($meber->name)) {
         $disposerName = $member->name;
     } else {
         $fan = \TMS_APP::M('user/fans')->byId($member->fid);
         $disposerName = $fan->nickname;
     }
     $seq = empty($last) ? 1 : $last->seq + 1;
     $newlog = array('mpid' => $mpid, 'article_id' => $id, 'seq' => $seq, 'mid' => $mid, 'disposer_name' => $disposerName, 'send_at' => time(), 'state' => 'P', 'phase' => $phase, 'remark' => $remark);
     $newlog['id'] = $this->insert('xxt_article_review_log', $newlog, true);
     return (object) $newlog;
 }
示例#18
0
 /**
  * 分段上传文件
  */
 public function uploadFile_action($mpid, $aid, $submitkey = '')
 {
     /* support CORS */
     header('Access-Control-Allow-Origin:*');
     header('Access-Control-Allow-Methods:POST');
     if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
         exit;
     }
     if (empty($submitkey)) {
         $user = $this->getUser($mpid);
         $submitkey = $user->vid;
     }
     /**
      * 分块上传文件
      */
     $modelFs = \TMS_APP::M('fs/local', $mpid, '_resumable');
     $dest = $submitkey . '_' . $_POST['resumableIdentifier'];
     $resumable = \TMS_APP::M('fs/resumable', $mpid, $dest, $modelFs);
     $resumable->handleRequest($_POST);
     return new \ResponseData('ok');
 }
示例#19
0
 /**
  * 向企业号用户发送消息
  *
  * $mpid
  * $message
  */
 public function messageSend($message, $encoded = false)
 {
     $mpa = TMS_APP::M('mp\\mpaccount')->byId($this->mpid, 'qy_agentid');
     $cmd = 'https://qyapi.weixin.qq.com/cgi-bin/message/send';
     $message['agentid'] = $mpa->qy_agentid;
     $posted = $encoded ? json_encode($message) : urldecode(json_encode($message));
     $rst = $this->httpPost($cmd, $posted);
     return $rst;
 }
示例#20
0
 /**
  * 根据属性值获得产品列表
  *
  * @param object $catelog 商品所属的分类
  * @param string $pvids 逗号分隔的商品属性值
  * @param array $options
  *
  */
 public function &byPropValue($catelog, $pvids, $options = array())
 {
     $fields = isset($options['fields']) ? $options['fields'] : '*';
     $cascaded = isset($options['cascaded']) ? $options['cascaded'] : 'Y';
     $state = isset($options['state']) ? $options['state'] : array();
     $beginAt = isset($options['beginAt']) ? $options['beginAt'] : 0;
     $endAt = isset($options['endAt']) ? $options['endAt'] : 0;
     $q = array($fields, 'xxt_merchant_product', "cate_id={$catelog->id}");
     foreach ($pvids as $pvid) {
         $q[2] .= " and prop_value like '%:\"{$pvid}\"%'";
     }
     isset($state['disabled']) && ($q[2] .= " and disabled='" . $state['disabled'] . "'");
     isset($state['active']) && ($q[2] .= " and active='" . $state['active'] . "'");
     $products = $this->query_objs_ss($q);
     /*填充详细信息*/
     if (!empty($products) && $cascaded === 'Y') {
         $modelSku = \TMS_APP::M('app\\merchant\\sku');
         $skuOptions = array('state' => array('disabled' => 'N'), 'beginAt' => $beginAt, 'endAt' => $endAt);
         foreach ($products as &$prod) {
             if (isset($prod->prop_value)) {
                 $prod->propValue = $this->_fillPropValue($prod->prop_value, $catelog);
                 unset($prod->prop_value);
             }
             $prod->cateSkus = $modelSku->byProduct($prod->id, $skuOptions);
         }
     }
     return $products;
 }
示例#21
0
 /**
  *
  */
 protected function getMpaccount()
 {
     return \TMS_APP::M('mp\\mpaccount')->byId($this->mpid, 'name,mpid,mpsrc,asparent,parent_mpid,yx_joined,wx_joined,qy_joined');
 }
示例#22
0
 /**
  * $id property's id
  */
 public function &valuesById($id, $assoPropVid = null)
 {
     $q = array('*', 'xxt_merchant_catelog_property_value v', "prop_id={$id}");
     if ($assoPropVid !== null) {
         $prop = \TMS_APP::M('app\\merchant\\property')->byId($id);
         $w = " and exists (select 1 from xxt_merchant_product p where";
         $w .= " p.cate_id={$prop->cate_id}";
         $w .= " and p.prop_value like concat('%\"{$id}\":\"',v.id,'\"%')";
         $w .= " and p.prop_value like '%:\"{$assoPropVid}\"%'";
         $w .= ")";
         $q[2] .= $w;
     }
     $values = $this->query_objs_ss($q);
     return $values;
 }
示例#23
0
 /**
  * 群发消息
  * 需要开通群发接口
  */
 public function mass2mps($sender, $matterId, $matterType, $mpids)
 {
     if (empty($mpids)) {
         return array(false, '没有指定接收消息的公众号');
     }
     $response = array();
     $mpModel = \TMS_APP::M('mp\\mpaccount');
     foreach ($mpids as $mpid) {
         $mpaccount = $mpModel->byId($mpid);
         $mpsrc = $mpaccount->mpsrc;
         /**
          * set message
          */
         $matterModel = \TMS_APP::M('matter\\' . $matterType);
         if ($mpsrc === 'wx' && in_array($matterType, array('article', 'news', 'channel'))) {
             /**
              * 微信的图文群发消息需要上传到公众号平台,所以链接素材无法处理
              */
             $message = $matterModel->forWxGroupPush($mpid, $matterId);
         } else {
             $message = $matterModel->forCustomPush($mpid, $matterId);
         }
         if (empty($message)) {
             $response[$mpid] = '指定的素材无法向公众号用户群发!';
             continue;
         }
         /**
          * send
          */
         $mpsrc === 'wx' && ($message['filter'] = array('is_to_all' => true));
         $mpproxy = \TMS_APP::M('mpproxy/' . $mpsrc, $mpid);
         $mpproxy->reset($mpid);
         // 因为重复获得对象会缓存
         $rst = $mpproxy->send2group($message);
         if ($rst[0] === true) {
             $response[$mpid] = 'ok';
             $msgid = isset($rst[1]->msg_id) ? $rst[1]->msg_id : 0;
             \TMS_APP::M('log')->mass($sender, $mpid, $matterType, $matterId, $message, $msgid, 'ok');
         } else {
             $response[$mpid] = $rst[1];
             \TMS_APP::M('log')->mass($sender, $mpid, $matterType, $matterId, $message, 0, $rst[1]);
         }
     }
     return array(true, $response);
 }
示例#24
0
 /**
  * 将消息发送给讨论组中的用户
  *
  * $mpid
  * $openid
  * $msg
  * $wall
  */
 public function push_others($mpid, $openid, $msg, $wall, $wid, $ctrl)
 {
     $mpa = \TMS_APP::M('mp\\mpaccount')->byId($mpid);
     /**
      * 获得当前用户的信息
      */
     $member = \TMS_APP::M('user/fans')->byOpenid($mpid, $openid, 'nickname');
     /**
      * 拼装推送消息
      */
     switch ($msg['type']) {
         case 'text':
             if (!empty($wall->user_url)) {
                 $url = $wall->user_url;
                 $url .= strpos($wall->user_url, '?') === false ? '?' : '&';
                 $url .= "openid={$openid}";
                 $txt = "<a href='{$url}'>{$member->nickname}</a>";
                 $txt .= ':' . $msg['data'];
             } else {
                 $txt = $member->nickname . ':' . $msg['data'];
             }
             $message = array("msgtype" => "text", "text" => array("content" => urlencode($txt)));
             break;
         case 'image':
             if ($mpa->mpsrc === 'yx' && empty($msg['data'][0])) {
                 /**
                  * 易信的图片消息不支持MediaId
                  */
                 $mpproxy = \TMS_APP::M('mpproxy\\yx', $mpid);
                 $rst = $mpproxy->mediaUpload($msg['data'][1]);
                 if ($rst[0] === false) {
                     $ctrl->sendByOpenid($mpid, $openid, array("msgtype" => "text", "text" => array("content" => urlencode($rst[1]))));
                     return $rst;
                 }
                 $mediaId = $rst[1];
             } else {
                 $mediaId = $msg['data'][0];
             }
             $message = array("msgtype" => "image", "image" => array("media_id" => $mediaId));
     }
     /**
      * 如果当前账号是企业号,且指定了参与的用户,那么发送给所有指定的用户;如果指定用户并未加入讨论组,应该提示他加入
      * 如果当前账号是服务号,那么发送给已经加入讨论组的所有用户
      */
     $finished = false;
     if ($mpa->mpsrc === 'qy') {
         /**
          * 企业号,或者开通了点对点消息接口易信公众号支持预先定义好组成员
          */
         $groupUsers = \TMS_APP::M('acl')->wallUsers($mpid, $wid);
         if (!empty($groupUsers)) {
             /**
              * 不推送给发送人
              */
             $pos = array_search($openid, $groupUsers);
             unset($groupUsers[$pos]);
             /**
              * 推送给已经加入讨论组的用户
              */
             $joinedGroupUsers = array();
             $ingroup = $this->joinedUsers($mpid, $wid);
             foreach ($ingroup as $ig) {
                 if ($openid === $ig->openid) {
                     continue;
                 }
                 $userid = $ig->openid;
                 $joinedGroupUsers[] = $userid;
                 /**
                  * 从所有成员用户中删除已进入讨论组的用户
                  */
                 $pos = array_search($userid, $groupUsers);
                 unset($groupUsers[$pos]);
             }
             if (!empty($joinedGroupUsers)) {
                 $message['touser'] = implode('|', $joinedGroupUsers);
                 $ctrl->send_to_qyuser($mpid, $message);
             }
             /**
              * 推送给未加入讨论组的用户
              */
             if (!empty($groupUsers)) {
                 $message['touser'] = implode('|', $groupUsers);
                 if ($msg['type'] === 'text') {
                     $joinUrl = 'http://' . $_SERVER['HTTP_HOST'] . "/rest/app/wall?wid={$wid}";
                     $message['text']['content'] = urlencode($txt . "(<a href='{$joinUrl}'>参与讨论</a>)");
                 }
                 $ctrl->send_to_qyuser($mpid, $message);
             }
             $finished = true;
         }
     }
     if (!$finished) {
         /**
          * 通过客服接口发送给墙内所有用户
          */
         $users = $this->joinedUsers($mpid, $wid);
         foreach ($users as $user) {
             if ($openid === $user->openid) {
                 continue;
             }
             $ctrl->sendByOpenid($mpid, $user->openid, $message);
         }
     }
     return array(true);
 }
示例#25
0
 /**
  * 直接打开频道的情况下(不是返回信息卡片),忽略置顶和置底,返回频道中的所有条目
  *
  * $channel_id int 频道的id
  * $channel 频道
  *
  * return 频道包含的所有条目
  */
 public function &getMattersNoLimit($channel_id, $vid, $params)
 {
     /**
      * load channel.
      */
     $channel = $this->byId($channel_id, 'matter_type');
     /**
      * in channel
      */
     if ($channel->matter_type === 'article') {
         $orderby = $params->orderby || $channel->orderby;
         $q1 = array();
         $q1[] = "m.id,m.title,m.summary,m.pic,m.create_at,m.creater_name,cm.create_at add_at,'article' type,m.score,m.remark_num,s.score myscore";
         $q1[] = "xxt_article m left join xxt_article_score s on m.id=s.article_id and s.vid='{$vid}',xxt_channel_matter cm";
         $q1[] = "m.state=1 and m.approved='Y' and cm.channel_id={$channel_id} and m.id=cm.matter_id and cm.matter_type='article'";
         $q2 = array();
         $q2['o'] = $this->matterOrderby('article', $orderby, 'cm.create_at desc');
         if (isset($params->page) && isset($params->size)) {
             $q2['r'] = array('o' => ($params->page - 1) * $params->size, 'l' => $params->size);
         }
         $matters = $this->query_objs_ss($q1, $q2);
     } else {
         $matters = array();
         $q1 = array();
         $q1[] = 'cm.create_at,cm.matter_type,cm.matter_id';
         $q1[] = 'xxt_channel_matter cm';
         $q1[] = "cm.channel_id='{$channel_id}'";
         $q2['o'] = 'cm.create_at desc';
         if (isset($params->page) && isset($params->size)) {
             $q2['r'] = array('o' => ($params->page - 1) * $params->size, 'l' => $params->size);
         }
         $simpleMatters = $this->query_objs_ss($q1, $q2);
         foreach ($simpleMatters as $sm) {
             $fullMatter = \TMS_APP::M('matter\\' . $sm->matter_type)->byId($sm->matter_id);
             $fullMatter->type = $sm->matter_type;
             $fullMatter->add_at = $sm->create_at;
             $matters[] = $fullMatter;
         }
     }
     return $matters;
 }
示例#26
0
 /**
  *
  */
 public function &M($model_path)
 {
     return TMS_APP::M($model_path);
 }
示例#27
0
 /**
  * 更新认证用户
  *
  * 要求认证用户首先必须是关注用户
  *
  * $mpid
  * $fid 关注用户id
  * $data
  * $attrs
  */
 public function modify($mpid, $authid, $mid, $member)
 {
     if (empty($mpid)) {
         return array(false, '没有指定MPID');
     }
     if (empty($authid)) {
         return array(false, '没有指定用户认证接口ID');
     }
     if (empty($mid)) {
         return array(false, '没有指定认证用户MID');
     }
     $member->mid = $mid;
     $member->mpid = $mpid;
     $member->authapi_id = $authid;
     $attrs = \TMS_APP::M('user/authapi')->byId($authid, 'attr_mobile,attr_email,attr_name,attr_password,extattr');
     if ($errMsg = $this->rejectAuth($member, $attrs)) {
         return array(false, $errMsg);
     }
     is_array($member) && ($member = (object) $member);
     /**
      * 用户的邮箱需要验证,将状态设置为等待验证的状态
      */
     $member->email_verified = $attrs->attr_email[4] === '1' ? 'N' : 'Y';
     /**
      * todo 应该支持使用扩展属性作为唯一标识
      */
     if ($attrs->attr_mobile[5] === '1' && isset($member->mobile)) {
         if ($attrs->attr_mobile[4] === '1') {
             $mobile = $member->mobile;
             $mpa = \TMS_APP::M('mp\\mpaccount')->getApis($mpid);
             if ('yx' !== $mpa->mpsrc) {
                 return array(false, '目前仅支持在易信客户端中验证手机号');
             }
             if ('N' == $mpa->yx_checkmobile) {
                 return array(false, '仅支持在开通了手机验证接口的公众号中验证手机号');
             }
             $rst = \TMS_APP::M('mpproxy/yx', $mpid)->mobile2Openid($mobile);
             if ($rst[0] === false) {
                 return array(false, "验证手机号失败【{$rst[1]}】");
             }
             $fan = \TMS_APP::M('user/fans')->byMid($mid);
             if ($fan->openid !== $rst[1]->openid) {
                 return array(false, "您输入的手机号与注册易信用户时的提供手机号不一致");
             }
         }
         $member->authed_identity = $member->mobile;
     } else {
         if ($attrs->attr_email[5] === '1' && isset($member->email)) {
             $member->authed_identity = $member->email;
         } else {
             return array(false, '无法获得用户身份标识信息');
         }
     }
     /**
      * 处理访问口令
      */
     /*if ($attrs->attr_password[0] === '0') {
     		if (empty($member->password) || strlen($member->password) < 6)
     		return array(false, '密码长度不符合要求');
     		$salt = $this->gen_salt();
     		$cpw = $this->compile_password($member->authed_identity, $member->password, $salt);
     		$member->password = $cpw;
     		$member->password_salt = $salt;
     		}*/
     /**
      * 扩展属性
      */
     if (!empty($member->extattr)) {
         $extdata = array();
         foreach ($member->extattr as $ek => $ev) {
             $extdata[$ek] = urlencode($ev);
         }
         $member->extattr = urldecode(json_encode($extdata));
     } else {
         $member->extattr = '{}';
     }
     $this->update('xxt_member', $member, "mid='{$mid}'");
     return array(true);
 }
示例#28
0
 /**
  * 上传文件并创建图文
  */
 public function articleUpload_action($mpid, $entry = null, $state = null)
 {
     if ($state === 'done') {
         $fan = $this->model('user/fans')->byId($this->user->fid, 'nickname');
         $posted = $this->getPostJson();
         $file = $posted->file;
         $modelFs = \TMS_APP::M('fs/local', $mpid, '_resumable');
         $fileUploaded = $modelFs->rootDir . '/article_' . $file->uniqueIdentifier;
         $current = time();
         $filename = str_replace(' ', '_', $file->name);
         $d = array();
         $d['mpid'] = $mpid;
         $d['entry'] = $entry;
         $d['creater'] = $this->user->mid;
         $d['creater_name'] = $fan->nickname;
         $d['creater_src'] = 'M';
         $d['create_at'] = $current;
         $d['modifier'] = $this->user->mid;
         $d['modifier_src'] = 'M';
         $d['modifier_name'] = $fan->nickname;
         $d['modify_at'] = $current;
         $d['title'] = substr($filename, 0, strrpos($filename, '.'));
         $d['author'] = $fan->nickname;
         $d['url'] = '';
         $d['hide_pic'] = 'Y';
         $d['can_picviewer'] = 'Y';
         $d['has_attachment'] = 'Y';
         $d['pic'] = '';
         $d['summary'] = '';
         $d['body'] = '';
         $d['finished'] = 'N';
         $d['approved'] = 'N';
         $d['public_visible'] = 'Y';
         $d['remark_notice'] = 'Y';
         $id = $this->model()->insert('xxt_article', $d, true);
         /**
          * 设置频道
          */
         list($entryType, $entryId) = explode(',', $entry);
         $entry = $this->model('matter\\' . $entryType)->byId($entryId, 'params');
         $params = json_decode($entry->params);
         if (!empty($params->channel)) {
             $channelId = $params->channel;
             $this->model('matter\\channel')->addMatter($channelId, array('id' => $id, 'type' => 'article'), $this->user->mid, $fan->nickname, 'M');
         }
         /**
          * 保存附件
          */
         $att = array();
         $att['article_id'] = $id;
         $att['name'] = $filename;
         $att['type'] = $file->type;
         $att['size'] = $file->size;
         $att['last_modified'] = $file->lastModified;
         $att['url'] = 'local://article_' . $id . '_' . $filename;
         $this->model()->insert('xxt_article_attachment', $att, true);
         $modelFs = \TMS_APP::M('fs/local', $mpid, '附件');
         $attachment = $modelFs->rootDir . '/article_' . $id . '_' . \TMS_MODEL::toLocalEncoding($filename);
         rename($fileUploaded, $attachment);
         /**
          * 获取附件的内容
          */
         $appRoot = $_SERVER['DOCUMENT_ROOT'];
         $ext = explode('.', $filename);
         $ext = array_pop($ext);
         $attAbs = $appRoot . '/' . $attachment;
         if (in_array($ext, array('doc', 'docx', 'ppt', 'pptx'))) {
             /* 存放附件转换结果 */
             $attDir = str_replace('.' . $ext, '', $attachment);
             mkdir($appRoot . '/' . $attDir);
             /* 执行转换操作 */
             $output = array();
             $attPng = $appRoot . '/' . $attDir . '/%d.jpg';
             $cmd = $appRoot . '/cus/conv2pdf2img ' . $attAbs . ' ' . $attPng;
             $rsp = exec($cmd, $output, $status);
             if ($status == 1) {
                 return new \ResponseError('转换文件失败:' . $rsp);
             }
             $this->setBodyByAtt($id, $attDir);
             if (in_array($ext, array('ppt', 'pptx'))) {
                 $this->setCoverByAtt($id, $attDir);
             }
         } else {
             if ($ext === 'pdf') {
                 /* 存放附件转换结果 */
                 $attDir = str_replace('.' . $ext, '', $attachment);
                 mkdir($appRoot . '/' . $attDir);
                 $attPng = $appRoot . '/' . $attDir . '/%d.jpg';
                 $cmd = $appRoot . '/cus/conv2img ' . $attAbs . ' ' . $attPng;
                 $rsp = exec($cmd);
                 $this->setBodyByAtt($id, $attDir);
             }
         }
         return new \ResponseData($id);
     } else {
         /**
          * 分块上传文件
          */
         $modelFs = \TMS_APP::M('fs/local', $mpid, '_resumable');
         $dest = '/article_' . $_POST['resumableIdentifier'];
         $resumable = new resumable($mpid, $dest, $modelFs);
         $resumable->handleRequest();
         exit;
     }
 }
示例#29
0
 /**
  * 获得openid
  */
 public function getOAuthUser($code)
 {
     $mpa = TMS_APP::M('mp\\mpaccount')->byId($this->mpid, "yx_appid,yx_appsecret");
     $cmd = "https://api.yixin.im/sns/oauth2/access_token";
     $params["appid"] = $mpa->yx_appid;
     $params["secret"] = $mpa->yx_appsecret;
     $params["code"] = $code;
     $params["grant_type"] = "authorization_code";
     $rst = $this->httpGet($cmd, $params, false, false);
     if ($rst[0] === false) {
         return $rst;
     }
     $openid = $rst[1]->openid;
     return array(true, $openid);
 }
示例#30
0
 /**
  *
  * todo 需要处理多个回车换行的问题
  */
 public function output($runningMpid, $mid, $vid, $ctrl)
 {
     if (!$this->article) {
         return false;
     }
     /**
      * output an article
      */
     $data = array();
     $this->article->shareby = $this->shareby;
     $data['mpid'] = $runningMpid;
     $visitor = new \stdClass();
     $visitor->openid = $this->openid;
     $visitor->vid = $vid;
     $data['visitor'] = $visitor;
     $user_agent = $_SERVER['HTTP_USER_AGENT'];
     if (preg_match('/yixin/i', $user_agent)) {
         if ($mp = \TMS_APP::model()->query_obj('yx_cardname,yx_cardid', 'xxt_mpaccount', "mpid='{$runningMpid}'")) {
             $yx_cardname = $mp->yx_cardname;
             $yx_cardid = $mp->yx_cardid;
         }
     }
     \TPL::assign('yx_cardid', empty($yx_cardid) ? false : $yx_cardid);
     \TPL::assign('yx_cardname', empty($yx_cardname) ? false : $yx_cardname);
     /**
      * 页面背景设置
      */
     $mpsetting = $ctrl->getMpSetting($runningMpid);
     \TPL::assign('body_ele', $mpsetting->body_ele);
     \TPL::assign('body_css', $mpsetting->body_css);
     /**
      * 补充数据
      */
     $model = \TMS_APP::model('matter\\article');
     /**
      * 评价信息
      */
     $user = $this->getUser($runningMpid);
     $this->article->praised = $model->praised($user, $this->article->id);
     /**
      * 评论
      */
     $this->article->remarks = $mpsetting->can_article_remark === 'Y' ? $model->remarks($this->article->id) : false;
     $data['article'] = $this->article;
     \TPL::assign('data', $data);
     /**
      * 选择模板
      */
     if ($this->article->custom_body === 'N') {
         \TPL::output('article');
     } else {
         \TPL::assign('title', $this->article->title);
         $nl = array("\r\n", "\n", "\r");
         if ($this->article->page_id) {
             $page = \TMS_APP::M('code/page')->byId($this->article->page_id);
             $page->html && \TPL::assign('body', $page->html);
             $page->css && \TPL::assign('css', $page->css);
             $page->js && \TPL::assign('js', $page->js);
             \TPL::assign('ext_js', $page->ext_js);
             \TPL::assign('ext_css', $page->ext_css);
         } else {
             $body = str_replace($nl, '', $this->article->body);
             \TPL::assign('body', $body);
             $this->article->css && \TPL::assign('css', $this->article->css);
         }
         \TPL::output('custom');
     }
 }