[ 'value' => "请完成账号关联后继续进行该操作。" ], 'keyword1' => [ 'value' => "{$user_info['nickname']}" ], 'keyword2' => [ 'value' => date("Y-m-d H:i:s") ], 'remark' => [ 'value' => "点此继续", "color" => "#FF7E98" ], ]; $app = (new WeChatTemplateChannel())->setAppId(config("wechat.fpdx.public_id")); $app->setTitle("绑定微信身份")->toUser($openid)->setPage("")->setUrl($page) ->setTemplateId($template_id)->setParameters($parameters) ->send(); return "success"; } /** * 关注事件 * @param $object * @return bool|string * @throws AlertException * @throws WeChatException * @throws \App\Exceptions\ApiException */ public static function subscribe($object) { $user_info = Fans::getUserInfo($object->FromUserName); try { self::setTag($user_info); } catch (\Exception $e) { app('sentry')->captureException($e); } $openid = $object->FromUserName; $public_id = $object->ToUserName; /** @var string $public_id */ $userinfo = \WeChat::Fans($public_id)->info($openid); $unionid = $userinfo['unionid']; $auth = AuthKey::where('auth_key', $unionid)->first(); if ($auth) { $uid = $auth->uid; $response = Curl::to("http://api.deep.fenpeiduixiang.com/api/analytic/check/new/scan?uid={$uid}")->asJsonResponse(false)->get(); $isexsts = Redis::Sismember("log:bevip:page:tag", $uid); if ((isset($response->isScan) && 1 == $response->isScan) || $isexsts) { $ps = new ProfileService(); $ps->beVip($uid, true); } AuthKey::updateOrCreate( ['auth_key' => $openid, 'auth_type' => $public_id], ['uid' => $uid, 'login_at' => time()] ); } else { if (empty($object->EventKey)) { return (new Event())->bindTemplate($openid, "tobe_vip"); } } if (substr($object->EventKey, 0, 8) == 'qrscene_') { try { $object->EventKey = substr($object->EventKey, 8); parse_str($object->EventKey, $param); $from = isset($param['from']) ? $param['from'] : ''; if (\DB::table('kdgx_fpdx_ta_event')->where('openid', $object->FromUserName)->first()) { \DB::table('kdgx_fpdx_ta_event')->where('openid', $object->FromUserName)->update([ 'from' => $from, 'updated_at' => $object->CreateTime ]); } else { \DB::table('kdgx_fpdx_ta_event')->insert([ 'openid' => $object->FromUserName, 'from' => $from, 'created_at' => $object->CreateTime, 'updated_at' => $object->CreateTime ]); } } catch (\Exception $exception) { app('sentry')->captureException($exception); } return static::scan($object); } return 'Success'; } /** * @param $user_info * @throws \App\Services\WeChat\WeChatException */ public static function setTag($user_info) { switch ($user_info['sex']) { case "1": $tagId = \WeChat::Tags(Config('wechat.fpdx.public_id'))->get("性别-男"); if ($tagId) { \WeChat::Tags(Config('wechat.fpdx.public_id'))->batchTagging($user_info['openid'], $tagId); } break; case "2": $tagId = \WeChat::Tags(Config('wechat.fpdx.public_id'))->get("性别-女"); if ($tagId) { \WeChat::Tags(Config('wechat.fpdx.public_id'))->batchTagging($user_info['openid'], $tagId); } break; default: $tagId = \WeChat::Tags(Config('wechat.fpdx.public_id'))->get("性别-未知"); if ($tagId) { \WeChat::Tags(Config('wechat.fpdx.public_id'))->batchTagging($user_info['openid'], $tagId); } break; } } /** * 取关事件 * @param $object * @return string * @throws WeChatException */ public static function unsubscribe($object) { try { Openid::where('openid', $object->FromUserName)->update(['subscribe' => 0]); $openData = CoreUser::getUidByOpenid($object->FromUserName); $profs = new ProfileService(); $profs->beVip($openData['uid'], false); } catch (\Exception $exception) { throw new WeChatException(); } return 'Success'; } /** * 扫码事件 * @param $object * @return string * @throws AlertException * @throws WeChatException * @throws \App\Exceptions\ApiException */ public static function scan($object) { parse_str($object->EventKey, $param); \DB::table('kdgx_fpdx_event')->insert([ 'openid' => $object->FromUserName, 'key' => $object->EventKey, 'from' => isset($param['from']) ? $param['from'] : '', 'created_at' => $object->CreateTime ]); if (!isset($param['event'])) { throw new WeChatException(); } switch ($param['event']) { case 'fpdx_task': $array = array( [ 'Title' => '恋爱任务入口', 'Description' => '点此进入', 'Url' => 'http://www.pocketuniversity.cn/ChargePartner/http/mediaCouple?media_id=gh_b598cb7474d8&page=task' ] ); return SendMsg::news($object, $array); case 'proenroll': $array = [ [ 'Title' => '欢迎来到分配对象', 'Description' => '点此互选对象,完成活动报名', 'Url' => 'http://www.pocketuniversity.cn/ChargePartner/Http/index?media_id=' . $object->ToUserName . '&media_name=fpdx&base_route=couple&page=matching&from=fpdx', ] ]; return SendMsg::news($object, $array); case 'secret': if (isset($param['secret'])) { $secret = $param['secret']; } else { $user_info = Fans::getUserInfo($object->FromUserName); if ($user_info['sex'] == 2) { $secret_list = \DB::table('koudai.kdgx_partner_charge_partner')->where([ 'sex' => 1, 'is_sell' => 1 ])->orderBy('praises', 'desc')->limit(100)->pluck('secret'); $secret = $secret_list[rand(0, $secret_list->count() - 1)]; } else { $secret_list = \DB::table('koudai.kdgx_partner_charge_partner')->where([ 'sex' => 2, 'is_sell' => 1 ])->orderBy('praises', 'desc')->limit(500)->pluck('secret'); $secret = $secret_list[rand(0, $secret_list->count() - 1)]; } } $partner = \DB::table('kdgx_partner_charge_partner')->where([ 'secret' => $secret, 'is_sell' => 1 ])->first(); if (!$partner) { $object->Content = '是想要联系方式吗?你的暗号错误或经本人要求暗号已失效,换个暗号试试吧!^-^!'; return SendMsg::text($object); } if ($partner) { $array = [ [ 'Title' => $partner->introduce, 'PicUrl' => 'http://oss.pocketuniversity.cn/' . $partner->photo_src, 'Url' => "http://www.pocketuniversity.cn/ChargePartner/http/index?page=date&id={$partner->id}&media_id={$object->ToUserName}", ], [ 'Title' => "\n🏫学校:{$partner->school}\n\n🕴身高:{$partner->height}cm\n\n🏝家乡:{$partner->home}\n\n💞魅力值:{($partner->praises/10)}", 'Url' => "http://www.pocketuniversity.cn/ChargePartner/http/index?page=date&id={$partner->id}&media_id={$object->ToUserName}", ], [ 'Title' => "💁点此解锁Ta的联系方式(微信)☞", 'Url' => "http://www.pocketuniversity.cn/ChargePartner/http/index?page=date&id={$partner->id}&media_id={$object->ToUserName}", ] ]; return SendMsg::news($object, $array); } break; case 'qbj_enroll': $object->Content = "点此继续报名参与时遇记情报局~"; return SendMsg::text($object); case 'enroll': $object->Content = "点此继续报名参与72小时恋爱体验活动~"; return SendMsg::text($object); case 'enrollkd_ce5103f65339': $object->Content = "点此继续报名参与72小时恋爱体验活动~"; return SendMsg::text($object); case 'enrollkd_5edc93aa148e': $object->Content = "点此继续报名参与72小时恋爱体验活动~"; return SendMsg::text($object); case 'enrollkd_qqzonesaohui': $object->Content = "点此继续报名参与72小时恋爱体验活动~"; return SendMsg::text($object); case 'enrollkd_b598cb7474d8': $object->Content = "点此继续报名参与72小时恋爱体验活动~"; return SendMsg::text($object); case 'enrollkd_wxkefuxiaoyu': $object->Content = "点此继续报名参与72小时恋爱体验活动~"; return SendMsg::text($object); case 'enrollkd_qzoneguanzhu': $object->Content = "点此继续报名参与72小时恋爱体验活动~"; return SendMsg::text($object); case 'enrollkd_fuwuhaoqunfa': $object->Content = "点此继续报名参与72小时恋爱体验活动~"; return SendMsg::text($object); case 'enrollkd_dingyuequnfa': $object->Content = "点此继续报名参与72小时恋爱体验活动~"; return SendMsg::text($object); case 'enrollkd_laiyuanpuapp': $object->Content = "点此继续报名参与72小时恋爱体验活动~"; return SendMsg::text($object); case 'invite': try { // 获取uid $core = new CoreUser(); $openData = $core->getUidByOpenid($object->FromUserName); $nms = new ManageService(); $nms->getNoticeByUser($openData['uid']); NoticeManageModel::where([ ['uid', $openData['uid']], ['key', 'flipped_notice'] ])->update(['isopen' => 1]); $object->Content = "已开启好友申请|心动通知"; } catch (ModelNotFoundException $e) { return (new Event())->bindTemplate($object->FromUserName, "invitation"); } return SendMsg::text($object); case 'ofogp': $array = [ [ 'Title' => 'ofo小黄车为杭州大学生分配对象啦,点此领取~', 'PicUrl' => 'https://mmbiz.qpic.cn/mmbiz_png/nAiaqJTVXP8Xr5jVPxltlVCqzqGRrASZJ3Fj9zn4k5SLX8M4K3gpJYERuyTUFYEjFVSDTboCftOicGfzs7XHdmhg/0?wx_fmt=png', 'Url' => 'https://mp.weixin.qq.com/s/ud7xj12AILkipA5WLiqREQ', ], [ 'Title' => 'ofo校园缘分4元月卡,助力脱单,点此领取~', 'PicUrl' => 'https://mmbiz.qpic.cn/mmbiz_png/nAiaqJTVXP8Xr5jVPxltlVCqzqGRrASZJicViaGl0HtAv45pQTsic3X4icF8mkYDfMRmtkqXPas4kaPgrIckQ17v9hA/0?wx_fmt=png', 'Url' => 'https://mp.weixin.qq.com/s/F3TgQQTjKgBibUGFkX2doQ', ] ]; return SendMsg::news($object, $array); case 'newuser': $array = [ [ 'Title' => '这是你们学校的交友名单,点此免费领取对象~', 'PicUrl' => 'http://oss.pocketuniversity.cn/media/2018-07-16/5b4c51b4a93e8.jpg', 'Url' => 'http://www.pocketuniversity.cn/ChargePartner/Http/index?need_school=1&media_id=gh_b598cb7474d8&media_name=fpdx', ], [ 'Title' => '“新用户免费获取联系方式”教程', 'PicUrl' => 'https://mmbiz.qpic.cn/mmbiz_png/nAiaqJTVXP8W3fKRkOqCL69Z2b8YwJHCELGsl9FCBbDU3jeX4oszjvz5HNmXbSYhicKSeKlAhREwibWDkXrB5TDrg/0?wx_fmt=png', 'Url' => 'http://mp.weixin.qq.com/s/hr2e2RoKwQYIm4n4NgcdHQ', ] ]; return SendMsg::news($object, $array); case 'pair_fail': $array = [ [ 'Title' => '点此退款或报名下一期', 'Description' => '分配对象,让美好的校园恋爱发生', 'PicUrl' => 'http://oss.pocketuniversity.cn/public/common/2017-11-08/4daf52864fc97b2d2c0b9b0f2f6afc95.png', 'Url' => 'http://www.pocketuniversity.cn/ChargePartner/http?media_id=gh_b598cb7474d8&media_name=fpdx&page=couple/list' ] ]; return SendMsg::news($object, $array); case 'remind': $object->Content = "提醒订阅成功~"; return SendMsg::text($object); break; case 'custom_service': $array = [ [ 'Title' => '点此联系客服', 'PicUrl' => 'http://wxpublic-1251448646.file.myqcloud.com/public/common/files/2018/06/640_356_21103007229201eaa6c.png', 'Url' => 'http://www.pocketuniversity.cn/wxpay/jsapi/roommate.html?media_id=gh_b598cb7474d8&page=couple/list&media_name=fpdx&show_xxd=1#/couple/list?media_id=gh_b598cb7474d8&page=couple%2Flist&media_name=fpdx&show_xxd=1' ] ]; return SendMsg::news($object, $array); case 'enroll_fpdx': $array = [ [ 'Title' => '点此报名“72小时恋爱体验”活动', 'PicUrl' => 'http://oss.pocketuniversity.cn/media/2018-08-01/5b6177baa39bb.jpg', 'Url' => 'http://www.pocketuniversity.cn/ChargePartner/Http/index?media_id=gh_b598cb7474d8&media_name=fpdx&page=couple' ], [ 'Title' => '点此查看“玩法介绍和往期活动”', 'PicUrl' => 'http://oss.pocketuniversity.cn/media/2018-08-01/5b6179e274720.png', 'Url' => 'http://mp.weixin.qq.com/mp/homepage?__biz=MzU0NTU4NDcxNA==&hid=1&sn=c21f26c011cada6395e492d9607995d6&scene=18#wechat_redirect' ] ]; return SendMsg::news($object, $array); case 'into_room': // 进入房间 try { // 获取uid $core = new CoreUser(); $openData = $core->getUidByOpenid($object->FromUserName); // 获取进房动作 $param = Redis::hget("fpdx_mini_action:{$openData['uid']}", "mini_into_room"); if (empty($param)) { throw new AlertException("无动作"); } // 进入房间 RoomController::into($openData['uid'], $param); } catch (\Exception $e) { $array = [ [ 'Title' => '聊天已建立,点此继续~', 'PicUrl' => 'http://oss.pocketuniversity.cn/media/2018-08-01/5b61996091933.png', 'Url' => 'http://www.pocketuniversity.cn/ChargePartner/http/mediaCouple#/fpdx-msg/list' ] ]; return SendMsg::news($object, $array); } break; case 'pair_query': $array = [ [ 'Title' => '点此查看匹配详情', 'PicUrl' => 'http://oss.pocketuniversity.cn/media/2018-08-11/5b6e5999edfec.png', 'Url' => 'http://www.pocketuniversity.cn/ChargePartner/http?media_name=fpdx&base_route=couple&media_id=gh_b598cb7474d8' ] ]; return SendMsg::news($object, $array); // 激活会员 case 'tobe_vip': // 获取uid try { $core = new CoreUser(); $openData = $core->getUidByOpenid($object->FromUserName); } catch (AlertException $exception) { return (new Event())->bindTemplate($object->FromUserName, "tobe_vip"); } $ps = new ProfileService(); $ps->beVip($openData['uid'], true, true); break; // 领取会员红包 case 'get_vip_flower': try { $core = new CoreUser(); $openData = $core->getUidByOpenid($object->FromUserName); } catch (ModelNotFoundException $exception) { return (new Event())->bindTemplate($object->FromUserName, "get_vip_flower"); } $ts = new TaskService(); try { $flower = $ts->getVipFlowerEveryDay($openData['uid']); $content = "恭喜你获得小fa:{$flower}朵,点此继续赚小fa。"; } catch (AlertException $exception) { $content = $exception->getMessage(); if ($exception->getCode() == 102) { $content = "{$content}"; } else { $content = "{$content}"; } } $object->Content = $content; return SendMsg::text($object); break; case 'open_pair_notice': try { $core = new CoreUser(); $openData = $core->getUidByOpenid($object->FromUserName); $uid = $openData['uid']; $group = 'fpdx'; $open = 1; $ms = new ManageService(); $ms->updateNoticeByGroup($uid, $group, $open); $object->Content = "活动提醒开启成功!点此查看报名状态,提升匹配成功率~"; return SendMsg::text($object); } catch (\Exception $e) { return (new Event())->bindTemplate($object->FromUserName, "pair_notice"); } break; case 'notice': # 通知 try { $core = new CoreUser(); $openData = $core->getUidByOpenid($object->FromUserName); $object->Content = "通知功能开启成功,继续设置通知开关。"; return SendMsg::text($object); break; } catch (\Exception $e) { return (new Event())->bindTemplate($object->FromUserName, "notice"); } break; case 'lottery_remind': # 抽奖提醒 try { $core = new CoreUser(); $openData = $core->getUidByOpenid($object->FromUserName); $object->Content = "抽奖提醒开启成功,继续设置通知开关。"; return SendMsg::text($object); break; } catch (\Exception $e) { return (new Event())->bindTemplate($object->FromUserName, "lotteryremind"); } break; case 'gteam_notice': # 开黑提醒 try { $core = new CoreUser(); $openData = $core->getUidByOpenid($object->FromUserName); $uid = $openData['uid']; $notice = new ManageService(); $is_open = $notice->updateNoticeByKey($uid, "gteam_match_success_notice", 1); $object->Content = "开黑通知订阅成功, 点此返回"; return SendMsg::text($object); } catch (\Exception $e) { return (new Event())->bindTemplate($object->FromUserName, "gteam_notice"); } break; case 'goodnight_chat': try { $core = new CoreUser(); $openData = $core->getUidByOpenid($object->FromUserName); $uid = $openData['uid']; $notice = new ManageService(); $is_open = $notice->updateNoticeByKey($uid, "goodnight_room_chat_notice", 1); $object->Content = "已订阅晚安伴侣提醒"; return SendMsg::text($object); } catch (\Exception $e) { return (new Event())->bindTemplate($object->FromUserName, "goodnight_chat"); } break; case "hangzhou": try { $object->Content = "象友你好,终于来啦![玫瑰][玫瑰]在今后的日子中,我将带你认识异性,遇见心动~ [跳跳]「72小时CP恋爱体验」杭州专场正在进行中,杭州的小伙伴不要错过哦,回复“杭州”参与活动 [爱心]更多有趣功能等你发现~~点击菜单“进入小程序”试试 分配对象 · 火爆的95后恋爱社交小程序 ———————— 点此报名参与“72小时CP恋爱体验”杭州专场活动~"; return SendMsg::text($object); } catch (\Exception $e) { } break; } return 'Success'; } /** * 点击事件 * @param $object * @return string */ public static function click($object) { switch ($object->EventKey) { case "menu_35410": $uid = \DB::table('kddx_user_openid')->where('openid', $object->FromUserName)->where( 'public_id', $object->ToUserName )->value('uid'); if ($uid) { $notice = new NoticeService(); $profile = NoticeManageModel::firstOrCreate([ 'uid' => $uid, 'key' => 'flipped_notice' ], [ 'group' => 'flipped', 'isopen' => 0 ]); if ($profile->isopen == 0) { $notice->subscribe($uid); $content = "已订阅心动提醒, 点此进入小程序"; $object->Content = $content; } else { $content = "你正在退订「好友/心动」消息提醒!退订后,将无法收到心动提醒\n\n确定退订请【点此】"; $object->Content = $content; } return SendMsg::text($object); } else { $object->Content = "及时接收Ta的心动通知 点此订阅「心动通知」"; return SendMsg::text($object); } break; case "menu_36694": try { $openData = CoreUser::getUidByOpenid($object->FromUserName); $ins = new InvitationService(); $dcnt = $ins->invitecnt($openData['uid']); $dmsg = "点此查看收到的好友申请,共收到{$dcnt['total']}条好友申请"; $object->Content = "" . $dmsg . ""; return SendMsg::text($object); } catch (\Exception $e) { $dmsg = "点此查看收到的好友申请"; $object->Content = "" . $dmsg . ""; return SendMsg::text($object); } break; } } }