WechatTemplateMessageService.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. namespace App\Services\Dwbs;
  3. use App\Repositories\Models\Base\User;
  4. use EasyWeChat\Factory;
  5. class WechatTemplateMessageService
  6. {
  7. /**
  8. * 发送获得学分消息
  9. * @param $user_id
  10. * @param $xuefen_id
  11. * @return false|void
  12. */
  13. public static function sendAddXuefen($user_id, $xuefen_id)
  14. {
  15. $tid = "YfPsq4t24pcikSoCS18bRrg6u1TBfl7L7s_6eetPNXo";
  16. $url = config('site.h5_base_url') . "/#/pages/ph/index?xuefen_record_id={$xuefen_id}";
  17. $data = [];
  18. $user = User::byIdGetWechatInfo($user_id);
  19. if (!$user) return false;
  20. self::send($tid, $user['credential'], $url, $data);
  21. }
  22. /**
  23. * 学分超过昨天
  24. * @param $user_id
  25. * @param $xuefen_id
  26. * @return false|void
  27. */
  28. public static function sendXuefenToYesday($user_id, $xuefen_id)
  29. {
  30. $tid = "YfPsq4t24pcikSoCS18bRrg6u1TBfl7L7s_6eetPNXo";
  31. $url = config('site.h5_base_url') . "/#/pages/ph/index?xuefen_record_id={$xuefen_id}";
  32. $data = [];
  33. $user = User::byIdGetWechatInfo($user_id);
  34. if (!$user) return false;
  35. self::send($tid, $user['credential'], $url, $data);
  36. }
  37. /**
  38. * 获得学位
  39. * @param $user_id
  40. * @param $xuefen_id
  41. * @return false|void
  42. */
  43. public static function sendAddZhengshu($user_id, $xuefen_id)
  44. {
  45. $tid = "YfPsq4t24pcikSoCS18bRrg6u1TBfl7L7s_6eetPNXo";
  46. $url = config('site.h5_base_url') . "/#/pages/ph/index?xuefen_record_id={$xuefen_id}";
  47. $data = [];
  48. $user = User::byIdGetWechatInfo($user_id);
  49. if (!$user) return false;
  50. self::send($tid, $user['credential'], $url, $data);
  51. }
  52. /**
  53. * 获得区间学霸
  54. * @param $user_id
  55. * @param $xuefen_id
  56. * @return false|void
  57. */
  58. public static function sendAddXueba($user_id, $xuefen_id)
  59. {
  60. $tid = "YfPsq4t24pcikSoCS18bRrg6u1TBfl7L7s_6eetPNXo";
  61. $url = config('site.h5_base_url') . "/#/pages/ph/index?xuefen_record_id={$xuefen_id}";
  62. $data = [];
  63. $user = User::byIdGetWechatInfo($user_id);
  64. if (!$user) return false;
  65. self::send($tid, $user['credential'], $url, $data);
  66. }
  67. /**
  68. * 商学院提醒
  69. * @param $user_id
  70. * @param $xuefen_id
  71. * @return false|void
  72. */
  73. public static function sendSchool($user_id, $xuefen_id)
  74. {
  75. $tid = "YfPsq4t24pcikSoCS18bRrg6u1TBfl7L7s_6eetPNXo";
  76. $url = config('site.h5_base_url') . "/#/pages/ph/index?xuefen_record_id={$xuefen_id}";
  77. $data = [];
  78. $user = User::byIdGetWechatInfo($user_id);
  79. if (!$user) return false;
  80. self::send($tid, $user['credential'], $url, $data);
  81. }
  82. /**
  83. * 兑换提醒
  84. * @param $user_id
  85. * @param $xuefen_id
  86. * @return false|void
  87. */
  88. public static function sendShopOrder($user_id, $xuefen_id)
  89. {
  90. $tid = "YfPsq4t24pcikSoCS18bRrg6u1TBfl7L7s_6eetPNXo";
  91. $url = config('site.h5_base_url') . "/#/pages/ph/index?xuefen_record_id={$xuefen_id}";
  92. $data = [];
  93. $user = User::byIdGetWechatInfo($user_id);
  94. if (!$user) return false;
  95. self::send($tid, $user['credential'], $url, $data);
  96. }
  97. /**
  98. * 发货提醒
  99. * @param $user_id
  100. * @param $xuefen_id
  101. * @return false|void
  102. */
  103. public static function sendShopOrderFahuo($user_id, $xuefen_id)
  104. {
  105. $tid = "YfPsq4t24pcikSoCS18bRrg6u1TBfl7L7s_6eetPNXo";
  106. $url = config('site.h5_base_url') . "/#/pages/ph/index?xuefen_record_id={$xuefen_id}";
  107. $data = [];
  108. $user = User::byIdGetWechatInfo($user_id);
  109. if (!$user) return false;
  110. self::send($tid, $user['credential'], $url, $data);
  111. }
  112. /**
  113. * 发货提醒
  114. * @param $user_id
  115. * @param $xuefen_id
  116. * @return false|void
  117. */
  118. public static function sendShopOrderClose($user_id, $xuefen_id)
  119. {
  120. $tid = "YfPsq4t24pcikSoCS18bRrg6u1TBfl7L7s_6eetPNXo";
  121. $url = config('site.h5_base_url') . "/#/pages/ph/index?xuefen_record_id={$xuefen_id}";
  122. $data = [];
  123. $user = User::byIdGetWechatInfo($user_id);
  124. if (!$user) return false;
  125. self::send($tid, $user['credential'], $url, $data);
  126. }
  127. private static function send($tid, $open_id, $url, $data)
  128. {
  129. try {
  130. $app = Factory::officialAccount(config('wechat.official_account.default'));
  131. $app->template_message->send([
  132. 'touser' => $open_id,
  133. 'template_id' => $tid,
  134. 'url' => $url,
  135. 'data' => $data,
  136. ]);
  137. } catch (\Exception $exception) {
  138. log_record('发送模板消息错误', $exception);
  139. }
  140. }
  141. }