CompleteInfoRemind.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 CompleteInfoRemind
  10. * @package App\Notifications
  11. */
  12. class CompleteInfoRemind extends Notification
  13. {
  14. protected $title = "提醒用户补全信息";
  15. /** @var array 绑定数据 */
  16. protected $buildData = array(
  17. 'remind_nickname' => "提醒者昵称",
  18. 'is_remind_nickname' => '被提醒者昵称'
  19. );
  20. /**
  21. * Create a new notification instance.
  22. *
  23. * @param $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/my-friend-card-editor/my-friend-card-editor";
  59. }
  60. /**
  61. *
  62. * @return TemplateChannel
  63. */
  64. public function toFpdxTemplate()
  65. {
  66. $templateIds = array(
  67. [
  68. 'template_id' => "MsktKh_eS5HMnjmCGznVYZFTAAm2JGHQfXmZgJNt4Qk",
  69. 'data' => [
  70. 'first' => [
  71. 'value' => "{$this->buildData['remind_nickname']}对你的资料很感兴趣,邀请你完善交友卡片~"
  72. ],
  73. 'keyword1' => [
  74. 'value' => "{$this->buildData['is_remind_nickname']}"
  75. ],
  76. 'keyword2' => [
  77. 'value' => "邀请你完善交友卡片"
  78. ],
  79. 'keyword3' => [
  80. 'value' => date('Y-m-d')
  81. ],
  82. 'remark' => [
  83. 'value' => "点此继续补全信息,可获得更高曝光度~",
  84. ]
  85. ]
  86. ],
  87. [
  88. 'template_id' => "aDsZW0gzbSTcEwxzqC44Cq-luC-8YHLp8CaPCrWAlBo",
  89. 'data' => [
  90. 'first' => [
  91. 'value' => "{$this->buildData['remind_nickname']}对你的资料很感兴趣,邀请你完善交友卡片~"
  92. ],
  93. 'keyword1' => [
  94. 'value' => "{$this->buildData['is_remind_nickname']}"
  95. ],
  96. 'keyword2' => [
  97. 'value' => "邀请你完善交友卡片"
  98. ],
  99. 'keyword3' => [
  100. 'value' => date('Y-m-d')
  101. ],
  102. 'remark' => [
  103. 'value' => "点此继续补全信息,可获得更高曝光度~",
  104. ]
  105. ]
  106. ]
  107. );
  108. $template = $templateIds[rand(0, count($templateIds) - 1)];
  109. $templateId = $template['template_id'];
  110. $data = $template['data'];
  111. $publicId = config("wechat.fpdx.public_id");
  112. return new TemplateChannel($this->to_uid, $templateId, $data, $publicId);
  113. }
  114. /**
  115. * @return TemplateChannel
  116. */
  117. public function toSyjTemplate()
  118. {
  119. $templateIds = array(
  120. [
  121. 'template_id' => "RJNTbLGdlK7tLRgt5uoKIEWxlB7-bwCdwgE5yR11aHk",
  122. 'data' => [
  123. 'first' => [
  124. 'value' => "{$this->buildData['remind_nickname']}对你的资料很感兴趣,邀请你完善交友卡片~"
  125. ],
  126. 'keyword1' => [
  127. 'value' => "{$this->buildData['is_remind_nickname']}"
  128. ],
  129. 'keyword2' => [
  130. 'value' => "邀请你完善交友卡片"
  131. ],
  132. 'keyword3' => [
  133. 'value' => date('Y-m-d')
  134. ],
  135. 'remark' => [
  136. 'value' => "点此继续补全信息,可获得更高曝光度~",
  137. ]
  138. ]
  139. ],
  140. [
  141. 'template_id' => "buiSCGP-jKweNEVi7V8ZK-8Lspem1FopbD5Kvupg1Ig",
  142. 'data' => [
  143. 'first' => [
  144. 'value' => "{$this->buildData['remind_nickname']}对你的资料很感兴趣,邀请你完善交友卡片~"
  145. ],
  146. 'keyword1' => [
  147. 'value' => "{$this->buildData['is_remind_nickname']}"
  148. ],
  149. 'keyword2' => [
  150. 'value' => "邀请你完善交友卡片"
  151. ],
  152. 'keyword3' => [
  153. 'value' => date('Y-m-d')
  154. ],
  155. 'remark' => [
  156. 'value' => "点此继续补全信息,可获得更高曝光度~",
  157. ]
  158. ]
  159. ]
  160. );
  161. $template = $templateIds[rand(0, count($templateIds) - 1)];
  162. $templateId = $template['template_id'];
  163. $data = $template['data'];
  164. $publicId = config("wechat.fpdx.public_id");
  165. return new TemplateChannel($this->to_uid, $templateId, $data, $publicId);
  166. }
  167. /**
  168. * @return MiniTemplateChannel
  169. */
  170. public function toMiniTemplate()
  171. {
  172. $templateId = "hc6Av4hGLXLzcVgc4JkDNmrYJ18rztBPU_NCfYUNy7U";
  173. $data = array(
  174. 'keyword1' => [
  175. 'value' => "{$this->buildData['remind_nickname']}对你的资料很感兴趣,邀请你完善交友卡片~"
  176. ],
  177. 'keyword2' => [
  178. 'value' => "点此继续补全信息,可获得更高曝光度~"
  179. ],
  180. 'keyword3' => [
  181. 'value' => "{$this->buildData['is_remind_nickname']}"
  182. ],
  183. );
  184. return new MiniTemplateChannel($this->to_uid, $templateId, $data);
  185. }
  186. /**
  187. * @return QQMiniTemplateChannel
  188. */
  189. public function toQQMiniTemplate()
  190. {
  191. $templateId = "481d4c5aaeb77b6b0cc3b962edd0e54d";
  192. $data = array(
  193. 'keyword1' => [
  194. 'value' => "{$this->buildData['remind_nickname']}对你的资料很感兴趣,邀请你完善交友卡片~"
  195. ],
  196. 'keyword2' => [
  197. 'value' => "邀请你完善交友卡片"
  198. ],
  199. 'keyword3' => [
  200. 'value' => "点此继续补全信息,可获得更高曝光度~"
  201. ],
  202. );
  203. return (new QQMiniTemplateChannel())
  204. ->setAppId('1109365561')
  205. ->setTitle($this->title)
  206. ->setPage($this->getPagePath())
  207. ->toUser($this->to_uid)
  208. ->setTemplateId($templateId)
  209. ->setParameters($data)
  210. ->send();
  211. }
  212. }