Event.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. <?php
  2. namespace App\Http\Controllers\Wechat;
  3. use App\Exceptions\AlertException;
  4. use App\Exceptions\WeChatException;
  5. use App\Http\Controllers\Core\User as CoreUser;
  6. use App\Http\Controllers\Fpdx\RoomController;
  7. use App\Models\Common\NoticeManageModel;
  8. use App\Models\User\AuthKey;
  9. use App\Models\User\Openid;
  10. use App\Services\Deed\InvitationService;
  11. use App\Services\Deed\NoticeService;
  12. use App\Services\Notice\ManageService;
  13. use App\Services\NoticeService\Channels\WeChatTemplateChannel;
  14. use App\Services\User\ProfileService;
  15. use App\Services\User\TaskService;
  16. use Illuminate\Database\Eloquent\ModelNotFoundException;
  17. use Illuminate\Support\Facades\Redis;
  18. use App\Http\Controllers\Controller;
  19. use Ixudra\Curl\Facades\Curl;
  20. /**
  21. * Class Event
  22. * @package App\Http\Controllers\Wechat
  23. */
  24. class Event extends Controller
  25. {
  26. /**
  27. * 绑定微信身份的模版消息
  28. * @param string $openid
  29. * @param string $key
  30. * @return string
  31. */
  32. public function bindTemplate(string $openid, string $key)
  33. {
  34. $user_info = Fans::getUserInfo($openid);
  35. $template_id = "alWufNQA9zhVec2RynEUqEUIl2l7TJZjvI6K0YZLzJM";
  36. $page = "https://m.fenpeiduixiang.com/login/index.html?action=bind&key={$key}";
  37. $parameters = [
  38. 'first' => [
  39. 'value' => "请完成账号关联后继续进行该操作。"
  40. ],
  41. 'keyword1' => [
  42. 'value' => "{$user_info['nickname']}"
  43. ],
  44. 'keyword2' => [
  45. 'value' => date("Y-m-d H:i:s")
  46. ],
  47. 'remark' => [
  48. 'value' => "点此继续",
  49. "color" => "#FF7E98"
  50. ],
  51. ];
  52. $app = (new WeChatTemplateChannel())->setAppId(config("wechat.fpdx.public_id"));
  53. $app->setTitle("绑定微信身份")->toUser($openid)->setPage("")->setUrl($page)
  54. ->setTemplateId($template_id)->setParameters($parameters)
  55. ->send();
  56. return "success";
  57. }
  58. /**
  59. * 关注事件
  60. * @param $object
  61. * @return bool|string
  62. * @throws AlertException
  63. * @throws WeChatException
  64. * @throws \App\Exceptions\ApiException
  65. */
  66. public static function subscribe($object)
  67. {
  68. $user_info = Fans::getUserInfo($object->FromUserName);
  69. try {
  70. self::setTag($user_info);
  71. } catch (\Exception $e) {
  72. app('sentry')->captureException($e);
  73. }
  74. $openid = $object->FromUserName;
  75. $public_id = $object->ToUserName;
  76. /** @var string $public_id */
  77. $userinfo = \WeChat::Fans($public_id)->info($openid);
  78. $unionid = $userinfo['unionid'];
  79. $auth = AuthKey::where('auth_key', $unionid)->first();
  80. if ($auth) {
  81. $uid = $auth->uid;
  82. $response = Curl::to("http://api.deep.fenpeiduixiang.com/api/analytic/check/new/scan?uid={$uid}")->asJsonResponse(false)->get();
  83. $isexsts = Redis::Sismember("log:bevip:page:tag", $uid);
  84. if ((isset($response->isScan) && 1 == $response->isScan) || $isexsts) {
  85. $ps = new ProfileService();
  86. $ps->beVip($uid, true);
  87. }
  88. AuthKey::updateOrCreate(
  89. ['auth_key' => $openid, 'auth_type' => $public_id],
  90. ['uid' => $uid, 'login_at' => time()]
  91. );
  92. } else {
  93. if (empty($object->EventKey)) {
  94. return (new Event())->bindTemplate($openid, "tobe_vip");
  95. }
  96. }
  97. if (substr($object->EventKey, 0, 8) == 'qrscene_') {
  98. try {
  99. $object->EventKey = substr($object->EventKey, 8);
  100. parse_str($object->EventKey, $param);
  101. $from = isset($param['from']) ? $param['from'] : '';
  102. if (\DB::table('kdgx_fpdx_ta_event')->where('openid', $object->FromUserName)->first()) {
  103. \DB::table('kdgx_fpdx_ta_event')->where('openid', $object->FromUserName)->update([
  104. 'from' => $from,
  105. 'updated_at' => $object->CreateTime
  106. ]);
  107. } else {
  108. \DB::table('kdgx_fpdx_ta_event')->insert([
  109. 'openid' => $object->FromUserName,
  110. 'from' => $from,
  111. 'created_at' => $object->CreateTime,
  112. 'updated_at' => $object->CreateTime
  113. ]);
  114. }
  115. } catch (\Exception $exception) {
  116. app('sentry')->captureException($exception);
  117. }
  118. return static::scan($object);
  119. }
  120. return 'Success';
  121. }
  122. /**
  123. * @param $user_info
  124. * @throws \App\Services\WeChat\WeChatException
  125. */
  126. public static function setTag($user_info)
  127. {
  128. switch ($user_info['sex']) {
  129. case "1":
  130. $tagId = \WeChat::Tags(Config('wechat.fpdx.public_id'))->get("性别-男");
  131. if ($tagId) {
  132. \WeChat::Tags(Config('wechat.fpdx.public_id'))->batchTagging($user_info['openid'], $tagId);
  133. }
  134. break;
  135. case "2":
  136. $tagId = \WeChat::Tags(Config('wechat.fpdx.public_id'))->get("性别-女");
  137. if ($tagId) {
  138. \WeChat::Tags(Config('wechat.fpdx.public_id'))->batchTagging($user_info['openid'], $tagId);
  139. }
  140. break;
  141. default:
  142. $tagId = \WeChat::Tags(Config('wechat.fpdx.public_id'))->get("性别-未知");
  143. if ($tagId) {
  144. \WeChat::Tags(Config('wechat.fpdx.public_id'))->batchTagging($user_info['openid'], $tagId);
  145. }
  146. break;
  147. }
  148. }
  149. /**
  150. * 取关事件
  151. * @param $object
  152. * @return string
  153. * @throws WeChatException
  154. */
  155. public static function unsubscribe($object)
  156. {
  157. try {
  158. Openid::where('openid', $object->FromUserName)->update(['subscribe' => 0]);
  159. $openData = CoreUser::getUidByOpenid($object->FromUserName);
  160. $profs = new ProfileService();
  161. $profs->beVip($openData['uid'], false);
  162. } catch (\Exception $exception) {
  163. throw new WeChatException();
  164. }
  165. return 'Success';
  166. }
  167. /**
  168. * 扫码事件
  169. * @param $object
  170. * @return string
  171. * @throws AlertException
  172. * @throws WeChatException
  173. * @throws \App\Exceptions\ApiException
  174. */
  175. public static function scan($object)
  176. {
  177. parse_str($object->EventKey, $param);
  178. \DB::table('kdgx_fpdx_event')->insert([
  179. 'openid' => $object->FromUserName,
  180. 'key' => $object->EventKey,
  181. 'from' => isset($param['from']) ? $param['from'] : '',
  182. 'created_at' => $object->CreateTime
  183. ]);
  184. if (!isset($param['event'])) {
  185. throw new WeChatException();
  186. }
  187. switch ($param['event']) {
  188. case 'fpdx_task':
  189. $array = array(
  190. [
  191. 'Title' => '恋爱任务入口',
  192. 'Description' => '点此进入',
  193. 'Url' => 'http://www.pocketuniversity.cn/ChargePartner/http/mediaCouple?media_id=gh_b598cb7474d8&page=task'
  194. ]
  195. );
  196. return SendMsg::news($object, $array);
  197. case 'proenroll':
  198. $array = [
  199. [
  200. 'Title' => '欢迎来到分配对象',
  201. 'Description' => '点此互选对象,完成活动报名',
  202. 'Url' => 'http://www.pocketuniversity.cn/ChargePartner/Http/index?media_id=' . $object->ToUserName . '&media_name=fpdx&base_route=couple&page=matching&from=fpdx',
  203. ]
  204. ];
  205. return SendMsg::news($object, $array);
  206. case 'secret':
  207. if (isset($param['secret'])) {
  208. $secret = $param['secret'];
  209. } else {
  210. $user_info = Fans::getUserInfo($object->FromUserName);
  211. if ($user_info['sex'] == 2) {
  212. $secret_list = \DB::table('koudai.kdgx_partner_charge_partner')->where([
  213. 'sex' => 1,
  214. 'is_sell' => 1
  215. ])->orderBy('praises', 'desc')->limit(100)->pluck('secret');
  216. $secret = $secret_list[rand(0, $secret_list->count() - 1)];
  217. } else {
  218. $secret_list = \DB::table('koudai.kdgx_partner_charge_partner')->where([
  219. 'sex' => 2,
  220. 'is_sell' => 1
  221. ])->orderBy('praises', 'desc')->limit(500)->pluck('secret');
  222. $secret = $secret_list[rand(0, $secret_list->count() - 1)];
  223. }
  224. }
  225. $partner = \DB::table('kdgx_partner_charge_partner')->where([
  226. 'secret' => $secret,
  227. 'is_sell' => 1
  228. ])->first();
  229. if (!$partner) {
  230. $object->Content = '是想要联系方式吗?你的暗号错误或经本人要求暗号已失效,换个暗号试试吧!^-^!';
  231. return SendMsg::text($object);
  232. }
  233. if ($partner) {
  234. $array = [
  235. [
  236. 'Title' => $partner->introduce,
  237. 'PicUrl' => 'http://oss.pocketuniversity.cn/' . $partner->photo_src,
  238. 'Url' => "http://www.pocketuniversity.cn/ChargePartner/http/index?page=date&id={$partner->id}&media_id={$object->ToUserName}",
  239. ],
  240. [
  241. 'Title' => "\n🏫学校:{$partner->school}\n\n🕴身高:{$partner->height}cm\n\n🏝家乡:{$partner->home}\n\n💞魅力值:{($partner->praises/10)}",
  242. 'Url' => "http://www.pocketuniversity.cn/ChargePartner/http/index?page=date&id={$partner->id}&media_id={$object->ToUserName}",
  243. ],
  244. [
  245. 'Title' => "💁点此解锁Ta的联系方式(微信)☞",
  246. 'Url' => "http://www.pocketuniversity.cn/ChargePartner/http/index?page=date&id={$partner->id}&media_id={$object->ToUserName}",
  247. ]
  248. ];
  249. return SendMsg::news($object, $array);
  250. }
  251. break;
  252. case 'qbj_enroll':
  253. $object->Content = "<a href=\"https://m.fenpeiduixiang.com/fpdx-attend/index.html?media_id=gh_01c089b58dda&sd=23#/home/attend-form?type=qbj\">点此继续报名参与时遇记情报局~</a>";
  254. return SendMsg::text($object);
  255. case 'enroll':
  256. $object->Content = "<a href=\"https://m.fenpeiduixiang.com/fpdx-attend/index.html?media_id=gh_01c089b58dda#/home/attend-form\">点此继续报名参与72小时恋爱体验活动~</a>";
  257. return SendMsg::text($object);
  258. case 'enrollkd_ce5103f65339':
  259. $object->Content = "<a href=\"https://m.fenpeiduixiang.com/fpdx-attend/index.html?media_id=kd_ce5103f65339#/home/attend-form\">点此继续报名参与72小时恋爱体验活动~</a>";
  260. return SendMsg::text($object);
  261. case 'enrollkd_5edc93aa148e':
  262. $object->Content = "<a href=\"https://m.fenpeiduixiang.com/fpdx-attend/index.html?media_id=kd_5edc93aa148e#/home/attend-form\">点此继续报名参与72小时恋爱体验活动~</a>";
  263. return SendMsg::text($object);
  264. case 'enrollkd_qqzonesaohui':
  265. $object->Content = "<a href=\"https://m.fenpeiduixiang.com/fpdx-attend/index.html?media_id=kd_qqzonesaohui#/home/attend-form\">点此继续报名参与72小时恋爱体验活动~</a>";
  266. return SendMsg::text($object);
  267. case 'enrollkd_b598cb7474d8':
  268. $object->Content = "<a href=\"https://m.fenpeiduixiang.com/fpdx-attend/index.html?media_id=kd_b598cb7474d8#/home/attend-form\">点此继续报名参与72小时恋爱体验活动~</a>";
  269. return SendMsg::text($object);
  270. case 'enrollkd_wxkefuxiaoyu':
  271. $object->Content = "<a href=\"https://m.fenpeiduixiang.com/fpdx-attend/index.html?media_id=kd_wxkefuxiaoyu#/home/attend-form\">点此继续报名参与72小时恋爱体验活动~</a>";
  272. return SendMsg::text($object);
  273. case 'enrollkd_qzoneguanzhu':
  274. $object->Content = "<a href=\"https://m.fenpeiduixiang.com/fpdx-attend/index.html?media_id=kd_qzoneguanzhu#/home/attend-form\">点此继续报名参与72小时恋爱体验活动~</a>";
  275. return SendMsg::text($object);
  276. case 'enrollkd_fuwuhaoqunfa':
  277. $object->Content = "<a href=\"https://m.fenpeiduixiang.com/fpdx-attend/index.html?media_id=kd_fuwuhaoqunfa#/home/attend-form\">点此继续报名参与72小时恋爱体验活动~</a>";
  278. return SendMsg::text($object);
  279. case 'enrollkd_dingyuequnfa':
  280. $object->Content = "<a href=\"https://m.fenpeiduixiang.com/fpdx-attend/index.html?media_id=kd_dingyuequnfa#/home/attend-form\">点此继续报名参与72小时恋爱体验活动~</a>";
  281. return SendMsg::text($object);
  282. case 'enrollkd_laiyuanpuapp':
  283. $object->Content = "<a href=\"https://m.fenpeiduixiang.com/fpdx-attend/index.html?media_id=kd_laiyuanpuapp#/home/attend-form\">点此继续报名参与72小时恋爱体验活动~</a>";
  284. return SendMsg::text($object);
  285. case 'invite':
  286. try {
  287. // 获取uid
  288. $core = new CoreUser();
  289. $openData = $core->getUidByOpenid($object->FromUserName);
  290. $nms = new ManageService();
  291. $nms->getNoticeByUser($openData['uid']);
  292. NoticeManageModel::where([
  293. ['uid', $openData['uid']],
  294. ['key', 'flipped_notice']
  295. ])->update(['isopen' => 1]);
  296. $object->Content = "<a data-miniprogram-appid='wx4c1722a4055bd229' data-miniprogram-path='pages/index/index'>已开启好友申请|心动通知</a>";
  297. } catch (ModelNotFoundException $e) {
  298. return (new Event())->bindTemplate($object->FromUserName, "invitation");
  299. }
  300. return SendMsg::text($object);
  301. case 'ofogp':
  302. $array = [
  303. [
  304. 'Title' => 'ofo小黄车为杭州大学生分配对象啦,点此领取~',
  305. 'PicUrl' => 'https://mmbiz.qpic.cn/mmbiz_png/nAiaqJTVXP8Xr5jVPxltlVCqzqGRrASZJ3Fj9zn4k5SLX8M4K3gpJYERuyTUFYEjFVSDTboCftOicGfzs7XHdmhg/0?wx_fmt=png',
  306. 'Url' => 'https://mp.weixin.qq.com/s/ud7xj12AILkipA5WLiqREQ',
  307. ],
  308. [
  309. 'Title' => 'ofo校园缘分4元月卡,助力脱单,点此领取~',
  310. 'PicUrl' => 'https://mmbiz.qpic.cn/mmbiz_png/nAiaqJTVXP8Xr5jVPxltlVCqzqGRrASZJicViaGl0HtAv45pQTsic3X4icF8mkYDfMRmtkqXPas4kaPgrIckQ17v9hA/0?wx_fmt=png',
  311. 'Url' => 'https://mp.weixin.qq.com/s/F3TgQQTjKgBibUGFkX2doQ',
  312. ]
  313. ];
  314. return SendMsg::news($object, $array);
  315. case 'newuser':
  316. $array = [
  317. [
  318. 'Title' => '这是你们学校的交友名单,点此免费领取对象~',
  319. 'PicUrl' => 'http://oss.pocketuniversity.cn/media/2018-07-16/5b4c51b4a93e8.jpg',
  320. 'Url' => 'http://www.pocketuniversity.cn/ChargePartner/Http/index?need_school=1&media_id=gh_b598cb7474d8&media_name=fpdx',
  321. ],
  322. [
  323. 'Title' => '“新用户免费获取联系方式”教程',
  324. 'PicUrl' => 'https://mmbiz.qpic.cn/mmbiz_png/nAiaqJTVXP8W3fKRkOqCL69Z2b8YwJHCELGsl9FCBbDU3jeX4oszjvz5HNmXbSYhicKSeKlAhREwibWDkXrB5TDrg/0?wx_fmt=png',
  325. 'Url' => 'http://mp.weixin.qq.com/s/hr2e2RoKwQYIm4n4NgcdHQ',
  326. ]
  327. ];
  328. return SendMsg::news($object, $array);
  329. case 'pair_fail':
  330. $array = [
  331. [
  332. 'Title' => '点此退款或报名下一期',
  333. 'Description' => '分配对象,让美好的校园恋爱发生',
  334. 'PicUrl' => 'http://oss.pocketuniversity.cn/public/common/2017-11-08/4daf52864fc97b2d2c0b9b0f2f6afc95.png',
  335. 'Url' => 'http://www.pocketuniversity.cn/ChargePartner/http?media_id=gh_b598cb7474d8&media_name=fpdx&page=couple/list'
  336. ]
  337. ];
  338. return SendMsg::news($object, $array);
  339. case 'remind':
  340. $object->Content = "提醒订阅成功~";
  341. return SendMsg::text($object);
  342. break;
  343. case 'custom_service':
  344. $array = [
  345. [
  346. 'Title' => '点此联系客服',
  347. 'PicUrl' => 'http://wxpublic-1251448646.file.myqcloud.com/public/common/files/2018/06/640_356_21103007229201eaa6c.png',
  348. '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'
  349. ]
  350. ];
  351. return SendMsg::news($object, $array);
  352. case 'enroll_fpdx':
  353. $array = [
  354. [
  355. 'Title' => '点此报名“72小时恋爱体验”活动',
  356. 'PicUrl' => 'http://oss.pocketuniversity.cn/media/2018-08-01/5b6177baa39bb.jpg',
  357. 'Url' => 'http://www.pocketuniversity.cn/ChargePartner/Http/index?media_id=gh_b598cb7474d8&media_name=fpdx&page=couple'
  358. ],
  359. [
  360. 'Title' => '点此查看“玩法介绍和往期活动”',
  361. 'PicUrl' => 'http://oss.pocketuniversity.cn/media/2018-08-01/5b6179e274720.png',
  362. 'Url' => 'http://mp.weixin.qq.com/mp/homepage?__biz=MzU0NTU4NDcxNA==&hid=1&sn=c21f26c011cada6395e492d9607995d6&scene=18#wechat_redirect'
  363. ]
  364. ];
  365. return SendMsg::news($object, $array);
  366. case 'into_room':
  367. // 进入房间
  368. try {
  369. // 获取uid
  370. $core = new CoreUser();
  371. $openData = $core->getUidByOpenid($object->FromUserName);
  372. // 获取进房动作
  373. $param = Redis::hget("fpdx_mini_action:{$openData['uid']}", "mini_into_room");
  374. if (empty($param)) {
  375. throw new AlertException("无动作");
  376. }
  377. // 进入房间
  378. RoomController::into($openData['uid'], $param);
  379. } catch (\Exception $e) {
  380. $array = [
  381. [
  382. 'Title' => '聊天已建立,点此继续~',
  383. 'PicUrl' => 'http://oss.pocketuniversity.cn/media/2018-08-01/5b61996091933.png',
  384. 'Url' => 'http://www.pocketuniversity.cn/ChargePartner/http/mediaCouple#/fpdx-msg/list'
  385. ]
  386. ];
  387. return SendMsg::news($object, $array);
  388. }
  389. break;
  390. case 'pair_query':
  391. $array = [
  392. [
  393. 'Title' => '点此查看匹配详情',
  394. 'PicUrl' => 'http://oss.pocketuniversity.cn/media/2018-08-11/5b6e5999edfec.png',
  395. 'Url' => 'http://www.pocketuniversity.cn/ChargePartner/http?media_name=fpdx&base_route=couple&media_id=gh_b598cb7474d8'
  396. ]
  397. ];
  398. return SendMsg::news($object, $array);
  399. // 激活会员
  400. case 'tobe_vip':
  401. // 获取uid
  402. try {
  403. $core = new CoreUser();
  404. $openData = $core->getUidByOpenid($object->FromUserName);
  405. } catch (AlertException $exception) {
  406. return (new Event())->bindTemplate($object->FromUserName, "tobe_vip");
  407. }
  408. $ps = new ProfileService();
  409. $ps->beVip($openData['uid'], true, true);
  410. break;
  411. // 领取会员红包
  412. case 'get_vip_flower':
  413. try {
  414. $core = new CoreUser();
  415. $openData = $core->getUidByOpenid($object->FromUserName);
  416. } catch (ModelNotFoundException $exception) {
  417. return (new Event())->bindTemplate($object->FromUserName, "get_vip_flower");
  418. }
  419. $ts = new TaskService();
  420. try {
  421. $flower = $ts->getVipFlowerEveryDay($openData['uid']);
  422. $content = "<a data-miniprogram-appid='wx4c1722a4055bd229' data-miniprogram-path='pages/starter/starter?launch_type=free&url=%2Fpages%2Frest-of-money%2Frest-of-money'>恭喜你获得小fa:{$flower}朵,点此继续赚小fa。</a>";
  423. } catch (AlertException $exception) {
  424. $content = $exception->getMessage();
  425. if ($exception->getCode() == 102) {
  426. $content = "<a data-miniprogram-appid='wx4c1722a4055bd229' data-miniprogram-path='pages/starter/starter?launch_type=free&url=%2Fpages%2Fvip%2Fvip'>{$content}</a>";
  427. } else {
  428. $content = "<a data-miniprogram-appid='wx4c1722a4055bd229' data-miniprogram-path='pages/starter/starter?launch_type=free&url=%2Fpages%2Frest-of-money%2Frest-of-money'>{$content}</a>";
  429. }
  430. }
  431. $object->Content = $content;
  432. return SendMsg::text($object);
  433. break;
  434. case 'open_pair_notice':
  435. try {
  436. $core = new CoreUser();
  437. $openData = $core->getUidByOpenid($object->FromUserName);
  438. $uid = $openData['uid'];
  439. $group = 'fpdx';
  440. $open = 1;
  441. $ms = new ManageService();
  442. $ms->updateNoticeByGroup($uid, $group, $open);
  443. $object->Content = "<a data-miniprogram-appid='wx4c1722a4055bd229' data-miniprogram-path=''>活动提醒开启成功!点此查看报名状态,提升匹配成功率~</a>";
  444. return SendMsg::text($object);
  445. } catch (\Exception $e) {
  446. return (new Event())->bindTemplate($object->FromUserName, "pair_notice");
  447. }
  448. break;
  449. case 'notice': # 通知
  450. try {
  451. $core = new CoreUser();
  452. $openData = $core->getUidByOpenid($object->FromUserName);
  453. $object->Content = "<a data-miniprogram-appid='wx4c1722a4055bd229' data-miniprogram-path='pages/starter/starter?launch_type=free&url=%2Fpages%2Fnotice-setting%2Fnotice-setting'>通知功能开启成功,继续设置通知开关。</a>";
  454. return SendMsg::text($object);
  455. break;
  456. } catch (\Exception $e) {
  457. return (new Event())->bindTemplate($object->FromUserName, "notice");
  458. }
  459. break;
  460. case 'lottery_remind': # 抽奖提醒
  461. try {
  462. $core = new CoreUser();
  463. $openData = $core->getUidByOpenid($object->FromUserName);
  464. $object->Content = "<a data-miniprogram-appid='wx4c1722a4055bd229' data-miniprogram-path='pages/starter/starter?launch_type=free&url=%2Fpages%2Fnotice-setting%2Fnotice-setting'>抽奖提醒开启成功,继续设置通知开关。</a>";
  465. return SendMsg::text($object);
  466. break;
  467. } catch (\Exception $e) {
  468. return (new Event())->bindTemplate($object->FromUserName, "lotteryremind");
  469. }
  470. break;
  471. case 'gteam_notice': # 开黑提醒
  472. try {
  473. $core = new CoreUser();
  474. $openData = $core->getUidByOpenid($object->FromUserName);
  475. $uid = $openData['uid'];
  476. $notice = new ManageService();
  477. $is_open = $notice->updateNoticeByKey($uid, "gteam_match_success_notice", 1);
  478. $object->Content = "<a data-miniprogram-appid='wx4c1722a4055bd229' data-miniprogram-path='pages/starter/starter?launch_type=black&action=free&url=%2Fblack%2Fpages%2Fpersonal%2Fpersonal%3Flist_type%3Dbookhistory'>开黑通知订阅成功, 点此返回</a>";
  479. return SendMsg::text($object);
  480. } catch (\Exception $e) {
  481. return (new Event())->bindTemplate($object->FromUserName, "gteam_notice");
  482. }
  483. break;
  484. case 'goodnight_chat':
  485. try {
  486. $core = new CoreUser();
  487. $openData = $core->getUidByOpenid($object->FromUserName);
  488. $uid = $openData['uid'];
  489. $notice = new ManageService();
  490. $is_open = $notice->updateNoticeByKey($uid, "goodnight_room_chat_notice", 1);
  491. $object->Content = "已订阅晚安伴侣提醒";
  492. return SendMsg::text($object);
  493. } catch (\Exception $e) {
  494. return (new Event())->bindTemplate($object->FromUserName, "goodnight_chat");
  495. }
  496. break;
  497. case "hangzhou":
  498. try {
  499. $object->Content = "象友你好,终于来啦![玫瑰][玫瑰]在今后的日子中,我将带你认识异性,遇见心动~
  500. [跳跳]「72小时CP恋爱体验」杭州专场正在进行中,杭州的小伙伴不要错过哦,回复“<a href=\"weixin://bizmsgmenu?msgmenucontent=杭州&msgmenuid=234234\">杭州</a>”参与活动
  501. [爱心]更多有趣功能等你发现~~点击菜单“<a href=\"weixin://bizmsgmenu?msgmenucontent=进入小程序&msgmenuid=234234\">进入小程序</a>”试试
  502. 分配对象 · 火爆的95后恋爱社交小程序
  503. ————————
  504. <a href=\" \" data-miniprogram-appid=\"wx4c1722a4055bd229\" data-miniprogram-path=\"/pages/starter/starter?scene=media_id%3Dkd_hangzhou\">点此报名参与“72小时CP恋爱体验”杭州专场活动~</a>";
  505. return SendMsg::text($object);
  506. } catch (\Exception $e) {
  507. }
  508. break;
  509. }
  510. return 'Success';
  511. }
  512. /**
  513. * 点击事件
  514. * @param $object
  515. * @return string
  516. */
  517. public static function click($object)
  518. {
  519. switch ($object->EventKey) {
  520. case "menu_35410":
  521. $uid = \DB::table('kddx_user_openid')->where('openid', $object->FromUserName)->where(
  522. 'public_id',
  523. $object->ToUserName
  524. )->value('uid');
  525. if ($uid) {
  526. $notice = new NoticeService();
  527. $profile = NoticeManageModel::firstOrCreate([
  528. 'uid' => $uid,
  529. 'key' => 'flipped_notice'
  530. ], [
  531. 'group' => 'flipped',
  532. 'isopen' => 0
  533. ]);
  534. if ($profile->isopen == 0) {
  535. $notice->subscribe($uid);
  536. $content = "<a data-miniprogram-appid='wx4c1722a4055bd229' data-miniprogram-path='pages/starter/starter?launch_type=free&url=%2Fpages%2Ffriend%2Ffriend'>已订阅心动提醒, 点此进入小程序</a>";
  537. $object->Content = $content;
  538. } else {
  539. $content = "你正在退订「好友/心动」消息提醒!退订后,将无法收到心动提醒\n\n确定退订请【<a href='weixin://bizmsgmenu?msgmenucontent=退订心动提醒&msgmenuid=234234'>点此</a>】";
  540. $object->Content = $content;
  541. }
  542. return SendMsg::text($object);
  543. } else {
  544. $object->Content = "<a data-miniprogram-appid='wx4c1722a4055bd229' data-miniprogram-path='pages/starter/starter?launch_type=free&url=%2Fpages%2Ffriend%2Ffriend'>及时接收Ta的心动通知 点此订阅「心动通知」</a>";
  545. return SendMsg::text($object);
  546. }
  547. break;
  548. case "menu_36694":
  549. try {
  550. $openData = CoreUser::getUidByOpenid($object->FromUserName);
  551. $ins = new InvitationService();
  552. $dcnt = $ins->invitecnt($openData['uid']);
  553. $dmsg = "点此查看收到的好友申请,共收到{$dcnt['total']}条好友申请";
  554. $object->Content = "<a data-miniprogram-appid='wx4c1722a4055bd229' data-miniprogram-path='pages/starter/starter?launch_type=free&url=%2Fpages%2Ffriend%2Ffriend'>" . $dmsg . "</a>";
  555. return SendMsg::text($object);
  556. } catch (\Exception $e) {
  557. $dmsg = "点此查看收到的好友申请";
  558. $object->Content = "<a data-miniprogram-appid='wx4c1722a4055bd229' data-miniprogram-path='pages/starter/starter?launch_type=free&url=%2Fpages%2Ffriend%2Ffriend'>" . $dmsg . "</a>";
  559. return SendMsg::text($object);
  560. }
  561. break;
  562. }
  563. }
  564. }