封装发送消息
This commit is contained in:
parent
d8ba69f9b6
commit
16a0225cc6
@ -178,12 +178,9 @@ class AssignDoctorConsumer extends ConsumerMessage
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 专家-公益
|
// 分配医生成功,发送消息
|
||||||
$ImService = new ImService();
|
$ImService = new ImService();
|
||||||
|
|
||||||
// 检测并创建患者账号
|
|
||||||
$ImService->createAccount($order_inquiry['user_id']);
|
|
||||||
|
|
||||||
// 获取订单医生数据
|
// 获取订单医生数据
|
||||||
$params = array();
|
$params = array();
|
||||||
$params['doctor_id'] = $doctor_id;
|
$params['doctor_id'] = $doctor_id;
|
||||||
@ -193,34 +190,8 @@ class AssignDoctorConsumer extends ConsumerMessage
|
|||||||
return Result::ACK;
|
return Result::ACK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检测并创建医生账号
|
// 发送消息
|
||||||
$ImService->createAccount($doctor_id);
|
$ImService->sendTextMessage($user_doctor['user_id'],$order_inquiry['user_id'],"等待医生接诊",$order_inquiry['order_inquiry_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);
|
|
||||||
|
|
||||||
}catch (\Exception $e) {
|
}catch (\Exception $e) {
|
||||||
// 验证失败
|
// 验证失败
|
||||||
|
|||||||
@ -133,12 +133,9 @@ class CallBackController extends AbstractController
|
|||||||
return $server->serve();
|
return $server->serve();
|
||||||
}
|
}
|
||||||
}elseif ($order_inquiry['inquiry_type'] == 1 || $order_inquiry['inquiry_type'] == 3){
|
}elseif ($order_inquiry['inquiry_type'] == 1 || $order_inquiry['inquiry_type'] == 3){
|
||||||
// 专家-公益
|
// 专家-公益,发送im消息
|
||||||
$ImService = new ImService();
|
$ImService = new ImService();
|
||||||
|
|
||||||
// 检测并创建患者账号
|
|
||||||
$ImService->createAccount($order_inquiry['user_id']);
|
|
||||||
|
|
||||||
// 获取订单医生数据
|
// 获取订单医生数据
|
||||||
$params = array();
|
$params = array();
|
||||||
$params['doctor_id'] = $order_inquiry['doctor_id'];
|
$params['doctor_id'] = $order_inquiry['doctor_id'];
|
||||||
@ -148,34 +145,8 @@ class CallBackController extends AbstractController
|
|||||||
return $server->serve();
|
return $server->serve();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检测并创建医生账号
|
// 发送消息
|
||||||
$ImService->createAccount($user_doctor['user_id']);
|
$ImService->sendTextMessage($user_doctor['user_id'],$order_inquiry['user_id'],"等待医生接诊",$order_inquiry['order_inquiry_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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch (\Exception $e) {
|
}catch (\Exception $e) {
|
||||||
@ -241,8 +212,6 @@ class CallBackController extends AbstractController
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* im回调
|
* im回调
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
|
|||||||
@ -11,6 +11,7 @@ use App\Model\UserPatient;
|
|||||||
use App\Model\UserPharmacist;
|
use App\Model\UserPharmacist;
|
||||||
use App\Utils\Log;
|
use App\Utils\Log;
|
||||||
use Extend\TencentIm\Account;
|
use Extend\TencentIm\Account;
|
||||||
|
use Extend\TencentIm\Message;
|
||||||
use Extend\TencentIm\Profile;
|
use Extend\TencentIm\Profile;
|
||||||
use GuzzleHttp\Exception\GuzzleException;
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
use Hyperf\Redis\Redis;
|
use Hyperf\Redis\Redis;
|
||||||
@ -72,9 +73,8 @@ class ImService extends BaseService
|
|||||||
|
|
||||||
$account = new Account();
|
$account = new Account();
|
||||||
// 查询账号导入状态
|
// 查询账号导入状态
|
||||||
$res = $account->checkAccountStatus($user_patient['user_id']);
|
$res = $account->checkAccountStatus($user['user_id']);
|
||||||
if (!$res){
|
if (!$res){
|
||||||
|
|
||||||
// 创建单个账号
|
// 创建单个账号
|
||||||
$account->createAccount($user_id,$user_name,$avatar);
|
$account->createAccount($user_id,$user_name,$avatar);
|
||||||
}
|
}
|
||||||
@ -83,7 +83,7 @@ class ImService extends BaseService
|
|||||||
if ($user['user_type'] == 2){
|
if ($user['user_type'] == 2){
|
||||||
// 检测用户资料
|
// 检测用户资料
|
||||||
$profile = new Profile();
|
$profile = new Profile();
|
||||||
$result = $profile->getOneAccountPortraitList("123456");
|
$result = $profile->getOneAccountPortraitList($user['user_id']);
|
||||||
if (!empty($result)){
|
if (!empty($result)){
|
||||||
// 获取订单医生医院
|
// 获取订单医生医院
|
||||||
$params = array();
|
$params = array();
|
||||||
@ -164,4 +164,52 @@ class ImService extends BaseService
|
|||||||
|
|
||||||
$redis->hSet($redis_key,$hash_key,json_encode($content,JSON_UNESCAPED_UNICODE));
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user