Beispiel #1
0
 /**
  * 微信消息接口入口
  * 所有发送到微信的消息都会推送到该操作
  * 所以,微信公众平台后台填写的api地址则为该操作的访问地址
  */
 public function index()
 {
     $token = 'maimaimai';
     //微信后台填写的TOKEN
     /* 加载微信SDK */
     $wechat = new Wechat($token);
     /* 获取请求信息 */
     $data = $wechat->request();
     if ($data && is_array($data)) {
         $wx_info = C('wx_info2');
         $Auth = new WechatAuth($wx_info['AppID'], $wx_info['Secret'], S('access_token2'));
         switch ($data['MsgType']) {
             case Wechat::MSG_TYPE_EVENT:
                 switch ($data['Event']) {
                     case Wechat::MSG_EVENT_SUBSCRIBE:
                         // 来源openid
                         $form_openid = $data['FromUserName'];
                         //获取来源者信息
                         $form = $Auth->userInfo($form_openid);
                         $old_wx['nickname'] = $form['nickname'];
                         $old_wx['sex'] = $form['sex'];
                         $old_wx['city'] = $form['city'];
                         $old_wx['province'] = $form['province'];
                         $result = M('wx_user')->where($old_wx)->find();
                         //判断
                         if ($result) {
                             $form['yyg_openid'] = $result['openid'];
                         }
                         $db = M('wx_jzq_user')->where(array('openid' => $form['openid']))->Find();
                         if (!$db) {
                             M('wx_jzq_user')->where(array('openid' => $form['openid']))->delete();
                             M('wx_jzq_user')->add($form);
                         }
                         $wechat->replyText("欢迎!发送<查询>可以查询邀请送红包活动信息");
                 }
                 break;
             case Wechat::MSG_TYPE_TEXT:
                 switch ($data['Content']) {
                     case '查询':
                         $re = M('wx_jzq_user')->where(array('openid' => $form['openid']))->Find();
                         if ($re['openid'] = !null && ($re['yyg_openid'] = !null)) {
                             $m = M('wx_user')->where(array('openid' => $re['yyg_openid']))->find();
                             if ($m['fahongbao'] != 0) {
                                 $wechat->replyText("明天准备收红包");
                                 break;
                             } else {
                                 $wechat->replyText("邀请人数不足,请努力");
                                 break;
                             }
                         } else {
                             $form_openid = $data['FromUserName'];
                             //获取来源者信息
                             $form = $Auth->userInfo($form_openid);
                             $old_wx['nickname'] = $form['nickname'];
                             $old_wx['sex'] = $form['sex'];
                             $old_wx['city'] = $form['city'];
                             $old_wx['province'] = $form['province'];
                             //判断
                             $result = M('wx_user')->where($old_wx)->find();
                             if ($result) {
                                 $form['yyg_openid'] = $result['openid'];
                             }
                             $db = M('wx_jzq_user')->where(array('openid' => $form['openid']))->Find();
                             if (!$db) {
                                 M('wx_jzq_user')->where(array('openid' => $form['openid']))->delete();
                                 M('wx_jzq_user')->add($form);
                             }
                             if ($db['yyg_openid'] == null) {
                                 $wechat->replyText("请再次查询");
                                 break;
                             }
                             break;
                         }
                 }
                 break;
         }
     }
 }
