123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <?php
- namespace App\Services\Dwbs;
- use App\Repositories\Models\Base\User;
- use EasyWeChat\Factory;
- class WechatTemplateMessageService
- {
- /**
- * 发送获得学分消息
- * @param $user_id
- * @param $xuefen_id
- * @return false|void
- */
- public static function sendAddXuefen($user_id, $xuefen_id)
- {
- $tid = "YfPsq4t24pcikSoCS18bRrg6u1TBfl7L7s_6eetPNXo";
- $url = config('site.h5_base_url') . "/#/pages/ph/index?xuefen_record_id={$xuefen_id}";
- $data = [];
- $user = User::byIdGetWechatInfo($user_id);
- if (!$user) return false;
- self::send($tid, $user['credential'], $url, $data);
- }
- /**
- * 学分超过昨天
- * @param $user_id
- * @param $xuefen_id
- * @return false|void
- */
- public static function sendXuefenToYesday($user_id, $xuefen_id)
- {
- $tid = "YfPsq4t24pcikSoCS18bRrg6u1TBfl7L7s_6eetPNXo";
- $url = config('site.h5_base_url') . "/#/pages/ph/index?xuefen_record_id={$xuefen_id}";
- $data = [];
- $user = User::byIdGetWechatInfo($user_id);
- if (!$user) return false;
- self::send($tid, $user['credential'], $url, $data);
- }
- /**
- * 获得学位
- * @param $user_id
- * @param $xuefen_id
- * @return false|void
- */
- public static function sendAddZhengshu($user_id, $xuefen_id)
- {
- $tid = "YfPsq4t24pcikSoCS18bRrg6u1TBfl7L7s_6eetPNXo";
- $url = config('site.h5_base_url') . "/#/pages/ph/index?xuefen_record_id={$xuefen_id}";
- $data = [];
- $user = User::byIdGetWechatInfo($user_id);
- if (!$user) return false;
- self::send($tid, $user['credential'], $url, $data);
- }
- /**
- * 获得区间学霸
- * @param $user_id
- * @param $xuefen_id
- * @return false|void
- */
- public static function sendAddXueba($user_id, $xuefen_id)
- {
- $tid = "YfPsq4t24pcikSoCS18bRrg6u1TBfl7L7s_6eetPNXo";
- $url = config('site.h5_base_url') . "/#/pages/ph/index?xuefen_record_id={$xuefen_id}";
- $data = [];
- $user = User::byIdGetWechatInfo($user_id);
- if (!$user) return false;
- self::send($tid, $user['credential'], $url, $data);
- }
- /**
- * 商学院提醒
- * @param $user_id
- * @param $xuefen_id
- * @return false|void
- */
- public static function sendSchool($user_id, $xuefen_id)
- {
- $tid = "YfPsq4t24pcikSoCS18bRrg6u1TBfl7L7s_6eetPNXo";
- $url = config('site.h5_base_url') . "/#/pages/ph/index?xuefen_record_id={$xuefen_id}";
- $data = [];
- $user = User::byIdGetWechatInfo($user_id);
- if (!$user) return false;
- self::send($tid, $user['credential'], $url, $data);
- }
- /**
- * 兑换提醒
- * @param $user_id
- * @param $xuefen_id
- * @return false|void
- */
- public static function sendShopOrder($user_id, $xuefen_id)
- {
- $tid = "YfPsq4t24pcikSoCS18bRrg6u1TBfl7L7s_6eetPNXo";
- $url = config('site.h5_base_url') . "/#/pages/ph/index?xuefen_record_id={$xuefen_id}";
- $data = [];
- $user = User::byIdGetWechatInfo($user_id);
- if (!$user) return false;
- self::send($tid, $user['credential'], $url, $data);
- }
- /**
- * 发货提醒
- * @param $user_id
- * @param $xuefen_id
- * @return false|void
- */
- public static function sendShopOrderFahuo($user_id, $xuefen_id)
- {
- $tid = "YfPsq4t24pcikSoCS18bRrg6u1TBfl7L7s_6eetPNXo";
- $url = config('site.h5_base_url') . "/#/pages/ph/index?xuefen_record_id={$xuefen_id}";
- $data = [];
- $user = User::byIdGetWechatInfo($user_id);
- if (!$user) return false;
- self::send($tid, $user['credential'], $url, $data);
- }
- /**
- * 发货提醒
- * @param $user_id
- * @param $xuefen_id
- * @return false|void
- */
- public static function sendShopOrderClose($user_id, $xuefen_id)
- {
- $tid = "YfPsq4t24pcikSoCS18bRrg6u1TBfl7L7s_6eetPNXo";
- $url = config('site.h5_base_url') . "/#/pages/ph/index?xuefen_record_id={$xuefen_id}";
- $data = [];
- $user = User::byIdGetWechatInfo($user_id);
- if (!$user) return false;
- self::send($tid, $user['credential'], $url, $data);
- }
- private static function send($tid, $open_id, $url, $data)
- {
- try {
- $app = Factory::officialAccount(config('wechat.official_account.default'));
- $app->template_message->send([
- 'touser' => $open_id,
- 'template_id' => $tid,
- 'url' => $url,
- 'data' => $data,
- ]);
- } catch (\Exception $exception) {
- log_record('发送模板消息错误', $exception);
- }
- }
- }
|