From 16a0225cc64542bf9235dd2fd9266e3256cb576f Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Fri, 10 Mar 2023 17:17:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=81=E8=A3=85=E5=8F=91=E9=80=81=E6=B6=88?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Amqp/Consumer/AssignDoctorConsumer.php | 35 ++------------ app/Controller/CallBackController.php | 37 ++------------- app/Services/ImService.php | 54 ++++++++++++++++++++-- 3 files changed, 57 insertions(+), 69 deletions(-) diff --git a/app/Amqp/Consumer/AssignDoctorConsumer.php b/app/Amqp/Consumer/AssignDoctorConsumer.php index 1700630..abd8af0 100644 --- a/app/Amqp/Consumer/AssignDoctorConsumer.php +++ b/app/Amqp/Consumer/AssignDoctorConsumer.php @@ -178,12 +178,9 @@ class AssignDoctorConsumer extends ConsumerMessage } try { - // 专家-公益 + // 分配医生成功,发送消息 $ImService = new ImService(); - // 检测并创建患者账号 - $ImService->createAccount($order_inquiry['user_id']); - // 获取订单医生数据 $params = array(); $params['doctor_id'] = $doctor_id; @@ -193,34 +190,8 @@ class AssignDoctorConsumer extends ConsumerMessage return Result::ACK; } - // 检测并创建医生账号 - $ImService->createAccount($doctor_id); - - // 医生给患者发送消息 - $message = new Message(); - - $arg = array(); - $arg['From_Account'] = $user_doctor['user_id']; // 发送方user_id 如系统发送,无需填写 - $arg['To_Account'] = $order_inquiry['user_id']; // 接收方user_id - $arg['SendMsgControl'] = ['NoUnread']; - - $arg['MsgBody'] = [ - [ - "MsgType" => "TIMTextElem", - "MsgContent" => [ - "Text" => "等待医生接诊", - ], - ] - ]; - - // 自定义消息 - $cloud_custom_data = array(); - $cloud_custom_data['order_inquiry_id'] = $order_inquiry['order_inquiry_id']; - $cloud_custom_data['is_system'] = 1; - - $arg['CloudCustomData'] = json_encode($cloud_custom_data,JSON_UNESCAPED_UNICODE); - - $message->sendMessage($arg); + // 发送消息 + $ImService->sendTextMessage($user_doctor['user_id'],$order_inquiry['user_id'],"等待医生接诊",$order_inquiry['order_inquiry_id']); }catch (\Exception $e) { // 验证失败 diff --git a/app/Controller/CallBackController.php b/app/Controller/CallBackController.php index 64aac21..c4b1b03 100644 --- a/app/Controller/CallBackController.php +++ b/app/Controller/CallBackController.php @@ -133,12 +133,9 @@ class CallBackController extends AbstractController return $server->serve(); } }elseif ($order_inquiry['inquiry_type'] == 1 || $order_inquiry['inquiry_type'] == 3){ - // 专家-公益 + // 专家-公益,发送im消息 $ImService = new ImService(); - // 检测并创建患者账号 - $ImService->createAccount($order_inquiry['user_id']); - // 获取订单医生数据 $params = array(); $params['doctor_id'] = $order_inquiry['doctor_id']; @@ -148,34 +145,8 @@ class CallBackController extends AbstractController return $server->serve(); } - // 检测并创建医生账号 - $ImService->createAccount($user_doctor['user_id']); - - // 医生给患者发送消息 - $message = new Message(); - - $arg = array(); - $arg['From_Account'] = $user_doctor['user_id']; // 发送方user_id 如系统发送,无需填写 - $arg['To_Account'] = $order_inquiry['user_id']; // 接收方user_id - $arg['SendMsgControl'] = ['NoUnread']; - - $arg['MsgBody'] = [ - [ - "MsgType" => "TIMTextElem", - "MsgContent" => [ - "Text" => "等待医生接诊", - ], - ] - ]; - - // 自定义消息 - $cloud_custom_data = array(); - $cloud_custom_data['order_inquiry_id'] = $order_inquiry['order_inquiry_id']; - $cloud_custom_data['is_system'] = 1; - - $arg['CloudCustomData'] = json_encode($cloud_custom_data,JSON_UNESCAPED_UNICODE); - - $message->sendMessage($arg); + // 发送消息 + $ImService->sendTextMessage($user_doctor['user_id'],$order_inquiry['user_id'],"等待医生接诊",$order_inquiry['order_inquiry_id']); } } }catch (\Exception $e) { @@ -241,8 +212,6 @@ class CallBackController extends AbstractController ); } - // - /** * im回调 * @return ResponseInterface diff --git a/app/Services/ImService.php b/app/Services/ImService.php index 5ea167c..32d46a9 100644 --- a/app/Services/ImService.php +++ b/app/Services/ImService.php @@ -11,6 +11,7 @@ use App\Model\UserPatient; use App\Model\UserPharmacist; use App\Utils\Log; use Extend\TencentIm\Account; +use Extend\TencentIm\Message; use Extend\TencentIm\Profile; use GuzzleHttp\Exception\GuzzleException; use Hyperf\Redis\Redis; @@ -72,9 +73,8 @@ class ImService extends BaseService $account = new Account(); // 查询账号导入状态 - $res = $account->checkAccountStatus($user_patient['user_id']); + $res = $account->checkAccountStatus($user['user_id']); if (!$res){ - // 创建单个账号 $account->createAccount($user_id,$user_name,$avatar); } @@ -83,7 +83,7 @@ class ImService extends BaseService if ($user['user_type'] == 2){ // 检测用户资料 $profile = new Profile(); - $result = $profile->getOneAccountPortraitList("123456"); + $result = $profile->getOneAccountPortraitList($user['user_id']); if (!empty($result)){ // 获取订单医生医院 $params = array(); @@ -164,4 +164,52 @@ class ImService extends BaseService $redis->hSet($redis_key,$hash_key,json_encode($content,JSON_UNESCAPED_UNICODE)); } + + /** + * 发送文本消息 + * @param string $from_user_id 发送者id + * @param string $to_user_id 接受者id + * @param string $content 内容 + * @param string $order_inquiry_id 订单id + * @return void + * @throws GuzzleException + */ + public function sendTextMessage(string $from_user_id,string $to_user_id,string $content,string $order_inquiry_id): void + { + if (!empty($from_user_id)){ + // 检测并创建发送者账号 + $this->createAccount($from_user_id); + } + + // 检测并创建接收者账号 + $this->createAccount($to_user_id); + + // 医生给患者发送消息 + $message = new Message(); + + $arg = array(); + if (!empty($from_user_id)){ + $arg['From_Account'] = $from_user_id; // 发送方user_id 如系统发送,无需填写 + } + $arg['To_Account'] = $to_user_id; // 接收方user_id + $arg['SendMsgControl'] = ['NoUnread']; + + $arg['MsgBody'] = [ + [ + "MsgType" => "TIMTextElem", + "MsgContent" => [ + "Text" => $content, + ], + ] + ]; + + // 自定义消息 + $cloud_custom_data = array(); + $cloud_custom_data['order_inquiry_id'] = $order_inquiry_id; + $cloud_custom_data['is_system'] = 1; + + $arg['CloudCustomData'] = json_encode($cloud_custom_data,JSON_UNESCAPED_UNICODE); + + $message->sendMessage($arg); + } } \ No newline at end of file