public function index($page = 1, $r = 20)
 {
     //读取数据
     $model = D('Common/Ucuser');
     $map['status'] = array('EGT', 0);
     $map['mp_id'] = get_mpid();
     $list = $model->where($map)->page($page, $r)->order('uid asc')->select();
     int_to_string($list);
     //设置status
     foreach ($list as &$val) {
         $val['sex'] = $model->getSex($val['sex']);
     }
     $totalCount = $model->count();
     //显示页面
     $builder = new AdminListBuilder();
     $builder->title('用户列表')->keyText('uid', 'uid')->keyText('openid', 'openid')->keyText('nickname', '昵称')->keyText('sex', '性别')->keyText('province', '省份')->keyText('city', '城市')->keyText('score1', '积分')->data($list)->pagination($totalCount, $r)->display();
 }
 public function index()
 {
     $map['id'] = I('id');
     $params['mp_id'] = $map['mp_id'] = get_mpid();
     hook('init_ucuser', $params);
     //把消息分发到addons/ucuser/init_ucuser的方法中,初始化公众号粉丝信息
     $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     $surl = get_shareurl();
     if (!empty($surl)) {
         $this->assign('share_url', $surl);
     }
     $info = get_mpid_appinfo($params['mp_id']);
     $options['appid'] = $info['appid'];
     //初始化options信息
     $options['appsecret'] = $info['secret'];
     $options['encodingaeskey'] = $info['encodingaeskey'];
     $weObj = new TPWechat($options);
     $auth = $weObj->checkAuth();
     $js_ticket = $weObj->getJsTicket();
     if (!$js_ticket) {
         $this->error('获取js_ticket失败!错误码:' . $weObj->errCode . ' 错误原因:' . ErrCode::getErrText($weObj->errCode));
     }
     $js_sign = $weObj->getJsSign($url);
     $this->assign('js_sign', $js_sign);
     $info = M('weicj')->where($map)->find();
     $info['pic1'] = get_cover_url($info['pic1']);
     $info['pic2'] = get_cover_url($info['pic2']);
     $info['pic3'] = get_cover_url($info['pic3']);
     $info['pic4'] = get_cover_url($info['pic4']);
     $info['pic5'] = get_cover_url($info['pic5']);
     $info['pic6'] = get_cover_url($info['pic6']);
     $info['clickpic'] = get_cover_url($info['clickpic']);
     if ($info['andio']) {
         $file = M('file')->where('id=' . $info['andio'])->find();
         $filename = 'http://' . $_SERVER['HTTP_HOST'] . '/Uploads/Download/' . $file['savepath'] . $file['savename'];
         $info['trueaudio'] = $filename;
     } else {
         $info['trueaudio'] = $info['audio2'];
     }
     $this->assign('info', $info);
     //$templateFile = $this->model ['template_list'] ? $this->model ['template_list'] : '';
     $this->display();
 }
 /**
  * 活动详情
  * @param int $id
  * autor:xjw129xjt
  */
 public function detail($id = 0)
 {
     $check_isSign = D('event_attend')->where(array('uid' => is_login(), 'event_id' => $id))->select();
     $this->assign('check_isSign', $check_isSign);
     $event_content = D('Event')->where(array('status' => 1, 'id' => $id))->find();
     if (!$event_content) {
         $this->error('404 not found');
     }
     D('Event')->where(array('id' => $id))->setInc('view_count');
     $event_content['user'] = query_user(array('id', 'username', 'nickname', 'space_url', 'space_link', 'avatar64', 'rank_html', 'signature'), $event_content['uid']);
     $event_content['type'] = $this->getType($event_content['type_id']);
     $menber = D('event_attend')->where(array('event_id' => $id, 'status' => 1))->select();
     foreach ($menber as $k => $v) {
         $event_content['member'][$k] = query_user(array('id', 'username', 'nickname', 'space_url', 'space_link', 'avatar64', 'rank_html', 'signature'), $v['uid']);
     }
     $params['mp_id'] = $map['mp_id'] = get_mpid();
     $this->assign('mp_id', $params['mp_id']);
     $uid = get_ucuser_uid();
     //获取粉丝用户uid,一个神奇的函数,没初始化过就初始化一个粉丝
     if ($uid === false) {
         $this->error('只可在微信中访问');
     }
     $user = get_uid_ucuser($uid);
     //获取公众号粉丝用户信息
     $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     $surl = get_shareurl();
     if (!empty($surl)) {
         $this->assign('share_url', $surl);
     }
     $appinfo = get_mpid_appinfo($params['mp_id']);
     //获取公众号信息
     $this->assign('appinfo', $appinfo);
     $options['appid'] = $appinfo['appid'];
     //初始化options信息
     $options['appsecret'] = $appinfo['secret'];
     $options['encodingaeskey'] = $appinfo['encodingaeskey'];
     $weObj = new TPWechat($options);
     $auth = $weObj->checkAuth();
     $js_ticket = $weObj->getJsTicket();
     if (!$js_ticket) {
     }
     $js_sign = $weObj->getJsSign($url);
     $this->assign('js_sign', $js_sign);
     $this->assign('user', $user);
     $this->assign('content', $event_content);
     $this->setTitle('{$content.title|op_t}' . '——活动');
     $this->setKeywords('{$content.title|op_t}' . ',活动');
     $this->getRecommend();
     $this->display();
 }
 public function forget()
 {
     $params['mp_id'] = $map['mp_id'] = get_mpid();
     $this->assign('mp_id', $params['mp_id']);
     $map['id'] = I('id');
     $uid = get_ucuser_uid();
     //获取粉丝用户uid,一个神奇的函数,没初始化过就初始化一个粉丝
     if ($uid === false) {
         $this->error('只可在微信中访问');
     }
     if (IS_POST) {
         $aMobile = I('post.mobile', '', 'op_t');
         $verify = I('post.verify', '', 'op_t');
         $password = I('post.password', '', 'op_t');
         $repassword = I('post.repassword', '', 'op_t');
         //确认两次输入的密码正确
         if ($password != $repassword) {
             $this->error('两次输入的密码不一致');
         }
         //读取SESSION中的验证信息
         $mobile = session('reset_password_mobile');
         //提交修改密码和接收验证码的手机号码不一致
         if ($aMobile != $mobile) {
             $this->error('提交修改密码和接收验证码的手机号码不一致');
         }
         $res = D('Verify')->checkVerify($aMobile, "mobile", $verify, 0);
         //确认验证信息正确
         if (!$res) {
             echo '验证码错误';
             return false;
         } else {
             echo true;
         }
         //将新的密码写入数据库
         $data1 = array('uid' => $uid, 'mobile' => $aMobile, 'password' => $password);
         $model = D('Common/Ucuser');
         $data1 = $model->create($data1);
         if (!$data1) {
             $this->error('密码格式不正确');
         }
         $result = $model->where(array('uid' => $uid))->save($data1);
         if ($result === false) {
             $this->error('数据库写入错误');
         }
         //将新的密码写入数据库
         $data = array('id' => $uid, 'mobile' => $aMobile, 'password' => $password);
         $model = UCenterMember();
         $data = $model->create($data);
         if (!$data) {
             $this->error('密码格式不正确');
         }
         $result = $model->where(array('id' => $uid))->save($data);
         if ($result === false) {
             $this->error('数据库写入错误');
         }
         //显示成功消息
         $this->success('密码重置成功', addons_url('Ucuser://Ucuser/login'));
     }
     $this->display();
 }
 /**
  *
  * jsApi微信支付示例
  * 注意:
  * 1、微信支付授权目录配置如下  http://test.uctoo.com/addon/Wxpay/Index/jsApiPay/mp_id/
  * 2、支付页面地址需带mp_id参数
  * 3、管理后台-基础设置-公众号管理,微信支付必须配置的参数都需填写正确
  * @param array $mp_id 公众号在系统中的ID
  * @return 将微信支付需要的参数写入支付页面,显示支付页面
  */
 public function jsApiPay($mp_id = 0)
 {
     empty($mp_id) && ($mp_id = get_mpid());
     $params['mp_id'] = $mp_id;
     //系统中公众号ID
     $this->assign('mp_id', $params['mp_id']);
     $uid = get_ucuser_uid();
     //获取粉丝用户uid,一个神奇的函数,没初始化过就初始化一个粉丝
     if ($uid === false) {
         $this->error('只可在微信中访问');
     }
     $user = get_uid_ucuser($uid);
     //获取本地存储公众号粉丝用户信息
     $this->assign('user', $user);
     $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     $surl = get_shareurl();
     if (!empty($surl)) {
         $this->assign('share_url', $surl);
     }
     //odata通用订单数据,订单数据可以从订单页面提交过来
     $odata['uid'] = $uid;
     $odata['mp_id'] = $params['mp_id'];
     // 当前公众号在系统中ID
     $odata['order_id'] = "time" . date("YmdHis");
     //
     $odata['order_status'] = 1;
     //不带该字段-全部状态, 2-待发货, 3-已发货, 5-已完成, 8-维权中
     $odata['order_total_price'] = 1;
     //订单总价,单位:分
     $odata['buyer_openid'] = $user['openid'];
     $odata['buyer_nick'] = $user['nickname'];
     $odata['receiver_mobile'] = $user['mobile'];
     $odata['product_id'] = 1;
     $odata['product_name'] = "UCToo";
     $odata['product_price'] = 100;
     //商品价格,单位:分
     $odata['product_sku'] = "UCToo_Wxpay";
     $odata['product_count'] = 1;
     $odata['module'] = MODULE_NAME;
     $odata['model'] = "order";
     $odata['aim_id'] = 1;
     $order = D("Order");
     // 实例化order对象
     $order->create($odata);
     // 生成数据对象
     $result = $order->add();
     // 写入数据
     if ($result) {
         // 如果主键是自动增长型 成功后返回值就是最新插入的值
     }
     //获取公众号信息,jsApiPay初始化参数
     $info = get_mpid_appinfo($odata['mp_id']);
     $this->options['appid'] = $info['appid'];
     $this->options['mchid'] = $info['mchid'];
     $this->options['mchkey'] = $info['mchkey'];
     $this->options['secret'] = $info['secret'];
     $this->options['notify_url'] = $info['notify_url'];
     $this->wxpaycfg = new WxPayConfig($this->options);
     //①、初始化JsApiPay
     $tools = new JsApiPay($this->wxpaycfg);
     $wxpayapi = new WxPayApi($this->wxpaycfg);
     //②、统一下单
     $input = new WxPayUnifiedOrder($this->wxpaycfg);
     //这里带参数初始化了WxPayDataBase
     //  $input->SetAppid($info['appid']);//公众账号ID
     //  $input->SetMch_id($info['mchid']);//商户号
     $input->SetBody($odata['product_name']);
     $input->SetAttach($odata['product_sku']);
     $input->SetOut_trade_no($odata['order_id']);
     $input->SetTotal_fee($odata['order_total_price']);
     $input->SetTime_start(date("YmdHis"));
     $input->SetTime_expire(date("YmdHis", time() + 600));
     // $input->SetGoods_tag("WXG");                      //商品标记,代金券或立减优惠功能的参数
     //  $input->SetNotify_url($info['notify_url']);       //http://test.uctoo.com/index.php/UShop/Index/notify
     $input->SetTrade_type("JSAPI");
     $input->SetOpenid($user['openid']);
     $order = $wxpayapi->unifiedOrder($input);
     $jsApiParameters = $tools->GetJsApiParameters($order);
     //获取共享收货地址js函数参数
     $editAddress = $tools->GetEditAddressParameters();
     //③、在支持成功回调通知中处理成功之后的事宜,见 notify.php
     /**
      * 注意:
      * 1、当你的回调地址不可访问的时候,回调通知会失败,可以通过查询订单来确认支付是否成功
      * 2、jsapi支付时需要填入用户openid,WxPay.JsApiPay.php中有获取openid流程 (文档可以参考微信公众平台“网页授权接口”,
      * 参考http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html)
      */
     $this->assign('order', $odata);
     $this->assign('jsApiParameters', $jsApiParameters);
     $this->assign('editAddress', $editAddress);
     $this->display();
 }
 /**
  * 微信消息接口入口
  * 所有发送到微信的消息都会推送到该操作
  * 所以,微信公众平台后台填写的api地址则为该操作的访问地址
  * 在mp.weixin.qq.com 开发者中心配置的 URL(服务器地址)  http://域名/index.php/home/weixin/index/id/member_public表的id.html
  */
 public function index($id = '')
 {
     //
     $this->member_public = M('MemberPublic')->find($id);
     $this->options['appid'] = $this->member_public['appid'];
     //初始化options信息
     $this->options['appsecret'] = $this->member_public['secret'];
     $this->options['encodingaeskey'] = $this->member_public['encodingaeskey'];
     $weObj = new TPWechat($this->options);
     $weObj->valid();
     $weObj->getRev();
     $data = $weObj->getRevData();
     $type = $weObj->getRevType();
     $ToUserName = $weObj->getRevTo();
     $FromUserName = $weObj->getRevFrom();
     $params['weObj'] =& $weObj;
     $params['mp_id'] = $id;
     $params['weOptions'] = $this->options;
     //如果被动响应可获得用户信息就记录下
     if (!empty($id)) {
         //设置当前上下文的公众号id
         $mp_id = get_mpid($id);
     }
     if (!empty($ToUserName)) {
         get_token($ToUserName);
     }
     if (!empty($FromUserName)) {
         $oid = get_openid($FromUserName);
     }
     hook('init_ucuser', $params);
     //把消息分发到addons/ucuser/init_ucuser的方法中,初始化公众号粉丝信息
     $map['openid'] = get_openid();
     $map['mp_id'] = $params['mp_id'];
     $ucuser = D('Ucuser');
     $user = $ucuser->where($map)->find();
     //查询出公众号的粉丝
     $fsub = $user["subscribe"];
     //记录首次关注状态
     //与微信交互的中控服务器逻辑可以自己定义,这里实现一个通用的
     switch ($type) {
         //事件
         case TPWechat::MSGTYPE_EVENT:
             //先处理事件型消息
             $event = $weObj->getRevEvent();
             switch ($event['event']) {
                 //关注
                 case TPWechat::EVENT_SUBSCRIBE:
                     //二维码关注
                     if (isset($event['eventkey']) && isset($event['ticket'])) {
                         //普通关注
                     } else {
                     }
                     if (!$user["subscribe"]) {
                         //未关注,并设置关注状态为已关注
                         $user["subscribe"] = 1;
                         $ucuser->where($map)->save($user);
                     }
                     hook('welcome', $params);
                     //把消息分发到实现了welcome方法的addons中,参数中包含本次用户交互的微信类实例和公众号在系统中id
                     exit;
                     break;
                     //扫描二维码
                 //扫描二维码
                 case TPWechat::EVENT_SCAN:
                     break;
                     //地理位置
                 //地理位置
                 case TPWechat::EVENT_LOCATION:
                     break;
                     //自定义菜单 - 点击菜单拉取消息时的事件推送
                 //自定义菜单 - 点击菜单拉取消息时的事件推送
                 case TPWechat::EVENT_MENU_CLICK:
                     break;
                     //自定义菜单 - 点击菜单跳转链接时的事件推送
                 //自定义菜单 - 点击菜单跳转链接时的事件推送
                 case TPWechat::EVENT_MENU_VIEW:
                     break;
                     //自定义菜单 - 扫码推事件的事件推送
                 //自定义菜单 - 扫码推事件的事件推送
                 case TPWechat::EVENT_MENU_SCAN_PUSH:
                     break;
                     //自定义菜单 - 扫码推事件且弹出“消息接收中”提示框的事件推送
                 //自定义菜单 - 扫码推事件且弹出“消息接收中”提示框的事件推送
                 case TPWechat::EVENT_MENU_SCAN_WAITMSG:
                     break;
                     //自定义菜单 - 弹出系统拍照发图的事件推送
                 //自定义菜单 - 弹出系统拍照发图的事件推送
                 case TPWechat::EVENT_MENU_PIC_SYS:
                     break;
                     //自定义菜单 - 弹出拍照或者相册发图的事件推送
                 //自定义菜单 - 弹出拍照或者相册发图的事件推送
                 case TPWechat::EVENT_MENU_PIC_PHOTO:
                     break;
                     //自定义菜单 - 弹出微信相册发图器的事件推送
                 //自定义菜单 - 弹出微信相册发图器的事件推送
                 case TPWechat::EVENT_MENU_PIC_WEIXIN:
                     break;
                     //自定义菜单 - 弹出地理位置选择器的事件推送
                 //自定义菜单 - 弹出地理位置选择器的事件推送
                 case TPWechat::EVENT_MENU_LOCATION:
                     break;
                     //取消关注
                 //取消关注
                 case TPWechat::EVENT_UNSUBSCRIBE:
                     if ($user["subscribe"]) {
                         $user["subscribe"] = 0;
                         //取消关注设置关注状态为取消
                         $ucuser->where($map)->save($user);
                     }
                     break;
                     //群发接口完成后推送的结果
                 //群发接口完成后推送的结果
                 case TPWechat::EVENT_SEND_MASS:
                     break;
                     //模板消息完成后推送的结果
                 //模板消息完成后推送的结果
                 case TPWechat::EVENT_SEND_TEMPLATE:
                     break;
                 default:
                     break;
             }
             break;
             //文本
         //文本
         case TPWechat::MSGTYPE_TEXT:
             hook('keyword', $params);
             //把消息分发到实现了keyword方法的addons中,参数中包含本次用户交互的微信类实例和公众号在系统中id
             $weObj->reply();
             //在addons中处理完业务逻辑,回复消息给用户
             break;
             //图像
         //图像
         case TPWechat::MSGTYPE_IMAGE:
             break;
             //语音
         //语音
         case TPWechat::MSGTYPE_VOICE:
             break;
             //视频
         //视频
         case TPWechat::MSGTYPE_VIDEO:
             break;
             //位置
         //位置
         case TPWechat::MSGTYPE_LOCATION:
             break;
             //链接
         //链接
         case TPWechat::MSGTYPE_LINK:
             break;
         default:
             break;
     }
     // 记录日志
     if (C('DEVELOP_MODE')) {
         // 是否开发者模式
         addWeixinLog($data, $GLOBALS['HTTP_RAW_POST_DATA']);
     }
 }
