CompletedInfo.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. namespace App\Notifications;
  3. use App\Services\NoticeService\Channels\MiniTemplateChannel;
  4. use App\Services\NoticeService\Channels\QQMiniTemplateChannel;
  5. use App\Services\NoticeService\Channels\TemplateChannel;
  6. use App\Services\NoticeService\Notification;
  7. /**
  8. * 补全信息完成
  9. * Class CompletedInfo
  10. * @package App\Notifications
  11. */
  12. class CompletedInfo extends Notification
  13. {
  14. protected $title = "提醒用户补全信息回应";
  15. /** @var array 绑定数据 */
  16. protected $buildData = array(
  17. 'is_remind_nickname' => '被提醒者昵称',
  18. 'is_remind_user_partner_id' => null
  19. );
  20. /**
  21. * Create a new notification instance.
  22. *
  23. * @param int $to_uid
  24. */
  25. public function __construct(int $to_uid)
  26. {
  27. parent::__construct($to_uid);
  28. }
  29. /**
  30. * Get the notification's delivery channels.
  31. *
  32. * @return array
  33. */
  34. public function via(): array
  35. {
  36. return [
  37. $this->toFpdxTemplate(),
  38. $this->toSyjTemplate(),
  39. $this->toMiniTemplate(),
  40. // $this->toQQMiniTemplate()
  41. ];
  42. }
  43. /**
  44. * @param array $build
  45. * @return $this
  46. */
  47. public function buildData(array $build)
  48. {
  49. $this->buildData = $build;
  50. return $this;
  51. }
  52. /**
  53. * 跳转地址
  54. * @return string
  55. */
  56. protected function getPagePath()
  57. {
  58. return "pages/other-friend-card/other-friend-card?partner_id={$this->buildData['is_remind_user_partner_id']}";
  59. }
  60. /**
  61. *
  62. * @return TemplateChannel
  63. */
  64. public function toFpdxTemplate()
  65. {
  66. $templateIds = array(
  67. [
  68. 'template_id' => "vj03Lys62tcWH0BAx2bKdDbzxBnhwe4Fhs3GXqbxkTg",
  69. 'data' => [
  70. 'first' => [
  71. 'value' => "你提醒的{$this->buildData['is_remind_nickname']},已完善交友卡片~"
  72. ],
  73. 'keyword1' => [
  74. 'value' => "提醒成功"
  75. ],
  76. 'keyword2' => [
  77. 'value' => date('Y-m-d H:i:s')
  78. ],
  79. 'remark' => [
  80. 'value' => "点此可查看{$this->buildData['is_remind_nickname']}详细资料",
  81. ]
  82. ]
  83. ]
  84. );
  85. $template = $templateIds[rand(0, count($templateIds) - 1)];
  86. $templateId = $template['template_id'];
  87. $data = $template['data'];
  88. $publicId = config("wechat.fpdx.public_id");
  89. return new TemplateChannel($this->to_uid, $templateId, $data, $publicId);
  90. }
  91. /**
  92. * @return TemplateChannel
  93. */
  94. public function toSyjTemplate()
  95. {
  96. $templateIds = array(
  97. [
  98. 'template_id' => "T5AvN3tkUKywz1-hVeW2RFLNYV1Ex_EfXI0OE_JQBxM",
  99. 'data' => [
  100. 'first' => [
  101. 'value' => "你提醒的{$this->buildData['is_remind_nickname']},已完善交友卡片~"
  102. ],
  103. 'keyword1' => [
  104. 'value' => date('Y-m-d H:i:s')
  105. ],
  106. 'keyword2' => [
  107. 'value' => "提醒成功"
  108. ],
  109. 'keyword3' => [
  110. 'value' => "点此可查看{$this->buildData['is_remind_nickname']}详细资料"
  111. ]
  112. ]
  113. ]
  114. );
  115. $template = $templateIds[rand(0, count($templateIds) - 1)];
  116. $templateId = $template['template_id'];
  117. $data = $template['data'];
  118. $publicId = config("wechat.fpdx.public_id");
  119. return new TemplateChannel($this->to_uid, $templateId, $data, $publicId);
  120. }
  121. /**
  122. * @return MiniTemplateChannel
  123. */
  124. public function toMiniTemplate()
  125. {
  126. $templateId = "THT3gLhSTLvs9Koli8wxdbKYq2_noErJKy7aov-YmMg";
  127. $data = array(
  128. 'keyword1' => [
  129. 'value' => "你提醒的{$this->buildData['is_remind_nickname']},已完善交友卡片~"
  130. ],
  131. 'keyword2' => [
  132. 'value' => date('Y-m-d H:i:s')
  133. ],
  134. 'keyword3' => [
  135. 'value' => "提醒成功"
  136. ],
  137. 'keyword4' => [
  138. 'value' => '更新成功'
  139. ],
  140. 'keyword5' => [
  141. 'value' => "点此可查看{$this->buildData['is_remind_nickname']}详细资料"
  142. ]
  143. );
  144. return new MiniTemplateChannel($this->to_uid, $templateId, $data);
  145. }
  146. /**
  147. * @return QQMiniTemplateChannel
  148. */
  149. public function toQQMiniTemplate()
  150. {
  151. $templateId = "3f90ecc0a1eed20431caee8212279ce3";
  152. $data = array(
  153. 'keyword1' => [
  154. 'value' => "你提醒的{$this->buildData['is_remind_nickname']},已完善交友卡片~"
  155. ],
  156. 'keyword2' => [
  157. 'value' => date('Y-m-d H:i:s')
  158. ],
  159. 'keyword3' => [
  160. 'value' => "提醒成功"
  161. ],
  162. 'keyword4' => [
  163. 'value' => '更新成功'
  164. ],
  165. 'keyword5' => [
  166. 'value' => "点此可查看{$this->buildData['is_remind_nickname']}详细资料"
  167. ]
  168. );
  169. return (new QQMiniTemplateChannel())->setTitle($this->title)
  170. ->toUser($this->to_uid)->setTemplateId($templateId)
  171. ->setPage($this->getPagePath())
  172. ->setParameters($data)->send();
  173. }
  174. }