UserNoticeService.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace App\Services\Notice;
  3. use App\Http\Controllers\Miniprogram\Core;
  4. use App\Http\Controllers\Wechat\Kfaccount;
  5. use App\Models\NoticeModel;
  6. use App\Models\User\Openid;
  7. use App\Models\User\UserModel;
  8. use App\Services\Log\NoticeLogService;
  9. use Illuminate\Support\Facades\Redis;
  10. class UserNoticeService
  11. {
  12. public function test(int $uid)
  13. {
  14. Redis::sadd("fpdx_supervip_test", $uid);
  15. $title = "内测邀请通知";
  16. $uuid = uuid();
  17. $to_uid = $uid;
  18. try {
  19. $titles = [
  20. "👑送你一个免费的超级会员~",
  21. "❤️恭喜你成为“心动考验”内测用户",
  22. ];
  23. $contents = [
  24. "参与内测,抢先体验新玩法“心动考验”!\n通过[①接唱]、[②问答]的方式设置考验,对你发出邀请的人需通过考验。完成两项设置,即可获得7天超级会员体验资格!",
  25. "新玩法抢先体验!通过[①接唱]、[②问答]的方式设置考验,对你发出邀请的人需通过考验。完成两项设置,还可获得7天超级会员👑体验资格!",
  26. ];
  27. // 发送系统消息
  28. NoticeModel::create([
  29. 'type' => 5,
  30. 'uid' => $uid,
  31. 'create_at' => time(),
  32. 'title' => $titles[rand(0, 1)],
  33. 'content' => $contents[rand(0, 1)],
  34. 'tab_content' => '参与内测',
  35. 'tab_url' => '/invite-test/pages/my-test/my-test',
  36. 'tab_action' => 'test',
  37. ]);
  38. $nls = new NoticeLogService();
  39. $content = "[爱心]恭喜你获得新玩法【心动考验】内测资格(每日限量100人)\n\n完成两项“心动考验”设置,可获得7天超级会员👑体验资格!\n同时你的交友卡片将被优先展示并拥有专属显示样式✨,增加三倍受邀率。\n心动考验:通过[接唱],[问答]的方式设置考验,对你发出邀请的人需通过考验。";
  40. $openid = Openid::ofPublic($uid)->value('openid');
  41. $page = "pages/starter/starter?log_type=notice&log_id={$uuid}&launch_type=free&url=%2Fpages%2Fsystem-notice%2Fsystem-notice%3Faction%3Dtest";
  42. // 客服消息
  43. $kfcontent = "{$content}\n\n<a data-miniprogram-appid='wx4c1722a4055bd229' data-miniprogram-path='{$page}'>点此体验新玩法</a>";
  44. $response = Kfaccount::text([
  45. 'touser' => $openid,
  46. 'content' => $kfcontent,
  47. 'kf_account' => 'notice@admin',
  48. ]);
  49. if ($response['code'] == 0) {
  50. $nls->record($uid, $title, "公众号客服消息", $uuid, 1, $kfcontent);
  51. return true;
  52. }
  53. // 模板消息
  54. $user = UserModel::findOrFail($uid);
  55. $public_id = \config('wechat.fpdx.public_id');
  56. $template_id = "QsgWayipj_3nUDIcLOWqPZI3Rm1D9SYCELfNeF-PgWs";
  57. $data = [
  58. 'first' => [
  59. 'value' => "❤恭️喜你获得全新功能「心动考验」内测资格(每天限量500人)每日前100名设置考验的用户还可获得7天超级会员体验资格!!\n",
  60. ],
  61. 'keyword1' => [
  62. 'value' => $user->nickname,
  63. ],
  64. 'keyword2' => [
  65. 'value' => "即日起30日内有效",
  66. ],
  67. 'keyword3' => [
  68. 'value' => "设置考验测ta真心:考验设置后,对你发出心动邀请需通过考验!同时你的交友卡片将拥有专属心动邀请显示样式,增加3倍受邀率!",
  69. ],
  70. 'keyword4' => [
  71. 'value' => date('Y-m-d'),
  72. ],
  73. 'remark' => [
  74. 'value' => "点此参与内测",
  75. "color" => "#FF7E98",
  76. ],
  77. ];
  78. $core = new Core();
  79. $result = $core->template($user->uid, $template_id, $public_id, $page, $data);
  80. if ($result) {
  81. $nls->record($user->uid, $title, "公众号模板消息", $uuid, 1, $data);
  82. return true;
  83. }
  84. } catch (\Exception $exception) {
  85. app('sentry')->captureException($exception);
  86. }
  87. $nls->record($to_uid, $title, "发送失败", $uuid);
  88. return false;
  89. }
  90. }