Example #7
0
function get_ucuser_uid($uid = 0)
{
    $mp_id = get_mpid();
    if ($uid !== NULL) {
        session('uid_' . $mp_id, $uid);
    } elseif (!empty($_REQUEST['uid'])) {
        session('uid_' . $mp_id, $_REQUEST['uid']);
    }
    //以上是带uid参数调用函数时设置session中的uid
    $uid = session('uid_' . $mp_id);
    $isWeixinBrowser = isWeixinBrowser();
    if (!$isWeixinBrowser) {
        //非微信浏览器返回false,调用此函数必须对false结果进行判断,非微信浏览器不可访问调用的controller
        return false;
    }
    //下面这段应该逻辑没问题,如果公众号配置信息错误或者没有snsapi_base作用域的获取信息权限可能会出现死循环,注释掉以下if可治愈
    if ($uid <= 0 && $isWeixinBrowser) {
        $map['openid'] = get_openid();
        $map['mp_id'] = $mp_id;
        $ucuser = D('Ucuser');
        $data = $ucuser->where($map)->find();
        if (!$data) {
            //公众号没有这个粉丝信息,就注册一个
            //先在Member表注册会员,使系统中uid统一,公众号粉丝在绑定手机后可登录网站
            //先在Member表注册会员,使系统中uid统一,公众号粉丝在绑定手机后可登录网站
            $aUsername = $aNickname = $map['openid'];
            //以openid作为默认UcenterMember用户名和Member昵称
            $aPassword = UCenterMember()->create_rand();
            //随机密码,用户未通过公众号注册,就不可登录网站
            $email = $aUsername . '@mp_id' . $map['mp_id'] . '.com';
            //以openid@mpid123.com作为默认邮箱
            $mobile = arr2str(UCenterMember()->rand_mobile());
            //生成随机手机号以通过model校验,不实际使用,准确手机以微信绑定的为准
            $aUnType = 5;
            //微信公众号粉丝注册
            $aRole = 3;
            //默认公众号粉丝用户角色
            /* 注册用户 */
            $uid = UCenterMember()->register($aUsername, $aNickname, $aPassword, $email, $mobile, $aUnType);
            if (0 < $uid) {
                //注册成功
                initRoleUser($aRole, $uid);
                //初始化角色用户
                set_user_status($uid, 1);
                //微信注册的用户状态直接设置为1
            } else {
                //注册失败,显示错误信息
            }
            $uid = $ucuser->registerUser($uid, $map['mp_id'], $map['openid']);
            //用注册member获取的统一uid注册微信粉丝
            session('uid_' . $mp_id, $uid);
        } else {
            $uid = $data['uid'];
            session('uid_' . $mp_id, $uid);
        }
    }
    if (empty($uid)) {
        return -1;
    }
    return $uid;
}
 public function change()
 {
     $map['id'] = I('id', 0, 'intval');
     $info = D('Mpbase/MemberPublic')->where($map)->find();
     get_mpid($map['id']);
     //设置当前下上文mp_id
     unset($map);
     $map['uid'] = UID;
     $res = M('Member')->where($map)->setField('token', $info['public_id']);
     $user = session('user_auth');
     $user['token'] = $info['public_id'];
     $user['public_name'] = $info['public_name'];
     session('user_auth', $user);
     session('user_auth_sign', data_auth_sign($user));
     $this->success('切换公众号成功!');
     redirect(U('index'));
 }
