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 index()
 {
     //JSSDK 初始部分
     $param['mp_id'] = I('mp_id');
     //$param ['id'] = I('id');                                          //如有插件中数据id,分享url中应加入id参数
     //$url = addons_url ( 'Jssdk://Jssdk/index', $param );  //分享的url需要和自定义回复入口url保持相同
     $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     $surl = get_shareurl();
     if (!empty($surl)) {
         $this->assign('share_url', $surl);
     }
     $info = get_mpid_appinfo($param['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);
     $addon_config = get_addon_config('Jssdk');
     $this->assign('addon_config', $addon_config);
     //微信支付部分
     //此处可以动态获取数据库中的MCHID和KEY
     $jssdkpay = new JsSdkPay($options);
     $jssdkpay->MCHID = "";
     // 动态MCHID;微信支付分配的商户号
     $jssdkpay->KEY = "";
     // 动态KEY;
     //=========步骤2:使用统一支付接口,获取prepay_id============
     //使用统一支付接口
     $jssdkpay->parameters['openid'] = get_openid();
     //trade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识。
     $jssdkpay->parameters['body'] = "订单支付";
     //商品或支付单简要描述
     $jssdkpay->parameters['out_trade_no'] = "outtradeno" . time();
     //商户系统内部的订单号,32个字符内、可包含字母,不可重复
     $jssdkpay->parameters['total_fee'] = 100;
     //收款金额,此处单位为分 出现小数点接口报错必须是整数
     $jssdkpay->parameters['notify_url'] = 'http://test.uctoo.com/index.php/addon/Jssdk/Jssdk/alarmnotify';
     //接收微信支付异步通知回调地址
     $jssdkpay->parameters['trade_type'] = "JSAPI";
     //取值如下:JSAPI,NATIVE,APP
     $jssdkpay->parameters['spbill_create_ip'] = get_client_ip();
     //APP和网页支付提交用户端ip,Native支付填调用微信支付API的机器IP。
     //以下非必填参数根据需要添加
     //$jssdkpay->parameters['device_info'] = "013467007045764";            //微信支付分配的终端设备号,商户自定义
     //$jssdkpay->parameters['detail'] = "UCToo   蓝色";                     //商品名称明细列表
     //$jssdkpay->parameters['attach'] = "说明";                             //附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据
     //$jssdkpay->parameters['fee_type'] = "CNY";                           //符合ISO 4217标准的三位字母代码,默认人民币:CNY
     //$jssdkpay->parameters['time_start'] = "20091225091010";              //订单生成时间,格式为yyyyMMddHHmmss
     //$jssdkpay->parameters['time_expire'] = "20091227091010";             //订单失效时间,格式为yyyyMMddHHmmss
     //$jssdkpay->parameters['goods_tag'] = "WXG";                          //商品标记,代金券或立减优惠功能的参数
     //$jssdkpay->parameters['product_id'] = "12235413214070356458058";     //trade_type=NATIVE,此参数必传。此id为二维码中包含的商品ID,商户自行定义。
     $jssdkpay->prepay_id = $jssdkpay->getPrepayId();
     //微信生成的预支付回话标识,用于后续接口调用中使用,该值有效期为2小时
     //=========步骤3:使用jsapi调起支付============
     $jsApiParameters = $jssdkpay->getParameters();
     //JSSDK 用户支付完成后的一些系统操作
     $param1['dcnum'] = $jssdkpay->parameters['out_trade_no'];
     $param1['openid'] = $jssdkpay->parameters['openid'];
     $ajaxurl = addons_url('Jssdk://Jssdk/orderpaid', $param1);
     //用户支付完成后,在微信支付返回alarmnotify之前(不保证时序),可以通过ajax调用,进行一些预处理操作
     $jsApiParameters = substr($jsApiParameters, 1, -1) . ",success: function (res) {\n                // 支付成功后的js回调函数\n               \n                }";
     $this->assign("jsApiParameters", $jsApiParameters);
     //向页面传整理好的调起支付参数
     $this->display();
 }
 public function profile()
 {
     $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('只可在微信中访问');
     }
     $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) {
         $this->error('获取js_ticket失败!错误码:' . $weObj->errCode . ' 错误原因:' . ErrCode::getErrText($weObj->errCode));
     }
     $js_sign = $weObj->getJsSign($url);
     $this->assign('js_sign', $js_sign);
     $fans = $weObj->getUserInfo($user['openid']);
     $this->assign('user', $user);
     if (IS_POST) {
         $data['uid'] = $uid;
         $data['nickname'] = I('post.nickname', '', 'op_t');
         $data['mobile'] = I('post.mobile', '', 'op_t');
         $data['email'] = I('post.email', '', 'op_t');
         $data['sex'] = I('post.sex', '', 'intval');
         $data['qq'] = I('post.qq', '', 'op_t');
         $data['weibo'] = I('post.weibo', '', 'op_t');
         $data['signature'] = I('post.signature', '', 'op_t');
         $ucuser = D('Common/Ucuser');
         $res = $ucuser->save($data);
         if ($res > 0) {
             $this->success('更新资料成功', addons_url('Ucuser://Ucuser/profile'));
         } else {
             $this->error($ucuser->getError());
         }
     } else {
         //显示资料页面
         if ($user['openid'] != $fans['openid']) {
             //本地保存的openid和公众平台获取的不同,不允许用户自己以外的人访问
             $this->error('无权访问用户资料', addons_url('Ucuser://Ucuser/login'), 5);
         }
         $this->display();
     }
 }
 public function notify()
 {
     $rsv_data = $GLOBALS['HTTP_RAW_POST_DATA'];
     $result = xmlToArray($rsv_data);
     $map["appid"] = $result["appid"];
     $map["mchid"] = $result["mch_id"];
     $info = M('member_public')->where($map)->find();
     //获取公众号信息,jsApiPay初始化参数
     $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);
     //发送模板消息
     $TMArray = array("touser" => $result["openid"], "template_id" => "diW6jm5hBwemeoDF0FZdU2agSZ9kydje22YJIC0gVMo", "url" => "http://test.uctoo.com/index.php?s=/home/addons/execute/Ucuser/Ucuser/index/mp_id/107.html", "topcolor" => "#FF0000", "data" => array("name" => array("value" => "优创智投", "color" => "#173177"), "remark" => array("value" => "今天", "color" => "#173177")));
     $options['appid'] = $info['appid'];
     //初始化options信息
     $options['appsecret'] = $info['secret'];
     $options['encodingaeskey'] = $info['encodingaeskey'];
     $weObj = new TPWechat($options);
     $res = $weObj->sendTemplateMessage($TMArray);
     //回复公众平台支付结果
     $notify = new PayNotifyCallBackController($this->wxpaycfg);
     //
     $notify->Handle(false);
     //处理业务逻辑
 }
 /**
  * 微信消息接口入口
  * 所有发送到微信的消息都会推送到该操作
  * 所以,微信公众平台后台填写的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']);
     }
 }
 /**
  * 向微信平台提交生成自定义菜单
  * @author patrick <*****@*****.**>
  */
 public function create()
 {
     $data = $this->get_data();
     // 要先填写appid
     $map['public_id'] = get_token();
     $info = D('Mpbase/MemberPublic')->where($map)->find();
     if (empty($info['appid']) || empty($info['secret'])) {
         $this->error('请先配置公众号的appid和secret', U('Admin/Mpbase/index', 'id=' . $info['id']));
     }
     $options = array('token' => 'uctoo', 'encodingaeskey' => $info['encodingaeskey'], 'appid' => $info['appid'], 'appsecret' => $info['secret']);
     $weObj = new TPWechat($options);
     $res = $weObj->createMenu($data);
     if ($res) {
         $this->success('发送菜单成功', U('Custommenu/index'), 3);
     } else {
         $this->success('发送菜单失败,错误的返回码是:' . $weObj->errCode . ', 错误的提示是:' . $weObj->errMsg, U('Custommenu/index'), 5);
     }
 }