新增im消息回调修改
This commit is contained in:
@@ -738,107 +738,26 @@ class CallBackController extends AbstractController
|
||||
return $this->ImErrorReturn("回调签名不匹配");
|
||||
}
|
||||
|
||||
// 验证消息内容
|
||||
if (empty($request_params['MsgBody'])) {
|
||||
return $this->ImErrorReturn("消息内容错误,缺少MsgBody");
|
||||
if (empty($request_params['CallbackCommand'])){
|
||||
return $this->ImErrorReturn("回调事件为空");
|
||||
}
|
||||
|
||||
// 验证消息内容类型
|
||||
if (empty($request_params['MsgBody'][0]['MsgType'])) {
|
||||
return $this->ImErrorReturn("消息内容错误,缺少MsgType");
|
||||
}
|
||||
$userService = new UserService();
|
||||
|
||||
// 验证消息内容详情
|
||||
if (empty($request_params['MsgBody'][0]['MsgContent'])) {
|
||||
return $this->ImErrorReturn("消息内容错误,缺少MsgContent");
|
||||
}
|
||||
|
||||
// 验证接收方user_id
|
||||
if (empty($request_params['To_Account'])) {
|
||||
return $this->ImErrorReturn("消息内容错误,接收用户错误");
|
||||
}
|
||||
|
||||
// 验证消息唯一id
|
||||
if (empty($request_params['MsgKey'])) {
|
||||
return $this->ImErrorReturn("消息内容错误,消息唯一标识错误");
|
||||
}
|
||||
|
||||
// 验证消息重复性
|
||||
$params = array();
|
||||
$params['message_key'] = $request_params['MsgKey'];
|
||||
$message = MessageIm::getExists($params);
|
||||
if ($message) {
|
||||
// 消息重复
|
||||
Log::getInstance("CallBackController-imCallBack")->info("消息重复");
|
||||
return $this->ImSuccessReturn();
|
||||
}
|
||||
|
||||
// 处理发送结果
|
||||
if ($request_params['SendMsgResult'] == 0) {
|
||||
// im中0表示成功
|
||||
$message_send_result = 1;
|
||||
}
|
||||
|
||||
// 验证自定义消息内容
|
||||
$is_system = 0;// 是否系统操作发送(0:否 1:是)
|
||||
if (!empty($request_params['CloudCustomData'])) {
|
||||
$cloud_custom_data = json_decode($request_params['CloudCustomData'], true);
|
||||
|
||||
if (!empty($cloud_custom_data['order_inquiry_id'])) {
|
||||
// 获取订单数据
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $cloud_custom_data['order_inquiry_id'];
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)) {
|
||||
return $this->ImErrorReturn("消息内容错误,非法订单");
|
||||
}
|
||||
|
||||
$order_inquiry_id = $cloud_custom_data['order_inquiry_id'];
|
||||
if ($request_params['CallbackCommand'] == "State.StateChange"){
|
||||
// 用户状态变更
|
||||
$result = $userService->userImLoginStatus($request_params);
|
||||
if ($result['code'] == 0){
|
||||
return $this->ImErrorReturn($result['message']);
|
||||
}
|
||||
|
||||
if (!empty($cloud_custom_data['is_system'])) {
|
||||
if ($cloud_custom_data['is_system'] == 1) {
|
||||
// 系统发送
|
||||
$is_system = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 入库
|
||||
$data = array();
|
||||
if (!empty($request_params['From_Account'])) {
|
||||
// 系统发送时不带参数
|
||||
$data['from_user_id'] = $request_params['From_Account'];
|
||||
}
|
||||
$data['to_user_id'] = $request_params['To_Account'];
|
||||
$data['message_key'] = $request_params['MsgKey'];
|
||||
$data['message_send_time'] = $request_params['RequestTime'];
|
||||
$data['message_seq'] = $request_params['MsgSeq'];
|
||||
$data['message_send_result'] = $message_send_result ?? 0;
|
||||
$data['send_error_info'] = $request_params['ErrorInfo'];
|
||||
$data['message_type'] = $request_params['MsgBody'][0]['MsgType'];
|
||||
|
||||
$data['is_system'] = $is_system;
|
||||
if (!empty($order_inquiry_id)) {
|
||||
$data['order_inquiry_id'] = $order_inquiry_id;
|
||||
}
|
||||
|
||||
$message_content = $request_params['MsgBody'][0]['MsgContent'];
|
||||
$data['message_content'] = json_encode($message_content, JSON_UNESCAPED_UNICODE);
|
||||
$data['message_custom_content'] = $request_params['CloudCustomData'] ?? "";
|
||||
$message = MessageIm::addMessage($data);
|
||||
if (empty($message)) {
|
||||
return $this->ImErrorReturn("存储数据库失败");
|
||||
}
|
||||
|
||||
// im消息通知
|
||||
if ($is_system == 0 && isset($message_send_result) && isset($order_inquiry_id)){
|
||||
try {
|
||||
$UserService = new UserService();
|
||||
$UserService->userImMessageNotice($request_params['To_Account'],$order_inquiry_id,$request_params['MsgBody']);
|
||||
}catch (\Throwable $e){
|
||||
Log::getInstance("CallBackController-imCallBack")->error("im消息通知失败");
|
||||
}elseif ($request_params['CallbackCommand'] == "C2C.CallbackAfterSendMsg"){
|
||||
// 用户im消息发送后回调
|
||||
$result = $userService->userImAfterSendMsg($request_params);
|
||||
if ($result['code'] == 0){
|
||||
return $this->ImErrorReturn($result['message']);
|
||||
}
|
||||
}else{
|
||||
return $this->ImErrorReturn("非法事件");
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// 验证失败
|
||||
|
||||
Reference in New Issue
Block a user