Beispiel #2
0
    /**
     * DEMO
     * @param  Object $wechat Wechat对象
     * @param  array  $data   接受到微信推送的消息
     */
    private function demo($wechat, $data)
    {
        $wx_info = C('wx_info');
        $Auth = new WechatAuth($wx_info['AppID'], $wx_info['Secret'], S('access_token'));
        switch ($data['MsgType']) {
            case Wechat::MSG_TYPE_EVENT:
                switch ($data['Event']) {
                    case Wechat::MSG_EVENT_SUBSCRIBE:
                        //来源openid
                        $form_openid = $data['FromUserName'];
                        //获取来源者信息
                        $form = $Auth->userInfo($form_openid);
                        //保存关注者信息
                        if (!M('wx_user')->where(array('openid' => $form['openid']))->Find()) {
                            // M('wx_user')->where(array('openid'=>$form['openid']))->delete();
                            M('wx_user')->add($form);
                        }
                        //如果是砍价1活动
                        if ($data['EventKey'] == 'kj1') {
                            //判断是否已经注册
                            $openid = $data['FromUserName'];
                            $user_info = M('member')->where(array('openid' => $openid))->find();
                            // $Auth->sendText($openid,$openid);
                            if (empty($user_info)) {
                                $back = $Auth->sendText($openid, "您还未注册/未绑定微信 \\d 请点击下面链接进行注册/登陆绑定");
                                if ($back) {
                                    $wechat->replyNewsOnce("点击注册送福气!", "只需几步即可完成注册", "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx1b4f89570d3f4976&redirect_uri=http%3A%2F%2Fwww.eyuanduobao.com%2Findex.php%2FHome%2FPerson%2Fme&response_type=code&scope=snsapi_base&state=STATE", "http://pic.qiantucdn.com/58pic/18/32/60/10c58PICXbP_1024.jpg");
                                }
                            } else {
                                //判断砍主是否已经曾经参与
                                if ($kj_id = M('kanjia')->where(array('uid' => $user_info['uid'], 'type' => 1))->getField('kj_id')) {
                                    $wechat->replyNewsOnce("[有人@你]您有一台Iphone6S尚未领取", "此链接是您的专属链接,请分享让朋友帮您砍价,由“壹圆购物”助力夺宝", "http://www.eyuanduobao.com/index.php/Wechat/Kanjia/index?kj_id=" . $kj_id, "http://www.eyuanduobao.com/Public/images/kj.png");
                                    exit;
                                }
                                /*保存砍主信息*/
                                //找到砍主id
                                $wx_id = M('wx_user')->where(array('openid' => $openid))->getField('wx_id');
                                // 如果没有获取到该砍主的微信信息
                                if (empty($wx_id)) {
                                    //获取来源者信息
                                    $add_info = $Auth->userInfo($openid);
                                    //保存关注者信息
                                    if (!M('wx_user')->where(array('openid' => $form['openid']))->Find()) {
                                        // M('wx_user')->where(array('openid'=>$form['openid']))->delete();
                                        if (M('wx_user')->add($add_info) === false) {
                                            $this->replyText("当前参与活动人数太多,请稍后重试");
                                            exit;
                                        }
                                        $wx_id = M('wx_user')->where(array('openid' => $openid))->getField('wx_id');
                                    }
                                }
                                $uid = $user_info['uid'];
                                $qr_url = $this->create_qr($openid, 1);
                                $map = array('uid' => $uid, 'wx_id' => $wx_id, 'time' => time(), 'money' => '7888.00', 'shengyumoney' => '7888.00', 'count' => 0, 'status' => 1, 'qr_url' => $qr_url, 'type' => 1);
                                //保存砍主信息
                                $kj_id = M('kanjia')->add($map);
                                if ($kj_id) {
                                    $wechat->replyNewsOnce("[有人@你]您有一台Iphone6S尚未领取", "此链接是您的专属链接,请分享让朋友帮您砍价,由“壹圆购物”助力夺宝", "http://www.eyuanduobao.com/index.php/Wechat/Kanjia/index?kj_id=" . $kj_id, "http://www.eyuanduobao.com/Public/images/kj.png");
                                } else {
                                    $Auth->sendText($openid, "当前参与活动人数太多,请稍后重试");
                                }
                            }
                            exit;
                        }
                        //如果是砍价2活动
                        if ($data['EventKey'] == 'kj2') {
                            //判断是否已经注册
                            $openid = $data['FromUserName'];
                            $user_info = M('member')->where(array('openid' => $openid))->find();
                            // $Auth->sendText($openid,$openid);
                            if (empty($user_info)) {
                                $back = $Auth->sendText($openid, "您还未注册/未绑定微信 \\d 请点击下面链接进行注册/登陆绑定");
                                if ($back) {
                                    $wechat->replyNewsOnce("点击注册送福气!", "只需几步即可完成注册", "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx1b4f89570d3f4976&redirect_uri=http%3A%2F%2Fwww.eyuanduobao.com%2Findex.php%2FHome%2FPerson%2Fme&response_type=code&scope=snsapi_base&state=STATE", "http://pic.qiantucdn.com/58pic/18/32/60/10c58PICXbP_1024.jpg");
                                }
                            } else {
                                //判断砍主是否已经曾经参与
                                if ($kj_id = M('kanjia')->where(array('uid' => $user_info['uid'], 'type' => 2))->getField('kj_id')) {
                                    $wechat->replyNewsOnce("[有人@你]5万积分等你来拿!!", "此链接是您的专属链接,请分享让朋友帮您砍价,由“壹圆购物”助力夺宝", "http://www.eyuanduobao.com/index.php/Wechat/Kanjia/index?kj_id=" . $kj_id, "http://www.eyuanduobao.com/Public/images/kj2.png");
                                    exit;
                                }
                                /*保存砍主信息*/
                                //找到砍主id
                                $wx_id = M('wx_user')->where(array('openid' => $openid))->getField('wx_id');
                                // 如果没有获取到该砍主的微信信息
                                if (empty($wx_id)) {
                                    //获取来源者信息
                                    $add_info = $Auth->userInfo($openid);
                                    //保存关注者信息
                                    if (!M('wx_user')->where(array('openid' => $form['openid']))->Find()) {
                                        // M('wx_user')->where(array('openid'=>$form['openid']))->delete();
                                        if (M('wx_user')->add($add_info) === false) {
                                            $this->replyText("当前参与活动人数太多,请稍后重试");
                                            exit;
                                        }
                                        $wx_id = M('wx_user')->where(array('openid' => $openid))->getField('wx_id');
                                    }
                                }
                                $uid = $user_info['uid'];
                                $qr_url = $this->create_qr($openid, 2);
                                $map = array('uid' => $uid, 'wx_id' => $wx_id, 'time' => time(), 'money' => '50000.00', 'shengyumoney' => '50000.00', 'count' => 0, 'status' => 1, 'qr_url' => $qr_url, 'type' => 2);
                                //保存砍主信息
                                $kj_id = M('kanjia')->add($map);
                                if ($kj_id) {
                                    $wechat->replyNewsOnce("[有人@你]5万积分等你来拿!!", "此链接是您的专属链接,请分享让朋友帮您砍价,由“壹圆购物”助力夺宝", "http://www.eyuanduobao.com/index.php/Wechat/Kanjia/index?kj_id=" . $kj_id, "http://www.eyuanduobao.com/Public/images/kj2.png");
                                } else {
                                    $Auth->sendText($openid, "当前参与活动人数太多,请稍后重试");
                                }
                            }
                            exit;
                        }
                        if (!empty($data['EventKey'])) {
                            $data['EventKey'] = str_replace('qrscene_', '', $data['EventKey']);
                            $uid = $data['EventKey'];
                            $type = $uid[0];
                            $uid = substr($uid, 1);
                            $openid = M('member')->where(array('uid' => $uid))->limit(1)->getField('openid');
                            //找到这个砍价消息
                            $D = D('Common/KanjiaUser', 'VModel');
                            $kanjia_info = $D->where(array('uid' => $uid, 'type' => $type))->find();
                            if (empty($kanjia_info)) {
                                $wechat->replyText("系统错误,找不到此砍价信息!{$uid} | {$type} |");
                                exit;
                            }
                            //找出此人的wx_id
                            $wx_id = M('wx_user')->where(array('openid' => $form_openid))->getField('wx_id');
                            //判断是否已经帮砍过了
                            $is_bangkan = M('bangkan')->where(array('wx_id' => $wx_id, 'kj_id' => $kanjia_info['kj_id']))->find();
                            if ($is_bangkan) {
                                //判断是否注册用户
                                //如果是注册用户可以再砍一次
                                $is_register = M('member')->where(array('openid' => $form_openid))->find();
                                if (empty($is_register)) {
                                    $wechat->replyText("/玫瑰 注册成为会员并通过微信登陆即可帮ta再砍一刀哦!");
                                    exit;
                                }
                                if ($is_register['is_kan']) {
                                    $wechat->replyText("/玫瑰 1.关注微信\n/玫瑰 2.注册成为会员\n以上2种方法都可以帮ta砍一次哦~\nps:注册还可以免费抽iphone哦~");
                                    exit;
                                } else {
                                    M('member')->where(array('uid' => $is_register['uid']))->setField('is_kan', 1);
                                }
                            }
                            //找出剩余的钱
                            $shengyumoney = $kanjia_info['shengyumoney'];
                            //区间砍价金额
                            $rule_map['type'] = $kanjia_info['type'];
                            $area = M('kanjiarule')->where($rule_map)->order('kjr_yikan ASC')->select();
                            if (empty($area)) {
                                //区间砍价金额
                                if ($shengyumoney >= 3000) {
                                    $money100 = mt_rand(0, 1) * 100;
                                    $money10 = mt_rand(0, 9) * 10;
                                    $money1 = mt_rand(0, 9) * 1;
                                    $moneyf = mt_rand(1, 9) * 0.1;
                                    $moneyf2 = mt_rand(0, 0) * 0.01;
                                }
                                if ($shengyumoney >= 1000 && $shengyumoney < 3000) {
                                    $money100 = mt_rand(0, 0) * 100;
                                    $money10 = mt_rand(0, 7) * 10;
                                    $money1 = mt_rand(0, 9) * 1;
                                    $moneyf = mt_rand(1, 9) * 0.1;
                                    $moneyf2 = mt_rand(0, 0) * 0.01;
                                }
                                if ($shengyumoney >= 500 && $shengyumoney < 1000) {
                                    $money100 = mt_rand(0, 0) * 100;
                                    $money10 = mt_rand(0, 0) * 10;
                                    $money1 = mt_rand(0, 9) * 1;
                                    $moneyf = mt_rand(1, 9) * 0.1;
                                    $moneyf2 = mt_rand(0, 0) * 0.01;
                                }
                                if ($shengyumoney < 500) {
                                    $money100 = mt_rand(0, 0) * 100;
                                    $money10 = mt_rand(0, 0) * 10;
                                    $money1 = mt_rand(0, 0) * 1;
                                    $moneyf = mt_rand(0, 9) * 0.1;
                                    $moneyf2 = mt_rand(1, 9) * 0.01;
                                }
                                $add_money = $money100 + $money10 + $money1 + $moneyf + $moneyf2;
                            } else {
                                //计算已砍比例
                                $yikan = $kanjia_info['money'] - $kanjia_info['shengyumoney'];
                                $yikan_bl = round($yikan / $kanjia_info['money'] * 100, 2);
                                //找到它所在的区间
                                foreach ($area as $key => $value) {
                                    if ($yikan_bl <= $value['kjr_yikan']) {
                                        $min = $value['kjr_min'];
                                        $max = $value['kjr_max'];
                                        if ($min > 0 && $max > 0) {
                                            $min = (int) $min;
                                            $max = (int) $max;
                                            $add_money1 = mt_rand($min, $max - 1);
                                            $add_money2 = mt_rand(1, 99) / 100;
                                            $add_money = $add_money1 + $add_money2;
                                        } elseif ($min <= 0 && $max >= 0) {
                                            $min = (int) ($min * 100);
                                            $max = (int) $max;
                                            $add_money1 = mt_rand(0, $max - 1);
                                            $add_money2 = mt_rand($min, 99) / 100;
                                            $add_money = $add_money1 + $add_money2;
                                        } elseif ($min <= 0 && $max <= 0) {
                                            $min = (int) ($min * 100);
                                            $max = (int) ($max * 100);
                                            $add_money1 = mt_rand(0, 0);
                                            $add_money2 = mt_rand($min, $max) / 100;
                                            $add_money = $add_money1 + $add_money2;
                                        } else {
                                            $add_money1 = mt_rand(0, 99);
                                            $add_money2 = mt_rand(1, 99) / 100;
                                            $add_money = $add_money1 + $add_money2;
                                        }
                                        break;
                                    } else {
                                        $add_money2 = mt_rand(1, 99) / 100;
                                        $add_money = $add_money2;
                                    }
                                }
                            }
                            if ($shengyumoney <= 50) {
                                $wechat->replyText("当前活动已经结束,请留意最新中奖公告");
                                exit;
                            }
                            //保存砍价记录
                            $wx_id = M('wx_user')->where(array('openid' => $form_openid))->getField('wx_id');
                            if (empty($wx_id)) {
                                $wechat->replyText("当前参与活动人数太多,请稍后重试");
                                exit;
                            }
                            $bangkan_add = array('wx_id' => $wx_id, 'kj_id' => $kanjia_info['kj_id'], 'bk_money' => $add_money, 'bk_time' => time());
                            //开启事物
                            M()->startTrans();
                            //保存帮砍信息
                            $add_status = M('bangkan')->add($bangkan_add);
                            //更新砍主信息
                            $save_status = M('kanjia')->where(array('kj_id' => $kanjia_info['kj_id']))->setField('shengyumoney', round($shengyumoney - $add_money, 2));
                            M('kanjia')->where(array('kj_id' => $kanjia_info['kj_id']))->setINC('count', 1);
                            if ($add_status && $save_status) {
                                M()->commit();
                            } else {
                                M()->rollback();
                                $wechat->replyText("当前参与活动人数太多,请稍后重试");
                                exit;
                            }
                            //获取来源者信息
                            $form = $Auth->userInfo($form_openid);
                            $rs = $Auth->userInfo($openid);
                            //发送消息给砍主
                            $Auth->sendText($openid, '您的好友“' . $form['nickname'] . '”\\n帮您砍下了' . $add_money . '元,快去答谢他(她)吧/示爱');
                            $wechat->replyText("您刚刚帮助您的好友[" . $rs['nickname'] . "]砍了" . $add_money . "元");
                        }
                        $wechat->replyText('哟呵~主子终于等到你,还好我没放屁啊!/示爱/示爱/示爱
欢迎来到【壹圆购物】王国游戏王国待会就更新啦,更多消息,请留意我们的微信公众号和新浪微博
请直接点击底部菜单,尽情购物吧!/玫瑰/玫瑰/玫瑰');
                        break;
                    case Wechat::MSG_EVENT_UNSUBSCRIBE:
                        //取消关注,记录日志
                        break;
                        //通过分享出去的扫码事件
                    //通过分享出去的扫码事件
                    case 'SCAN':
                        //如果是砍价1活动
                        if ($data['EventKey'] == 'kj1') {
                            //判断是否已经注册
                            $openid = $data['FromUserName'];
                            $user_info = M('member')->where(array('openid' => $openid))->find();
                            // $Auth->sendText($openid,$openid);
                            if (empty($user_info)) {
                                $back = $Auth->sendText($openid, "您还未注册/未绑定微信 \\d 请点击下面链接进行注册/登陆绑定");
                                if ($back) {
                                    $wechat->replyNewsOnce("点击注册送福气!", "只需几步即可完成注册", "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx1b4f89570d3f4976&redirect_uri=http%3A%2F%2Fwww.eyuanduobao.com%2Findex.php%2FHome%2FPerson%2Fme&response_type=code&scope=snsapi_base&state=STATE", "http://pic.qiantucdn.com/58pic/18/32/60/10c58PICXbP_1024.jpg");
                                }
                            } else {
                                //判断砍主是否已经曾经参与
                                if ($kj_id = M('kanjia')->where(array('uid' => $user_info['uid'], 'type' => 1))->getField('kj_id')) {
                                    $wechat->replyNewsOnce("[有人@你]您有一台Iphone6S尚未领取", "此链接是您的专属链接,请分享让朋友帮您砍价,由“壹圆购物”助力夺宝", "http://www.eyuanduobao.com/index.php/Wechat/Kanjia/index?kj_id=" . $kj_id, "http://www.eyuanduobao.com/Public/images/kj.png");
                                    exit;
                                }
                                /*保存砍主信息*/
                                //找到砍主id
                                $wx_id = M('wx_user')->where(array('openid' => $openid))->getField('wx_id');
                                // 如果没有获取到该砍主的微信信息
                                if (empty($wx_id)) {
                                    //获取来源者信息
                                    $add_info = $Auth->userInfo($openid);
                                    //保存关注者信息
                                    if (!M('wx_user')->where(array('openid' => $form['openid']))->Find()) {
                                        // M('wx_user')->where(array('openid'=>$form['openid']))->delete();
                                        if (M('wx_user')->add($add_info) === false) {
                                            $this->replyText("当前参与活动人数太多,请稍后重试");
                                            exit;
                                        }
                                        $wx_id = M('wx_user')->where(array('openid' => $openid))->getField('wx_id');
                                    }
                                }
                                $uid = $user_info['uid'];
                                $qr_url = $this->create_qr($openid, 1);
                                $map = array('uid' => $uid, 'wx_id' => $wx_id, 'time' => time(), 'money' => '7888.00', 'shengyumoney' => '7888.00', 'count' => 0, 'status' => 1, 'qr_url' => $qr_url, 'type' => 1);
                                //保存砍主信息
                                $kj_id = M('kanjia')->add($map);
                                if ($kj_id) {
                                    $wechat->replyNewsOnce("[有人@你]您有一台Iphone6S尚未领取", "此链接是您的专属链接,请分享让朋友帮您砍价,由“壹圆购物”助力夺宝", "http://www.eyuanduobao.com/index.php/Wechat/Kanjia/index?kj_id=" . $kj_id, "http://www.eyuanduobao.com/Public/images/kj.png");
                                } else {
                                    $Auth->sendText($openid, "当前参与活动人数太多,请稍后重试");
                                }
                            }
                            exit;
                        }
                        //如果是砍价2活动
                        if ($data['EventKey'] == 'kj2') {
                            //判断是否已经注册
                            $openid = $data['FromUserName'];
                            $user_info = M('member')->where(array('openid' => $openid))->find();
                            // $Auth->sendText($openid,$openid);
                            if (empty($user_info)) {
                                $back = $Auth->sendText($openid, "您还未注册/未绑定微信 \\d 请点击下面链接进行注册/登陆绑定");
                                if ($back) {
                                    $wechat->replyNewsOnce("点击注册送福气!", "只需几步即可完成注册", "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx1b4f89570d3f4976&redirect_uri=http%3A%2F%2Fwww.eyuanduobao.com%2Findex.php%2FHome%2FPerson%2Fme&response_type=code&scope=snsapi_base&state=STATE", "http://pic.qiantucdn.com/58pic/18/32/60/10c58PICXbP_1024.jpg");
                                }
                            } else {
                                //判断砍主是否已经曾经参与
                                if ($kj_id = M('kanjia')->where(array('uid' => $user_info['uid'], 'type' => 2))->getField('kj_id')) {
                                    $wechat->replyNewsOnce("[有人@你]5万积分等你来拿!!", "此链接是您的专属链接,请分享让朋友帮您砍价,由“壹圆购物”助力夺宝", "http://www.eyuanduobao.com/index.php/Wechat/Kanjia/index?kj_id=" . $kj_id, "http://www.eyuanduobao.com/Public/images/kj2.png");
                                    exit;
                                }
                                /*保存砍主信息*/
                                //找到砍主id
                                $wx_id = M('wx_user')->where(array('openid' => $openid))->getField('wx_id');
                                // 如果没有获取到该砍主的微信信息
                                if (empty($wx_id)) {
                                    //获取来源者信息
                                    $add_info = $Auth->userInfo($openid);
                                    //保存关注者信息
                                    if (!M('wx_user')->where(array('openid' => $form['openid']))->Find()) {
                                        // M('wx_user')->where(array('openid'=>$form['openid']))->delete();
                                        if (M('wx_user')->add($add_info) === false) {
                                            $this->replyText("当前参与活动人数太多,请稍后重试");
                                            exit;
                                        }
                                        $wx_id = M('wx_user')->where(array('openid' => $openid))->getField('wx_id');
                                    }
                                }
                                $uid = $user_info['uid'];
                                $qr_url = $this->create_qr($openid, 2);
                                $map = array('uid' => $uid, 'wx_id' => $wx_id, 'time' => time(), 'money' => '50000.00', 'shengyumoney' => '50000.00', 'count' => 0, 'status' => 1, 'qr_url' => $qr_url, 'type' => 2);
                                //保存砍主信息
                                $kj_id = M('kanjia')->add($map);
                                if ($kj_id) {
                                    $wechat->replyNewsOnce("[有人@你]5万积分等你来拿!!", "此链接是您的专属链接,请分享让朋友帮您砍价,由“壹圆购物”助力夺宝", "http://www.eyuanduobao.com/index.php/Wechat/Kanjia/index?kj_id=" . $kj_id, "http://www.eyuanduobao.com/Public/images/kj2.png");
                                } else {
                                    $Auth->sendText($openid, "当前参与活动人数太多,请稍后重试");
                                }
                            }
                            exit;
                        }
                        if (!empty($data['EventKey'])) {
                            $uid = $data['EventKey'];
                            $type = $uid[0];
                            $uid = substr($uid, 1);
                            //砍主openid
                            $openid = M('member')->where(array('uid' => $uid))->limit(1)->getField('openid');
                            //来源openid
                            $form_openid = $data['FromUserName'];
                            //找到这个砍价消息
                            $D = D('Common/KanjiaUser', 'VModel');
                            $kanjia_info = $D->where(array('uid' => $uid, 'type' => $type))->find();
                            if (empty($kanjia_info)) {
                                $wechat->replyText("系统错误,找不到此砍价信息!{$uid} | {$type} |");
                                exit;
                            }
                            //找出此人的wx_id
                            $wx_id = M('wx_user')->where(array('openid' => $form_openid))->getField('wx_id');
                            //判断是否已经帮砍过了
                            $is_bangkan = M('bangkan')->where(array('wx_id' => $wx_id, 'kj_id' => $kanjia_info['kj_id']))->find();
                            if ($is_bangkan) {
                                //判断是否注册用户
                                //如果是注册用户可以再砍一次
                                $is_register = M('member')->where(array('openid' => $form_openid))->find();
                                if (empty($is_register)) {
                                    $wechat->replyText("/玫瑰 注册成为会员并通过微信登陆即可帮ta再砍一刀哦!");
                                    exit;
                                }
                                if ($is_register['is_kan']) {
                                    $wechat->replyText("/玫瑰 1.关注微信\n/玫瑰 2.注册成为会员\n以上2种方法都可以帮ta砍一次哦~\nps:注册还可以免费抽iphone哦~");
                                    exit;
                                } else {
                                    M('member')->where(array('uid' => $is_register['uid']))->setField('is_kan', 1);
                                }
                            }
                            //找出剩余的钱
                            $shengyumoney = $kanjia_info['shengyumoney'];
                            //区间砍价金额
                            $rule_map['type'] = $kanjia_info['type'];
                            $area = M('kanjiarule')->where($rule_map)->order('kjr_yikan ASC')->select();
                            if (empty($area)) {
                                //区间砍价金额
                                if ($shengyumoney >= 3000) {
                                    $money100 = mt_rand(0, 1) * 100;
                                    $money10 = mt_rand(0, 9) * 10;
                                    $money1 = mt_rand(0, 9) * 1;
                                    $moneyf = mt_rand(1, 9) * 0.1;
                                    $moneyf2 = mt_rand(0, 0) * 0.01;
                                }
                                if ($shengyumoney >= 1000 && $shengyumoney < 3000) {
                                    $money100 = mt_rand(0, 0) * 100;
                                    $money10 = mt_rand(0, 7) * 10;
                                    $money1 = mt_rand(0, 9) * 1;
                                    $moneyf = mt_rand(1, 9) * 0.1;
                                    $moneyf2 = mt_rand(0, 0) * 0.01;
                                }
                                if ($shengyumoney >= 500 && $shengyumoney < 1000) {
                                    $money100 = mt_rand(0, 0) * 100;
                                    $money10 = mt_rand(0, 0) * 10;
                                    $money1 = mt_rand(0, 9) * 1;
                                    $moneyf = mt_rand(1, 9) * 0.1;
                                    $moneyf2 = mt_rand(0, 0) * 0.01;
                                }
                                if ($shengyumoney < 500) {
                                    $money100 = mt_rand(0, 0) * 100;
                                    $money10 = mt_rand(0, 0) * 10;
                                    $money1 = mt_rand(0, 0) * 1;
                                    $moneyf = mt_rand(0, 9) * 0.1;
                                    $moneyf2 = mt_rand(1, 9) * 0.01;
                                }
                                $add_money = $money100 + $money10 + $money1 + $moneyf + $moneyf2;
                            } else {
                                //计算已砍比例
                                $yikan = $kanjia_info['money'] - $kanjia_info['shengyumoney'];
                                $yikan_bl = round($yikan / $kanjia_info['money'] * 100, 2);
                                //找到它所在的区间
                                foreach ($area as $key => $value) {
                                    if ($yikan_bl <= $value['kjr_yikan']) {
                                        $min = $value['kjr_min'];
                                        $max = $value['kjr_max'];
                                        if ($min > 0 && $max > 0) {
                                            $min = (int) $min;
                                            $max = (int) $max;
                                            $add_money1 = mt_rand($min, $max - 1);
                                            $add_money2 = mt_rand(1, 99) / 100;
                                            $add_money = $add_money1 + $add_money2;
                                        } elseif ($min <= 0 && $max >= 0) {
                                            $min = (int) ($min * 100);
                                            $max = (int) $max;
                                            $add_money1 = mt_rand(0, $max - 1);
                                            $add_money2 = mt_rand($min, 99) / 100;
                                            $add_money = $add_money1 + $add_money2;
                                        } elseif ($min <= 0 && $max <= 0) {
                                            $min = (int) ($min * 100);
                                            $max = (int) ($max * 100);
                                            $add_money1 = mt_rand(0, 0);
                                            $add_money2 = mt_rand($min, $max) / 100;
                                            $add_money = $add_money1 + $add_money2;
                                        } else {
                                            $add_money1 = mt_rand(0, 99);
                                            $add_money2 = mt_rand(1, 99) / 100;
                                            $add_money = $add_money1 + $add_money2;
                                        }
                                        break;
                                    } else {
                                        $add_money2 = mt_rand(1, 99) / 100;
                                        $add_money = $add_money2;
                                    }
                                }
                            }
                            if ($shengyumoney <= 50) {
                                $wechat->replyText("当前活动已经结束,请留意最新中奖公告");
                                exit;
                            }
                            //保存砍价记录
                            $wx_id = M('wx_user')->where(array('openid' => $form_openid))->getField('wx_id');
                            // 如果没有获取到该砍主的微信信息
                            if (empty($wx_id)) {
                                //获取来源者信息
                                $add_info = $Auth->userInfo($form_openid);
                                //保存关注者信息
                                if (!M('wx_user')->where(array('openid' => $form_openid))->Find()) {
                                    // M('wx_user')->where(array('openid'=>$form['openid']))->delete();
                                    if (M('wx_user')->add($add_info) === false) {
                                        $this->replyText("当前参与活动人数太多,请稍后重试");
                                        exit;
                                    }
                                    $wx_id = M('wx_user')->where(array('openid' => $form_openid))->getField('wx_id');
                                } else {
                                    $wechat->replyText("当前参与活动人数太多,请稍后重试");
                                    exit;
                                }
                            }
                            $bangkan_add = array('wx_id' => $wx_id, 'kj_id' => $kanjia_info['kj_id'], 'bk_money' => $add_money, 'bk_time' => time());
                            //开启事物
                            M()->startTrans();
                            //保存帮砍信息
                            $add_status = M('bangkan')->add($bangkan_add);
                            //更新砍主信息
                            $save_status = M('kanjia')->where(array('kj_id' => $kanjia_info['kj_id']))->setField('shengyumoney', round($shengyumoney - $add_money, 2));
                            M('kanjia')->where(array('kj_id' => $kanjia_info['kj_id']))->setINC('count', 1);
                            if ($add_status && $save_status) {
                                M()->commit();
                            } else {
                                M()->rollback();
                                $wechat->replyText("当前参与活动人数太多,请稍后重试");
                                exit;
                            }
                            //获取来源者信息
                            $form = $Auth->userInfo($form_openid);
                            $rs = $Auth->userInfo($openid);
                            //发送消息给砍主
                            $Auth->sendText($openid, '您的好友“' . $form['nickname'] . '”\\n帮您砍下了' . $add_money . '元,快去答谢他(她)吧/示爱');
                            $wechat->replyText("您刚刚帮助您的好友[" . $rs['nickname'] . "]砍了" . $add_money . "元");
                        }
                        break;
                    case "CLICK":
                        if ($data['EventKey'] == "图文") {
                            //判断是否已经注册
                            $openid = $data['FromUserName'];
                            $user_info = M('member')->where(array('openid' => $openid))->find();
                            // $Auth->sendText($openid,$openid);
                            if (empty($user_info)) {
                                $back = $Auth->sendText($openid, "您还未注册/未绑定微信 \\d 请点击下面链接进行注册/登陆绑定");
                                if ($back) {
                                    $wechat->replyNewsOnce("点击注册送福气!", "只需几步即可完成注册", "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx1b4f89570d3f4976&redirect_uri=http%3A%2F%2Fwww.eyuanduobao.com%2Findex.php%2FHome%2FPerson%2Fme&response_type=code&scope=snsapi_base&state=STATE", "http://pic.qiantucdn.com/58pic/18/32/60/10c58PICXbP_1024.jpg");
                                }
                            } else {
                                //判断砍主是否已经曾经参与
                                if ($kj_id = M('kanjia')->where(array('uid' => $user_info['uid'], 'type' => 1))->getField('kj_id')) {
                                    $wechat->replyNewsOnce("[有人@你]您有一台Iphone6S尚未领取", "此链接是您的专属链接,请分享让朋友帮您砍价,由“壹圆购物”助力夺宝", "http://www.eyuanduobao.com/index.php/Wechat/Kanjia/index?kj_id=" . $kj_id, "http://www.eyuanduobao.com/Public/images/kj.png");
                                    exit;
                                }
                                /*保存砍主信息*/
                                //找到砍主id
                                $wx_id = M('wx_user')->where(array('openid' => $openid))->getField('wx_id');
                                // 如果没有获取到该砍主的微信信息
                                if (empty($wx_id)) {
                                    //获取来源者信息
                                    $add_info = $Auth->userInfo($openid);
                                    //保存关注者信息
                                    if (!M('wx_user')->where(array('openid' => $form['openid']))->Find()) {
                                        // M('wx_user')->where(array('openid'=>$form['openid']))->delete();
                                        if (M('wx_user')->add($add_info) === false) {
                                            $this->replyText("当前参与活动人数太多,请稍后重试");
                                            exit;
                                        }
                                        $wx_id = M('wx_user')->where(array('openid' => $openid))->getField('wx_id');
                                    }
                                }
                                $uid = $user_info['uid'];
                                $qr_url = $this->create_qr($openid, 1);
                                $map = array('uid' => $uid, 'wx_id' => $wx_id, 'time' => time(), 'money' => '7888.00', 'shengyumoney' => '7888.00', 'count' => 0, 'status' => 1, 'qr_url' => $qr_url, 'type' => 1);
                                //保存砍主信息
                                $kj_id = M('kanjia')->add($map);
                                if ($kj_id) {
                                    $wechat->replyNewsOnce("[有人@你]您有一台Iphone6S尚未领取", "此链接是您的专属链接,请分享让朋友帮您砍价,由“壹圆购物”助力夺宝", "http://www.eyuanduobao.com/index.php/Wechat/Kanjia/index?kj_id=" . $kj_id, "http://www.eyuanduobao.com/Public/images/kj.png");
                                } else {
                                    $Auth->sendText($openid, "当前参与活动人数太多,请稍后重试");
                                }
                            }
                        }
                        if ($data['EventKey'] == "图文2") {
                            //判断是否已经注册
                            $openid = $data['FromUserName'];
                            $user_info = M('member')->where(array('openid' => $openid))->find();
                            // $Auth->sendText($openid,$openid);
                            if (empty($user_info)) {
                                $back = $Auth->sendText($openid, "您还未注册/未绑定微信 \\d 请点击下面链接进行注册/登陆绑定");
                                if ($back) {
                                    $wechat->replyNewsOnce("点击注册送福气!", "只需几步即可完成注册", "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx1b4f89570d3f4976&redirect_uri=http%3A%2F%2Fwww.eyuanduobao.com%2Findex.php%2FHome%2FPerson%2Fme&response_type=code&scope=snsapi_base&state=STATE", "http://pic.qiantucdn.com/58pic/18/32/60/10c58PICXbP_1024.jpg");
                                }
                            } else {
                                //判断砍主是否已经曾经参与
                                if ($kj_id = M('kanjia')->where(array('uid' => $user_info['uid'], 'type' => 2))->getField('kj_id')) {
                                    $wechat->replyNewsOnce("[有人@你]5万积分等你来拿!!", "此链接是您的专属链接,请分享让朋友帮您砍价,由“壹圆购物”助力夺宝", "http://www.eyuanduobao.com/index.php/Wechat/Kanjia/index?kj_id=" . $kj_id, "http://www.eyuanduobao.com/Public/images/kj2.png");
                                    exit;
                                }
                                /*保存砍主信息*/
                                //找到砍主id
                                $wx_id = M('wx_user')->where(array('openid' => $openid))->getField('wx_id');
                                // 如果没有获取到该砍主的微信信息
                                if (empty($wx_id)) {
                                    //获取来源者信息
                                    $add_info = $Auth->userInfo($openid);
                                    //保存关注者信息
                                    if (!M('wx_user')->where(array('openid' => $form['openid']))->Find()) {
                                        // M('wx_user')->where(array('openid'=>$form['openid']))->delete();
                                        if (M('wx_user')->add($add_info) === false) {
                                            $this->replyText("当前参与活动人数太多,请稍后重试");
                                            exit;
                                        }
                                        $wx_id = M('wx_user')->where(array('openid' => $openid))->getField('wx_id');
                                    }
                                }
                                $uid = $user_info['uid'];
                                $qr_url = $this->create_qr($openid, 2);
                                $map = array('uid' => $uid, 'wx_id' => $wx_id, 'time' => time(), 'money' => '50000.00', 'shengyumoney' => '50000.00', 'count' => 0, 'status' => 1, 'qr_url' => $qr_url, 'type' => 2);
                                //保存砍主信息
                                $kj_id = M('kanjia')->add($map);
                                if ($kj_id) {
                                    $wechat->replyNewsOnce("[有人@你]5万积分等你来拿!!", "此链接是您的专属链接,请分享让朋友帮您砍价,由“壹圆购物”助力夺宝", "http://www.eyuanduobao.com/index.php/Wechat/Kanjia/index?kj_id=" . $kj_id, "http://www.eyuanduobao.com/Public/images/kj2.png");
                                } else {
                                    $Auth->sendText($openid, "当前参与活动人数太多,请稍后重试");
                                }
                            }
                        }
                        break;
                    default:
                        // $wechat->replyText("欢迎访问[壹圆购物]公众平台!您的事件类型:{$data['Event']},EventKey:{$data['EventKey']}");
                        $wechat->replyText("亲,想参与最新0元砍价活动。请点击下方菜单");
                        break;
                }
                break;
            case Wechat::MSG_TYPE_TEXT:
                switch ($data['Content']) {
                    case '联系我们':
                        $wechat->replyText('在这个平台里,你的事就是我的事啦、/得意
那我将有什么事情还没解决的呢?/可爱 你可以在这里给我们发信息,我们会在工作时间回复您的。/亲亲也可以拨打电话:400-671-6080 /玫瑰/玫瑰/玫瑰');
                        break;
                        // case '图片':
                        //     //$media_id = $this->upload('image');
                        //     $media_id = '1J03FqvqN_jWX6xe8F-VJr7QHVTQsJBS6x4uwKuzyLE';
                        //     $wechat->replyImage($media_id);
                        //     break;
                        // case '语音':
                        //     //$media_id = $this->upload('voice');
                        //     $media_id = '1J03FqvqN_jWX6xe8F-VJgisW3vE28MpNljNnUeD3Pc';
                        //     $wechat->replyVoice($media_id);
                        //     break;
                        // case '视频':
                        //     //$media_id = $this->upload('video');
                        //     $media_id = '1J03FqvqN_jWX6xe8F-VJn9Qv0O96rcQgITYPxEIXiQ';
                        //     $wechat->replyVideo($media_id, '视频标题', '视频描述信息。。。');
                        //     break;
                        // case '音乐':
                        //     //$thumb_media_id = $this->upload('thumb');
                        //     $thumb_media_id = '1J03FqvqN_jWX6xe8F-VJrjYzcBAhhglm48EhwNoBLA';
                        //     $wechat->replyMusic(
                        //         'Wakawaka!',
                        //         'Shakira - Waka Waka, MaxRNB - Your first R/Hiphop source',
                        //         'http://wechat.zjzit.cn/Public/music.mp3',
                        //         'http://wechat.zjzit.cn/Public/music.mp3',
                        //         $thumb_media_id
                        //     ); //回复音乐消息
                        //     break;
                    // case '图片':
                    //     //$media_id = $this->upload('image');
                    //     $media_id = '1J03FqvqN_jWX6xe8F-VJr7QHVTQsJBS6x4uwKuzyLE';
                    //     $wechat->replyImage($media_id);
                    //     break;
                    // case '语音':
                    //     //$media_id = $this->upload('voice');
                    //     $media_id = '1J03FqvqN_jWX6xe8F-VJgisW3vE28MpNljNnUeD3Pc';
                    //     $wechat->replyVoice($media_id);
                    //     break;
                    // case '视频':
                    //     //$media_id = $this->upload('video');
                    //     $media_id = '1J03FqvqN_jWX6xe8F-VJn9Qv0O96rcQgITYPxEIXiQ';
                    //     $wechat->replyVideo($media_id, '视频标题', '视频描述信息。。。');
                    //     break;
                    // case '音乐':
                    //     //$thumb_media_id = $this->upload('thumb');
                    //     $thumb_media_id = '1J03FqvqN_jWX6xe8F-VJrjYzcBAhhglm48EhwNoBLA';
                    //     $wechat->replyMusic(
                    //         'Wakawaka!',
                    //         'Shakira - Waka Waka, MaxRNB - Your first R/Hiphop source',
                    //         'http://wechat.zjzit.cn/Public/music.mp3',
                    //         'http://wechat.zjzit.cn/Public/music.mp3',
                    //         $thumb_media_id
                    //     ); //回复音乐消息
                    //     break;
                    case '图文':
                        //回复单条图文消息
                        break;
                        // case '多图文':
                        //     $news = array(
                        //         "全民创业蒙的就是你,来一盆冷水吧!",
                        //         "全民创业已经如火如荼,然而创业是一个非常自我的过程,它是一种生活方式的选择。从外部的推动有助于提高创业的存活率,但是未必能够提高创新的成功率。第一次创业的人,至少90%以上都会以失败而告终。创业成功者大部分年龄在30岁到38岁之间,而且创业成功最高的概率是第三次创业。",
                        //         "http://www.topthink.com/topic/11991.html",
                        //         "http://yun.topthink.com/Uploads/Editor/2015-07-30/55b991cad4c48.jpg"
                        //     ); //回复单条图文消息
                        $wechat->replyNews($news, $news, $news, $news, $news);
                        break;
                    default:
                        $wechat->replyText("(●˘◡˘●) 想参与最新活动吗?\n\n /玫瑰 0元得iphone6s\n /玫瑰 领取5万积分\n\n 点击下方菜单\n->[惊喜无限]参与活动吧!");
                        break;
                }
                break;
            default:
                # code...
                break;
        }
    }
Beispiel #3
0
    /**
     * DEMO
     * @param  Object $wechat Wechat对象
     * @param  array  $data   接受到微信推送的消息
     */
    private function demo($wechat, $data)
    {
        $wx_info = C('wx_info');
        $Auth = new WechatAuth($wx_info['AppID'], $wx_info['Secret'], S('access_token'));
        switch ($data['MsgType']) {
            case Wechat::MSG_TYPE_EVENT:
                switch ($data['Event']) {
                    case Wechat::MSG_EVENT_SUBSCRIBE:
                        //来源openid
                        $form_openid = $data['FromUserName'];
                        //获取来源者信息
                        $form = $Auth->userInfo($form_openid);
                        //保存关注者信息
                        if (!M('wx_user')->where(array('openid' => $form['openid']))->Find()) {
                            // M('wx_user')->where(array('openid'=>$form['openid']))->delete();
                            M('wx_user')->add($form);
                        }
                        $wechat->replyText('哟呵~主子终于等到你,还好我没放屁啊!/示爱/示爱/示爱
欢迎来到【壹易购物】王国游戏王国待会就更新啦,更多消息,请留意我们的微信公众号和新浪微博
请直接点击底部菜单,尽情购物吧!/玫瑰/玫瑰/玫瑰');
                        break;
                    case Wechat::MSG_EVENT_UNSUBSCRIBE:
                        //取消关注,记录日志
                        break;
                        //通过分享出去的扫码事件
                    //通过分享出去的扫码事件
                    case 'SCAN':
                        $wechat->replyText("点击下方菜单【免费奶茶】可以参与活动哦~");
                        break;
                    case "CLICK":
                        if ($data['EventKey'] == "联系我们") {
                            $wechat->replyText('在这个平台里,你的事就是我的事啦、/得意
那我将有什么事情还没解决的呢?/可爱 你可以在这里给我们发信息,我们会在工作时间回复您的。/亲亲也可以拨打电话:400-671-6080 /玫瑰/玫瑰/玫瑰');
                        } elseif ($data['EventKey'] == "naicha") {
                            //检测此用户有没有注册
                            $openid = $data['FromUserName'];
                            $user_info = M('member')->where(array('openid' => $openid))->find();
                            if (!$user_info) {
                                $Auth->sendText($openid, "您还未注册或未绑定微信 \n\n /玫瑰<a href='http://www.eyuanduobao.com/index.php/Home/Public/login'>请点击点击此处进行登陆</a>\n");
                                exit;
                            }
                            //查一下这个人有没有未成功砍价的记录
                            $kj_record = M('kanjia')->where(array('uid' => $user_info['uid'], 'status' => 1, 'type' => 3))->find();
                            $count = M('kanjia')->where(array('uid' => $user_info['uid'], 'shengyumoney' => 0, 'type' => 3))->count();
                            if ($count >= 1) {
                                $Auth->sendText($openid, "您已经成功参与并曾成功获得" . $count . "箱午後奶茶,再接再厉哦~");
                            }
                            //查这个人的wx_id
                            $wx_id = M('wx_user')->where(array('openid' => $openid))->getField('wx_id');
                            if (empty($wx_id)) {
                                $form = $Auth->userInfo($openid);
                                //保存关注者信息
                                if (!M('wx_user')->where(array('openid' => $openid))->Find()) {
                                    // M('wx_user')->where(array('openid'=>$form['openid']))->delete();
                                    $wx_id = M('wx_user')->add($form);
                                }
                            }
                            if ($kj_record) {
                                //查看kj_id
                                $Auth->sendText($openid, "转发您的专属链接即可邀请好友帮你助力获取午後奶茶哦~");
                                $wechat->replyNewsOnce("邀请好友即可获得一箱奶茶!", "此链接为您的专属链接,转发邀请好友帮你获得奶茶一箱", "http://www.eyuanduobao.com/index.php/Wechat/kanjia/index?kj_id=" . $kj_record['kj_id'], "http://www.eyuanduobao.com/Public/images/wuhounaicha_banner.jpg");
                            } else {
                                $new_array = array('uid' => $user_info['uid'], 'money' => 30, 'shengyumoney' => 30, 'count' => 0, 'status' => 1, 'time' => time(), 'type' => 3, 'wx_id' => $wx_id);
                                $add_status = M('kanjia')->add($new_array);
                                if ($add_status) {
                                    // $wechat->replyText("您的kj_id=".$add_status);
                                    $Auth->sendText($openid, "转发您的专属链接即可邀请好友帮你助力获取午後奶茶哦~");
                                    $wechat->replyNewsOnce("邀请好友即可获得一箱奶茶!", "此链接为您的专属链接,转发邀请好友帮你获得奶茶一箱", "http://www.eyuanduobao.com/index.php/Wechat/kanjia/index?kj_id=" . $add_status, "http://www.eyuanduobao.com/Public/images/wuhounaicha_banner.jpg");
                                } else {
                                    $wechat->replyText("系统有误,请联系管理员");
                                }
                            }
                            exit;
                        } else {
                            $wechat->replyText("亲,想参与最新0元砍价活动。请点击下方菜单");
                        }
                        break;
                    default:
                        $wechat->replyText("亲,想参与最新0元砍价活动。请点击下方菜单");
                        break;
                }
                break;
            case Wechat::MSG_TYPE_TEXT:
                switch ($data['Content']) {
                    case '联系我们':
                        $wechat->replyText('在这个平台里,你的事就是我的事啦、/得意
那我将有什么事情还没解决的呢?/可爱 你可以在这里给我们发信息,我们会在工作时间回复您的。/亲亲也可以拨打电话:400-671-6080 /玫瑰/玫瑰/玫瑰');
                        break;
                    case '注册':
                        $wechat->replyNewsOnce("点击注册送福气!", "只需几步即可完成注册", "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx1b4f89570d3f4976&redirect_uri=http%3A%2F%2Fwww.eyuanduobao.com%2Findex.php%2FHome%2FPerson%2Fme&response_type=code&scope=snsapi_base&state=STATE", "http://pic.qiantucdn.com/58pic/18/32/60/10c58PICXbP_1024.jpg");
                        break;
                    case '活动':
                        $wechat->replyText("/玫瑰 点击下方菜单【免费奶茶】\n\n 免费品尝午后奶茶一箱,活动真实有效!");
                        break;
                    case '投票':
                        $wechat->replyText("/玫瑰 点击下方菜单【免费奶茶】\n\n 免费品尝午后奶茶一箱,活动真实有效!");
                        break;
                    case '砍价':
                        $wechat->replyText("/玫瑰 点击下方菜单【免费奶茶】\n\n 免费品尝午后奶茶一箱,活动真实有效!");
                        break;
                    case '参与活动':
                        $wechat->replyText("/玫瑰 点击下方菜单【免费奶茶】\n\n 免费品尝午后奶茶一箱,活动真实有效!");
                        break;
                    case '我要参与':
                        $wechat->replyText("/玫瑰 点击下方菜单【免费奶茶】\n\n 免费品尝午后奶茶一箱,活动真实有效!");
                        break;
                        // case '图片':
                        //     $media_id = $this->upload('image');
                        //     $media_id = '1J03FqvqN_jWX6xe8F-VJr7QHVTQsJBS6x4uwKuzyLE';
                        //     $wechat->replyImage($media_id);
                        //     break;
                        // case '语音':
                        //     //$media_id = $this->upload('voice');
                        //     $media_id = '1J03FqvqN_jWX6xe8F-VJgisW3vE28MpNljNnUeD3Pc';
                        //     $wechat->replyVoice($media_id);
                        //     break;
                        // case '视频':
                        //     //$media_id = $this->upload('video');
                        //     $media_id = '1J03FqvqN_jWX6xe8F-VJn9Qv0O96rcQgITYPxEIXiQ';
                        //     $wechat->replyVideo($media_id, '视频标题', '视频描述信息。。。');
                        //     break;
                        // case '音乐':
                        //     //$thumb_media_id = $this->upload('thumb');
                        //     $thumb_media_id = '1J03FqvqN_jWX6xe8F-VJrjYzcBAhhglm48EhwNoBLA';
                        //     $wechat->replyMusic(
                        //         'Wakawaka!',
                        //         'Shakira - Waka Waka, MaxRNB - Your first R/Hiphop source',
                        //         'http://wechat.zjzit.cn/Public/music.mp3',
                        //         'http://wechat.zjzit.cn/Public/music.mp3',
                        //         $thumb_media_id
                        //     ); //回复音乐消息
                        //     break;
                    // case '图片':
                    //     $media_id = $this->upload('image');
                    //     $media_id = '1J03FqvqN_jWX6xe8F-VJr7QHVTQsJBS6x4uwKuzyLE';
                    //     $wechat->replyImage($media_id);
                    //     break;
                    // case '语音':
                    //     //$media_id = $this->upload('voice');
                    //     $media_id = '1J03FqvqN_jWX6xe8F-VJgisW3vE28MpNljNnUeD3Pc';
                    //     $wechat->replyVoice($media_id);
                    //     break;
                    // case '视频':
                    //     //$media_id = $this->upload('video');
                    //     $media_id = '1J03FqvqN_jWX6xe8F-VJn9Qv0O96rcQgITYPxEIXiQ';
                    //     $wechat->replyVideo($media_id, '视频标题', '视频描述信息。。。');
                    //     break;
                    // case '音乐':
                    //     //$thumb_media_id = $this->upload('thumb');
                    //     $thumb_media_id = '1J03FqvqN_jWX6xe8F-VJrjYzcBAhhglm48EhwNoBLA';
                    //     $wechat->replyMusic(
                    //         'Wakawaka!',
                    //         'Shakira - Waka Waka, MaxRNB - Your first R/Hiphop source',
                    //         'http://wechat.zjzit.cn/Public/music.mp3',
                    //         'http://wechat.zjzit.cn/Public/music.mp3',
                    //         $thumb_media_id
                    //     ); //回复音乐消息
                    //     break;
                    case '奶茶':
                        //回复单条图文消息
                        //检测此用户有没有注册
                        $openid = $data['FromUserName'];
                        $user_info = M('member')->where(array('openid' => $openid))->find();
                        if (!$user_info) {
                            $Auth->sendText($openid, "您还未注册或未绑定微信 \n\n /玫瑰<a href='http://www.eyuanduobao.com/index.php/Home/Public/login'>请点击点击此处进行登陆</a>\n");
                            exit;
                        }
                        // $Auth->sendText($openid,$user_info['uid']);die;
                        //查一下这个人有没有未成功砍价的记录
                        $kj_record = M('kanjia')->where(array('uid' => $user_info['uid'], 'status' => 1, 'type' => 3))->find();
                        $count = M('kanjia')->where(array('uid' => $user_info['uid'], 'shengyumoney' => 0, 'type' => 3))->count();
                        if ($count >= 1) {
                            $Auth->sendText($openid, "您已经成功参与并曾成功获得" . $count . "箱午後奶茶,再接再厉哦~");
                        }
                        //查这个人的wx_id
                        $wx_id = M('wx_user')->where(array('openid' => $openid))->getField('wx_id');
                        if (empty($wx_id)) {
                            $form = $Auth->userInfo($openid);
                            //保存关注者信息
                            if (!M('wx_user')->where(array('openid' => $openid))->Find()) {
                                // M('wx_user')->where(array('openid'=>$form['openid']))->delete();
                                $wx_id = M('wx_user')->add($form);
                            }
                        }
                        if ($kj_record) {
                            //查看kj_id
                            $Auth->sendText($openid, "转发您的专属链接即可邀请好友帮你助力获取午後奶茶哦~");
                            $wechat->replyNewsOnce("邀请好友即可获得一箱奶茶!", "此链接为您的专属链接,转发邀请好友帮你获得奶茶一箱", "http://www.eyuanduobao.com/index.php/Wechat/kanjia/index?kj_id=" . $kj_record['kj_id'], "http://www.eyuanduobao.com/Public/images/wuhounaicha_banner.jpg");
                        } else {
                            $new_array = array('uid' => $user_info['uid'], 'money' => 30, 'shengyumoney' => 30, 'count' => 0, 'status' => 1, 'time' => time(), 'type' => 3, 'wx_id' => $wx_id);
                            $add_status = M('kanjia')->add($new_array);
                            if ($add_status) {
                                // $wechat->replyText("您的kj_id=".$add_status);
                                $Auth->sendText($openid, "转发您的专属链接即可邀请好友帮你助力获取午後奶茶哦~");
                                $wechat->replyNewsOnce("邀请好友即可获得一箱奶茶!", "此链接为您的专属链接,转发邀请好友帮你获得奶茶一箱", "http://www.eyuanduobao.com/index.php/Wechat/kanjia/index?kj_id=" . $add_status, "http://www.eyuanduobao.com/Public/images/wuhounaicha_banner.jpg");
                            } else {
                                $wechat->replyText("系统有误,请联系管理员");
                            }
                        }
                        exit;
                        break;
                        // case '多图文':
                        //     $news = array(
                        //         "全民创业蒙的就是你,来一盆冷水吧!",
                        //         "全民创业已经如火如荼,然而创业是一个非常自我的过程,它是一种生活方式的选择。从外部的推动有助于提高创业的存活率,但是未必能够提高创新的成功率。第一次创业的人,至少90%以上都会以失败而告终。创业成功者大部分年龄在30岁到38岁之间,而且创业成功最高的概率是第三次创业。",
                        //         "http://www.topthink.com/topic/11991.html",
                        //         "http://yun.topthink.com/Uploads/Editor/2015-07-30/55b991cad4c48.jpg"
                        //     ); //回复单条图文消息
                        $wechat->replyNews($news, $news, $news, $news, $news);
                        break;
                    default:
                        $wechat->replyText("(●˘◡˘●) 想参与最新活动吗?\n\n  /玫瑰 免费奶茶\n\n点击下方菜单\n->[免费奶茶]参与活动吧!");
                        break;
                }
                break;
            default:
                # code...
                break;
        }
    }