RecommendNotChangeNotification.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. namespace App\Services\Partner\Notifications;
  3. use App\Models\User\UserModel;
  4. use App\Services\NoticeService\Channels\MiniTemplateChannel;
  5. use App\Services\NoticeService\Channels\TemplateChannel;
  6. use App\Services\NoticeService\Notification;
  7. class RecommendNotChangeNotification extends Notification
  8. {
  9. protected $title = "交友卡片-卡片取消推荐未更换通知";
  10. private $user;
  11. public function __construct($to_uid)
  12. {
  13. parent::__construct($to_uid);
  14. $this->user = UserModel::select('nickname', 'sex')->find($to_uid);
  15. }
  16. /**
  17. * 是否订阅
  18. * @return bool
  19. */
  20. public function subscribe(): bool
  21. {
  22. return true;
  23. }
  24. /**
  25. * 节流阀
  26. * @return bool
  27. */
  28. public function throttle(): bool
  29. {
  30. return true;
  31. }
  32. /**
  33. * 通知渠道
  34. * @return array
  35. */
  36. public function via(): array
  37. {
  38. return [
  39. $this->toTemplate(),
  40. $this->toMiniTemplate(),
  41. ];
  42. }
  43. protected function getPagePath()
  44. {
  45. return "pages/my-friend-card-editor/my-friend-card-editor";
  46. }
  47. /**
  48. * 模版消息
  49. * @return TemplateChannel
  50. */
  51. public function toTemplate()
  52. {
  53. $number = rand(101, 249);
  54. $name = $this->user->sex == 2 ? "小哥哥" : "小姐姐";
  55. $templates = [
  56. [
  57. 'template_id' => 'JVICUmaP38MoputCdKVn5AAIFmc7ZO9eewj2FyW58NM',
  58. 'data' => [
  59. 'first' => [
  60. 'value' => "昨日有{$number}个{$name},访问了你的个人主页",
  61. ],
  62. 'keyword1' => [
  63. 'value' => '暂时未收到心动,建议你更换照片哦~',
  64. ],
  65. 'keyword2' => [
  66. 'value' => "一张精致清晰的照片能够迅速吸引异性的注意力!",
  67. ],
  68. 'remark' => [
  69. 'value' => "点此更换个人照片,有助于你收到更多心动,快速脱单~",
  70. ],
  71. ]
  72. ],
  73. [
  74. 'template_id' => 'vj03Lys62tcWH0BAx2bKdDbzxBnhwe4Fhs3GXqbxkTg',
  75. 'data' => [
  76. 'first' => [
  77. 'value' => "昨日有{$number}个{$name},访问了你的个人主页",
  78. ],
  79. 'keyword1' => [
  80. 'value' => "暂时未收到心动,建议你更换照片哦~",
  81. ],
  82. 'keyword2' => [
  83. 'value' => "一张精致清晰的照片能够迅速吸引异性的注意力!",
  84. ],
  85. 'remark' => [
  86. 'value' => "点此更换个人照片,有助于你收到更多心动,快速脱单~",
  87. ],
  88. ]
  89. ],
  90. [
  91. 'template_id' => 'hHzk7eaLtmNBdhsZwfgQur83_xAWvMs1t1_5fLaNwbc',
  92. 'data' => [
  93. 'first' => [
  94. 'value' => "昨日有{$number}个{$name},访问了你的个人主页",
  95. ],
  96. 'keyword1' => [
  97. 'value' => "暂时未收到心动,建议你更换照片哦~",
  98. ],
  99. 'keyword2' => [
  100. 'value' => "一张精致清晰的照片能够迅速吸引异性的注意力!",
  101. ],
  102. 'keyword3' => [
  103. 'value' => "昨日",
  104. ],
  105. 'remark' => [
  106. 'value' => "点此更换个人照片,有助于你收到更多心动,快速脱单~",
  107. ],
  108. ]
  109. ],
  110. ];
  111. $rand = rand(0, count($templates) - 1);
  112. $templateId = $templates[$rand]['template_id'];
  113. $data = $templates[$rand]['data'];
  114. return new TemplateChannel($this->to_uid, $templateId, $data);
  115. }
  116. /**
  117. * 小程序模版消息
  118. * @return MiniTemplateChannel
  119. */
  120. public function toMiniTemplate()
  121. {
  122. $number = rand(1000, 10000);
  123. $name = $this->user->sex == 2 ? "小哥哥" : "小姐姐";
  124. $templates = [
  125. [
  126. 'template_id' => 'ClWa4GHeJSh0_u8jsi6zWzvskIU7LvMbig8bkhHoehw',
  127. 'data' => [
  128. 'keyword1' => [
  129. 'value' => "昨日有{$number}个{$name},访问了你的个人主页"
  130. ],
  131. 'keyword2' => [
  132. 'value' => "暂时未收到心动,建议你更换照片哦~"
  133. ],
  134. 'keyword3' => [
  135. 'value' => "一张精致清晰的照片能够迅速吸引异性的注意力!\n点此更换个人照片,有助于你收到更多心动,快速脱单~",
  136. ],
  137. ]
  138. ],
  139. [
  140. 'template_id' => 'Xcp8AnnJr-cJmDMcr9WyIQmKgpN4qu6q6lStS0ZAiqs',
  141. 'data' => [
  142. 'keyword1' => [
  143. 'value' => "昨日有{$number}个{$name},访问了你的个人主页"
  144. ],
  145. 'keyword2' => [
  146. 'value' => "暂时未收到心动,建议你更换照片哦~"
  147. ],
  148. 'keyword3' => [
  149. 'value' => "一张精致清晰的照片能够迅速吸引异性的注意力!\n点此更换个人照片,有助于你收到更多心动,快速脱单~",
  150. ],
  151. ]
  152. ],
  153. [
  154. 'template_id' => 'dyXPTYwXRTywADyfFcxuUVckNeIldrieTbZtFfc9oHI',
  155. 'data' => [
  156. 'keyword1' => [
  157. 'value' => "昨日有{$number}个{$name},访问了你的个人主页"
  158. ],
  159. 'keyword2' => [
  160. 'value' => $this->user->nickname,
  161. ],
  162. 'keyword3' => [
  163. 'value' => "暂时未收到心动,建议你更换照片哦~"
  164. ],
  165. 'keyword4' => [
  166. 'value' => "一张精致清晰的照片能够迅速吸引异性的注意力!\n点此更换个人照片,有助于你收到更多心动,快速脱单~",
  167. ],
  168. ]
  169. ],
  170. ];
  171. $rand = rand(0, count($templates) - 1);
  172. $templateId = $templates[$rand]['template_id'];
  173. $data = $templates[$rand]['data'];
  174. return new MiniTemplateChannel($this->to_uid, $templateId, $data);
  175. }
  176. }