Guide.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. <?php
  2. namespace App\Http\Controllers\Miniprogram;
  3. use App\Services\App\KfService;
  4. use Illuminate\Http\Request;
  5. use App\Http\Controllers\Controller;
  6. use App\Models\User\AuthKey;
  7. use App\Models\Common\FormidModel;
  8. class Guide extends Controller
  9. {
  10. /**
  11. * 发送客服消息
  12. * @param string $type
  13. * @param string|null $openid
  14. * @return array
  15. * @throws \Psr\SimpleCache\InvalidArgumentException
  16. * @throws \Tymon\JWTAuth\Exceptions\JWTException
  17. */
  18. public function custom(string $type, string $openid = null)
  19. {
  20. if (empty($openid)) {
  21. $uid = Auth::auth();
  22. } else {
  23. try {
  24. $akm = new AuthKey();
  25. $uid = $akm->getUidByKey($openid);
  26. } catch (\Exception $e) {
  27. $uid = null;
  28. }
  29. }
  30. $kfs = new KfService();
  31. switch ($type) {
  32. // 情报局报名
  33. case 'qbj_enroll_text':
  34. $data = [
  35. 'msgtype' => 'text',
  36. 'text' => [
  37. 'content' => "点击下方图片,长按扫码↓↓\n↓快速报名参加时遇记情报局↓\n(扫码后不错过活动动态)!"
  38. ]
  39. ];
  40. break;
  41. case 'qbj_enroll_img':
  42. $data = [
  43. 'msgtype' => 'image',
  44. 'image' => [
  45. 'media_id' => $kfs->getMedia("qbj_enroll")
  46. ]
  47. ];
  48. break;
  49. // 活动报名
  50. case 'enroll_text':
  51. $data = [
  52. 'msgtype' => 'text',
  53. 'text' => [
  54. 'content' => "点击下方图片,长按扫码↓↓\n↓快速报名72小时恋爱体验活动↓\n(扫码后不错过活动动态)!"
  55. ]
  56. ];
  57. break;
  58. case 'enroll_img_0':
  59. $data = [
  60. 'msgtype' => 'image',
  61. 'image' => [
  62. 'media_id' => $kfs->getMedia("enrollkd_ce5103f65339")
  63. ]
  64. ];
  65. break;
  66. case 'enroll_img':
  67. $data = [
  68. 'msgtype' => 'image',
  69. 'image' => [
  70. 'media_id' => $kfs->getMedia("enroll")
  71. ]
  72. ];
  73. break;
  74. case 'enroll_img_2':
  75. $data = [
  76. 'msgtype' => 'image',
  77. 'image' => [
  78. 'media_id' => $kfs->getMedia("enrollkd_5edc93aa148e")
  79. ]
  80. ];
  81. break;
  82. case 'enroll_img_3':
  83. $data = [
  84. 'msgtype' => 'image',
  85. 'image' => [
  86. 'media_id' => $kfs->getMedia('enrollkd_qqzonesaohui')
  87. ]
  88. ];
  89. break;
  90. case 'enroll_img_4':
  91. $data = [
  92. 'msgtype' => 'image',
  93. 'image' => [
  94. 'media_id' => $kfs->getMedia('enrollkd_qzoneguanzhu')
  95. ]
  96. ];
  97. break;
  98. case 'enroll_img_5':
  99. $data = [
  100. 'msgtype' => 'image',
  101. 'image' => [
  102. 'media_id' => $kfs->getMedia('enrollkd_b598cb7474d8')
  103. ]
  104. ];
  105. break;
  106. case 'enroll_img_6':
  107. $data = [
  108. 'msgtype' => 'image',
  109. 'image' => [
  110. 'media_id' => $kfs->getMedia('enrollkd_wxkefuxiaoyu')
  111. ]
  112. ];
  113. break;
  114. case 'enroll_img_7':
  115. $data = [
  116. 'msgtype' => 'image',
  117. 'image' => [
  118. 'media_id' => $kfs->getMedia('enrollkd_fuwuhaoqunfa')
  119. ]
  120. ];
  121. break;
  122. case 'enroll_img_8':
  123. $data = [
  124. 'msgtype' => 'image',
  125. 'image' => [
  126. 'media_id' => $kfs->getMedia('enrollkd_dingyuequnfa')
  127. ]
  128. ];
  129. break;
  130. case 'enroll_img_9':
  131. $data = [
  132. 'msgtype' => 'image',
  133. 'image' => [
  134. 'media_id' => $kfs->getMedia('enrollkd_laiyuanpuapp')
  135. ]
  136. ];
  137. break;
  138. // 进入公众号聊天
  139. case 'intoroom_text':
  140. $data = [
  141. 'msgtype' => 'text',
  142. 'text' => [
  143. 'content' => "点击下方图片,长按扫码↓↓\n↓按提示进入房间,体验极速聊天↓"
  144. ],
  145. ];
  146. break;
  147. case 'intoroom_img':
  148. $data = [
  149. 'msgtype' => 'image',
  150. 'image' => [
  151. 'media_id' => $kfs->getMedia('intoroom'),
  152. ]
  153. ];
  154. break;
  155. // 订阅抽奖提醒
  156. case 'lotteryremind_text':
  157. $data = [
  158. 'msgtype' => 'text',
  159. 'text' => [
  160. 'content' => "点击下方图片,长按扫码↓↓\n↓开启抽奖通知,不错过中奖信息↓"
  161. ],
  162. ];
  163. break;
  164. case 'lotteryremind_img':
  165. $data = [
  166. 'msgtype' => 'image',
  167. 'image' => [
  168. 'media_id' => $kfs->getMedia('lotteryremind'),
  169. ]
  170. ];
  171. break;
  172. // 72小时活动确认客服
  173. case 'wxkf_text':
  174. try {
  175. $kfs = new KfService();
  176. $wxid = $kfs->hashWxkf($uid);
  177. if ($wxid) {
  178. $data = [
  179. 'msgtype' => 'text',
  180. 'text' => [
  181. 'content' => "点击下方图片,长按扫码添加专属客服!!!\n\n添加后回复【CP】,即可确认CP关系"
  182. ],
  183. ];
  184. \DB::table('kdgx_fpdx_wxkf')->where('wxid', $wxid)->increment('replay_cnt', 1);
  185. } else {
  186. $data = [
  187. 'msgtype' => 'text',
  188. 'text' => [
  189. 'content' => "点此确认CP关系: https://m.fenpeiduixiang.com/fpdx-bindwxid/index.html"
  190. ],
  191. ];
  192. }
  193. } catch (\Exception $e) {
  194. app('sentry')->captureException($e);
  195. $data = [
  196. 'msgtype' => 'text',
  197. 'text' => [
  198. 'content' => "点此确认CP关系: https://m.fenpeiduixiang.com/fpdx-bindwxid/index.html"
  199. ],
  200. ];
  201. }
  202. break;
  203. case 'wxkf_img':
  204. try {
  205. $kfs = new KfService();
  206. $wxid = $kfs->hashWxkf($uid);
  207. if ($wxid) {
  208. $data = [
  209. 'msgtype' => 'image',
  210. 'image' => [
  211. 'media_id' => $kfs->getMedia($wxid),
  212. ]
  213. ];
  214. } else {
  215. return [
  216. 'code' => 200,
  217. 'message' => 'success'
  218. ];
  219. }
  220. } catch (\Exception $e) {
  221. app('sentry')->captureException($e);
  222. return [
  223. 'code' => 200,
  224. 'message' => 'success'
  225. ];
  226. }
  227. break;
  228. // 添加微信认证专员
  229. case 'wxkfzy_text':
  230. try {
  231. if (is_null($uid)) {
  232. $data = [
  233. 'msgtype' => 'text',
  234. 'text' => [
  235. 'content' => "用户身份识别失败,无法获取认证客服号。请按以下流程操作:1. 点击长按下方图片,绑定身份。\n2. 重新进入小程序客服消息(即当前页面)回复[认证]获取认证客服号。\n3. 如还是\"用户身份识别失败,无法获取认证客服号\",回复「客服」联系小象导,并提供此错误码:「{$openid}」(直接复制,错误码尽量不要截图)和你的uid(不知道uid?可以咨询小象导)"
  236. ],
  237. ];
  238. } else {
  239. $kfs = new KfService();
  240. $wxid = $kfs->hashWxshzy($uid);
  241. if ($wxid) {
  242. $data = [
  243. 'msgtype' => 'text',
  244. 'text' => [
  245. 'content' => "点击长按下方图片,添加审核专员\n👇👇👇👇👇\n\n添加后回复「认证」,快速认证"
  246. ],
  247. ];
  248. } else {
  249. $data = [
  250. 'msgtype' => 'text',
  251. 'text' => [
  252. 'content' => "审核专员繁忙,请稍后重试。。。"
  253. ],
  254. ];
  255. }
  256. }
  257. } catch (\Exception $e) {
  258. app('sentry')->captureException($e);
  259. return [
  260. 'code' => 200,
  261. 'message' => 'success'
  262. ];
  263. }
  264. break;
  265. case 'wxkfzy_img':
  266. try {
  267. if (is_null($uid)) {
  268. $data = [
  269. 'msgtype' => 'image',
  270. 'image' => [
  271. 'media_id' => $kfs->getMedia("bindauthkey"),
  272. ]
  273. ];
  274. } else {
  275. $kfs = new KfService();
  276. $wxid = $kfs->hashWxshzy($uid);
  277. if ($wxid) {
  278. $data = [
  279. 'msgtype' => 'image',
  280. 'image' => [
  281. 'media_id' => $kfs->getMedia($wxid),
  282. ]
  283. ];
  284. \DB::table('kdgx_fpdx_wxkf')->where('wxid', $wxid)->increment('replay_cnt', 1);
  285. } else {
  286. $data = [
  287. 'msgtype' => 'text',
  288. 'text' => [
  289. 'content' => "审核专员繁忙,请稍后重试。。。"
  290. ],
  291. ];
  292. return [
  293. 'code' => 200,
  294. 'message' => 'success'
  295. ];
  296. }
  297. }
  298. } catch (\Exception $e) {
  299. app('sentry')->captureException($e);
  300. return [
  301. 'code' => 200,
  302. 'message' => 'success'
  303. ];
  304. }
  305. break;
  306. // 打开通知
  307. case 'notice_text':
  308. $data = [
  309. 'msgtype' => 'text',
  310. 'text' => [
  311. 'content' => "点击下方图片,长按扫码↓↓↓开启消息通知能力↓"
  312. ]
  313. ];
  314. break;
  315. case 'notice_img':
  316. $data = [
  317. 'msgtype' => 'image',
  318. 'image' => [
  319. 'media_id' => $kfs->getMedia('notice')
  320. ]
  321. ];
  322. break;
  323. // 心动邀请订阅通知
  324. case 'pair_notice_text':
  325. case 'invitation_text':
  326. $data = [
  327. 'msgtype' => 'text',
  328. 'text' => [
  329. 'content' => "点击下方图片,长按扫码↓↓↓订阅提醒↓↓↓"
  330. ]
  331. ];
  332. break;
  333. case 'invitation_img':
  334. $data = [
  335. 'msgtype' => 'image',
  336. 'image' => [
  337. 'media_id' => $kfs->getMedia('invitation')
  338. ]
  339. ];
  340. break;
  341. // 订阅匹配结果通知
  342. case 'pair_notice_img':
  343. $data = [
  344. 'msgtype' => 'image',
  345. 'image' => [
  346. 'media_id' => $kfs->getMedia('pair_notice')
  347. ]
  348. ];
  349. break;
  350. // 订阅开黑通知
  351. case 'gteam_notice_text':
  352. $data = [
  353. 'msgtype' => 'text',
  354. 'text' => [
  355. 'content' => "点击下方图片,长按扫码↓↓↓订阅提醒↓"
  356. ]
  357. ];
  358. break;
  359. case 'gteam_notice_img':
  360. $data = [
  361. 'msgtype' => 'image',
  362. 'image' => [
  363. 'media_id' => $kfs->getMedia('gteam_notice')
  364. ]
  365. ];
  366. break;
  367. // 联系客服小象导
  368. case 'kfxxd_text':
  369. $data = [
  370. 'msgtype' => 'text',
  371. 'text' => [
  372. 'content' => "点击下方图片,长按扫码↓↓↓联系客服,碰到任何问题,都可以来找小象导哦~↓"
  373. ]
  374. ];
  375. break;
  376. case 'kfxxd_img':
  377. $data = [
  378. 'msgtype' => 'image',
  379. 'image' => [
  380. 'media_id' => $kfs->getMedia('fpdxkfgzh')
  381. ]
  382. ];
  383. break;
  384. // 订阅晚安伴侣|留言通知
  385. case 'goodnight_chat_text':
  386. $data = [
  387. 'msgtype' => 'text',
  388. 'text' => [
  389. 'content' => "点击下方图片,长按扫码↓↓↓获取提醒↓↓↓"
  390. ]
  391. ];
  392. break;
  393. case 'goodnight_chat_img':
  394. $data = [
  395. 'msgtype' => 'image',
  396. 'image' => [
  397. 'media_id' => $kfs->getMedia('goodnight_chat')
  398. ]
  399. ];
  400. break;
  401. // 激活会员
  402. case 'tobe_vip_text':
  403. $data = [
  404. 'msgtype' => 'text',
  405. 'text' => [
  406. 'content' => "点击下方图片,长按扫码马上激活会员。"
  407. ]
  408. ];
  409. break;
  410. case 'tobe_vip_img':
  411. $data = [
  412. 'msgtype' => 'image',
  413. 'image' => [
  414. 'media_id' => $kfs->getMedia('tobe_vip')
  415. ]
  416. ];
  417. break;
  418. // 领取会员红包
  419. case 'get_vip_flower_text':
  420. $data = [
  421. 'msgtype' => 'text',
  422. 'text' => [
  423. 'content' => "点击下方图片,长按扫码领取每日红包"
  424. ]
  425. ];
  426. break;
  427. case 'get_vip_flower_img':
  428. $data = [
  429. 'msgtype' => 'image',
  430. 'image' => [
  431. 'media_id' => $kfs->getMedia('get_vip_flower')
  432. ]
  433. ];
  434. break;
  435. case "app":
  436. $data = [
  437. 'msgtype' => 'text',
  438. 'text' => [
  439. 'content' => "<a href='https://a.app.qq.com/o/simple.jsp?pkgname=com.fenpeiduixiang.www'>点此下载/更新分配对象APP-></a>
  440. 重要更新 v1.0.9:
  441. 1、正式上线72小时CP功能,大家可以在App中报名参与活动啦!超即时通知,不错过活动动态;
  442. 2、修复已知Bug,细节优化完善;
  443. 3、v1.1.0在路上,请大家期待。"
  444. ]
  445. ];
  446. break;
  447. case 'gh_01c089b58dda_default':
  448. $data = [
  449. 'msgtype' => 'text',
  450. 'text' => [
  451. 'content' => "回复:[1]活动报名(公众号快速通道)
  452. 回复:[2]打开「好友/心动」消息提醒
  453. 回复:[3]确认CP关系
  454. 回复:[4]抽奖提醒
  455. 回复:[5]打开通知
  456. 回复:[客服]联系客服
  457. 回复:[认证]添加微信认证专员
  458. 回复:[聊天]开启公众号聊天
  459. 回复:[123]下载/更新分配对象App"
  460. ],
  461. ];
  462. break;
  463. default:
  464. $data = [
  465. 'msgtype' => 'text',
  466. 'text' => [
  467. 'content' => "很抱歉,消息通知/聊天等相关功能正在维护中,请稍后再试\n\n*如需联系客服,请搜索关注公众号【分配对象】点按菜单->72小时恋爱->反馈/联系客服\n\n*如需建立聊天链接,请搜索关注公众号【分配对象】点按菜单->聊天列表"
  468. ],
  469. ];
  470. break;
  471. }
  472. $data['touser'] = $openid;
  473. $core = new Core();
  474. $core->custom($uid, $data);
  475. return [
  476. 'code' => 200,
  477. 'message' => 'success'
  478. ];
  479. }
  480. /**
  481. * 记录formid
  482. * @param Request $request
  483. * @return array
  484. * @throws \App\Exceptions\AlertException
  485. * @throws \Tymon\JWTAuth\Exceptions\JWTException
  486. */
  487. public function logFormid(Request $request)
  488. {
  489. $this->validate($request, [
  490. 'form_id' => 'required',
  491. ]);
  492. if ($request->form_id == 'the formId is a mock one') {
  493. return response([
  494. 'code' => 200,
  495. 'message' => 'success'
  496. ]);
  497. }
  498. $public_id = config('miniprogram.public_id');
  499. try {
  500. $uid = Auth::auth();
  501. $authKey = new AuthKey();
  502. $openid = $authKey->getKeyOfType($uid, $public_id);
  503. } catch (\Exception $exception) {
  504. $uid = 0;
  505. $openid = $request->get('openid');
  506. if (empty($openid)) {
  507. return response([
  508. 'code' => 200,
  509. 'message' => 'success'
  510. ]);
  511. }
  512. }
  513. FormidModel::create([
  514. 'uid' => $uid,
  515. 'openid' => $openid,
  516. 'form_id' => $request->form_id,
  517. 'public_id' => $public_id,
  518. 'action_id' => $request->post('action_id') ?? 0,
  519. 'extra' => $request->post('extra') ? json_encode($request->post('extra')) : null,
  520. ]);
  521. return response([
  522. 'code' => 200,
  523. 'message' => 'success'
  524. ]);
  525. }
  526. }