Example #9
0
function get_openid($openid = NULL)
{
    $mp_id = get_mpid();
    if ($openid !== NULL) {
        session('openid_' . $mp_id, $openid);
    } elseif (!empty($_REQUEST['openid'])) {
        session('openid_' . $mp_id, $_REQUEST['openid']);
    }
    $openid = session('openid_' . $mp_id);
    trace($mp_id . 'wechat:openid' . $openid, '微信', 'DEBUG', true);
    $isWeixinBrowser = isWeixinBrowser();
    //下面这段应该逻辑没问题,如果公众号配置信息错误或者没有snsapi_base作用域的获取信息权限可能会出现死循环,注释掉以下if可治愈
    if ($openid <= 0 && $isWeixinBrowser) {
        trace('wechat:openid1' . $openid, '微信', 'DEBUG', true);
        $callback = GetCurUrl();
        // OAuthWeixin ( $callback );
        $info = get_mpid_appinfo();
        trace('wechat:OAuthWeixin' . $info['id'], '微信', 'DEBUG', true);
        $options['token'] = APP_TOKEN;
        $options['appid'] = $info['appid'];
        //初始化options信息
        $options['appsecret'] = $info['secret'];
        $options['encodingaeskey'] = $info['encodingaeskey'];
        $auth = new Com\Wxauth($options);
        $openid = $auth->open_id;
        trace('wechat:openid3' . $openid, '微信', 'DEBUG', true);
    }
    if (empty($openid)) {
        return -1;
    }
    trace($mp_id . 'wechat:openid2' . $openid, '微信', 'DEBUG', true);
    return $openid;
}
 /**
  * 自动登录用户
  * @param  integer $user 用户信息数组
  */
 private function autoLogin($user, $remember = false, $role_id = 0)
 {
     /* 更新登录信息 */
     $data = array('uid' => $user['uid'], 'login' => array('exp', '`login`+1'), 'last_login_time' => NOW_TIME, 'last_login_ip' => get_client_ip(1), 'last_login_role' => $user['last_login_role']);
     $this->save($data);
     //判断角色用户是否审核
     $map['uid'] = $user['uid'];
     $map['role_id'] = $user['last_login_role'];
     $audit = D('UserRole')->where($map)->getField('status');
     //判断角色用户是否审核 end
     $umap['uid'] = $user['uid'];
     $umap['public_id'] = $user['token'];
     $info = D('Mpbase/MemberPublic')->where($umap)->find();
     get_mpid($info['id']);
     //设置当前下上文mp_id
     /* 记录登录SESSION和COOKIES */
     $auth = array('uid' => $user['uid'], 'username' => get_username($user['uid']), 'last_login_time' => $user['last_login_time'], 'role_id' => $user['last_login_role'], 'audit' => $audit, 'mp_id' => $info['id'], 'token' => $info['public_id'], 'public_name' => $info['public_name']);
     session('user_auth', $auth);
     session('user_auth_sign', data_auth_sign($auth));
     if ($remember) {
         $user1 = D('user_token')->where('uid=' . $user['uid'])->find();
         $token = $user1['token'];
         if ($user1 == null) {
             $token = build_auth_key();
             $data['token'] = $token;
             $data['time'] = time();
             $data['uid'] = $user['uid'];
             D('user_token')->add($data);
         }
     }
     if (!$this->getCookieUid() && $remember) {
         $expire = 3600 * 24 * 7;
         cookie('OX_LOGGED_USER', $this->jiami($this->change() . ".{$user['uid']}.{$token}"), $expire);
     }
 }
 public function edit($id = null)
 {
     $model = D('Weicj');
     if (IS_POST) {
         //提交表单
         $data['mp_id'] = I('post.mp_id', '', 'op_t');
         $data['url'] = I('post.url', '', 'op_t');
         $data['title'] = I('post.title', '', 'op_t');
         $data['intro'] = I('post.intro', '', 'op_t');
         $data['cover'] = I('post.cover', '', 'intval');
         //不指定模块,默认用CustomReply模块
         $data['pic1'] = I('post.pic1', '', 'intval');
         $data['pic2'] = I('post.pic2', '', 'intval');
         $data['pic3'] = I('post.pic3', '', 'intval');
         $data['pic4'] = I('post.pic4', '', 'intval');
         $data['pic5'] = I('post.pic5', '', 'intval');
         $data['pic6'] = I('post.pic6', '', 'intval');
         $data['clickpic'] = I('post.clickpic', '', 'intval');
         $data['andio'] = I('post.andio', '', 'intval');
         $data['cjurl'] = I('post.cjurl', 1, 'op_t');
         $data['audio2'] = I('post.audio2', 1, 'op_t');
         if ($id != 0) {
             $data['id'] = $id;
             $data['url'] = "http://" . $_SERVER['HTTP_HOST'] . addons_url('Weicj://Weicj/index', array('id' => $id, 'mp_id' => $data['mp_id']));
             //分享链接里一定加mp_id
             $data['url'] = str_replace("/admin/addon", "/home/addon", $data['url']);
             //哎呀,管理类中生成的url得替换成前台的,好麻烦
             $res = $model->save($data);
         } else {
             $res = $model->add($data);
             if ($res) {
                 //新增成功,追加修改一下url字段数据
                 $data['id'] = $res;
                 $data['url'] = "http://" . $_SERVER['HTTP_HOST'] . addons_url('Weicj://Weicj/index', array('id' => $res, 'mp_id' => $data['mp_id']));
                 //分享链接里一定加mp_id
                 $data['url'] = str_replace("/admin/addon", "/home/addon", $data['url']);
                 //哎呀,管理类中生成的url得替换成前台的,好麻烦
                 $res = $model->save($data);
             }
         }
         $this->success(($id == 0 ? '添加' : '编辑') . '成功', $id == 0 ? U('', array('id' => $res)) : '');
     } else {
         //显示表单
         //读取微场景信息
         if ($id != 0) {
             //编辑
             $weicj = $model->where(array('id' => $id))->find();
         } else {
             //新增初始化数据
             $weicj = array('mp_id' => get_mpid());
             //
         }
         //显示页面
         $builder = new AdminConfigBuilder();
         $builder->title($id != 0 ? '编辑微场景' : '添加微场景')->keyId()->keyHidden('mp_id', '')->keyHidden('url', '')->keyText('title', '标题', '自定义回复的标题')->keyText('intro', '描述', '自定义回复的描述')->keySingleImage('cover', '封面图', '自定义回复的封面图片')->keySingleImage('pic1', '场景1', '微场景图片1')->keySingleImage('pic2', '场景2', '微场景图片2')->keySingleImage('pic3', '场景3', '微场景图片3')->keySingleImage('pic4', '场景4', '微场景图片4')->keySingleImage('pic5', '场景5', '微场景图片5')->keySingleImage('pic6', '场景6', '微场景图片6')->keySingleImage('clickpic', '跳转图片', '跳转场景图片或按钮')->keyText('cjurl', '跳转网址', '跳转网址必须以http://开头')->keyText('audio2', '背景音乐网址', '网址必须以http://开头,仅支持mp3格式')->data($weicj)->buttonSubmit(U('edit'))->buttonBack()->display();
     }
 }
    }
    $ad_id = (int) $_GET['details'];
    $sql = 'SELECT d.*,
                   a1.alliance_name AS alliance1_name,
                   a2.alliance_name AS alliance2_name
            FROM (alliance_diplomacy d)
            INNER JOIN (alliance a1) ON a1.alliance_id = d.alliance1_id
            INNER JOIN (alliance a2) ON a2.alliance_id = d.alliance2_id
            WHERE d.ad_id = ' . $ad_id;
    if (($diplomacy = $db->queryrow($sql)) === false) {
        message(DATABASE_ERROR, 'Could not query alliance diplomacy data');
    }
    if (empty($diplomacy['ad_id'])) {
        message(NOTICE, constant($game->sprache("TEXT47")));
    }
    $mpid = get_mpid($diplomacy['alliance1_id']);
    $opid = get_opid($diplomacy['alliance1_id']);
    $game->out('
<table width="450" align="center" border="0" cellpadding="2" cellspacing="2" class="style_outer">
  <tr>
    <td>
      <table width="450" align="center" border="0" cellpadding="2" cellspacing="2" class="style_inner">
        <tr>
          <td align="center">
            <span style="font-size: 12pt; font-weight: bold;">' . $game->player['alliance_name'] . ' [' . $game->player['alliance_tag'] . ']</span><br><br>
            <table width="430" align="center" border="0" cellpadding="2" cellspacing="2">
              <tr><td width="430" align="left"><a href="' . parse_link('a=alliance_diplomacy') . '">' . constant($game->sprache("TEXT39")) . '</a> &raquo; <i>' . $diplomacy['alliance' . $opid . '_name'] . '</i></td></tr>
            </table>
            <table width="430" align="center" border="0" cellpadding="2" cellspacing="2" class="border_grey"><tr><td>
              <table width="300" align="center" border="0" cellpadding="0" cellspacing="0">
                <tr>