新增im消息回调时推送订阅消息
This commit is contained in:
@@ -29,14 +29,17 @@ use App\Model\OrderProductRefund;
|
||||
use App\Model\PatientFamily;
|
||||
use App\Model\Product;
|
||||
use App\Model\ProductPlatformAmount;
|
||||
use App\Model\User;
|
||||
use App\Model\UserCoupon;
|
||||
use App\Model\UserDoctor;
|
||||
use App\Model\UserPatient;
|
||||
use App\Model\UserSystem;
|
||||
use App\Services\BaseService;
|
||||
use App\Services\ImService;
|
||||
use App\Services\InquiryService;
|
||||
use App\Services\MessagePush;
|
||||
use App\Services\OrderPrescriptionService;
|
||||
use App\Services\UserService;
|
||||
use App\Utils\Log;
|
||||
use Extend\Alibaba\Oss;
|
||||
use Extend\TencentIm\Account;
|
||||
@@ -634,10 +637,9 @@ class CallBackController extends AbstractController
|
||||
{
|
||||
$request_params = $this->request->all();
|
||||
try {
|
||||
Log::getInstance()->info("Im回调数据:" . json_encode($request_params, JSON_UNESCAPED_UNICODE));
|
||||
Log::getInstance("CallBackController-imCallBack")->info("Im回调数据:" . json_encode($request_params, JSON_UNESCAPED_UNICODE));
|
||||
|
||||
if (empty($request_params['RequestTime']) || empty($request_params['Sign'])) {
|
||||
Log::getInstance()->error("Im回调数据处理失败:缺少时间时间戳/签名字段");
|
||||
return $this->ImErrorReturn("缺少时间时间戳/签名字段");
|
||||
}
|
||||
|
||||
@@ -645,37 +647,31 @@ class CallBackController extends AbstractController
|
||||
$imService = new ImService();
|
||||
$result = $imService->validateSign($request_params['RequestTime'], $request_params['Sign']);
|
||||
if (!$result) {
|
||||
Log::getInstance()->error("Im回调数据处理失败:回调签名不匹配");
|
||||
return $this->ImErrorReturn("回调签名不匹配");
|
||||
}
|
||||
|
||||
// 验证消息内容
|
||||
if (empty($request_params['MsgBody'])) {
|
||||
Log::getInstance()->error("Im回调数据处理失败:消息内容错误");
|
||||
return $this->ImErrorReturn("消息内容错误,缺少MsgBody");
|
||||
}
|
||||
|
||||
// 验证消息内容类型
|
||||
if (empty($request_params['MsgBody'][0]['MsgType'])) {
|
||||
Log::getInstance()->error("Im回调数据处理失败:缺少MsgType");
|
||||
return $this->ImErrorReturn("消息内容错误,缺少MsgType");
|
||||
}
|
||||
|
||||
// 验证消息内容详情
|
||||
if (empty($request_params['MsgBody'][0]['MsgContent'])) {
|
||||
Log::getInstance()->error("Im回调数据处理失败:缺少MsgContent");
|
||||
return $this->ImErrorReturn("消息内容错误,缺少MsgContent");
|
||||
}
|
||||
|
||||
// 验证接收方user_id
|
||||
if (empty($request_params['To_Account'])) {
|
||||
Log::getInstance()->error("Im回调数据处理失败:接收用户错误");
|
||||
return $this->ImErrorReturn("消息内容错误,接收用户错误");
|
||||
}
|
||||
|
||||
// 验证消息唯一id
|
||||
if (empty($request_params['MsgKey'])) {
|
||||
Log::getInstance()->error("Im回调数据处理失败:消息唯一标识错误");
|
||||
return $this->ImErrorReturn("消息内容错误,消息唯一标识错误");
|
||||
}
|
||||
|
||||
@@ -685,7 +681,7 @@ class CallBackController extends AbstractController
|
||||
$message = MessageIm::getExists($params);
|
||||
if ($message) {
|
||||
// 消息重复
|
||||
Log::getInstance()->info("Im回调数据处理失败:消息重复");
|
||||
Log::getInstance("CallBackController-imCallBack")->info("消息重复");
|
||||
return $this->ImSuccessReturn();
|
||||
}
|
||||
|
||||
@@ -706,7 +702,6 @@ class CallBackController extends AbstractController
|
||||
$params['order_inquiry_id'] = $cloud_custom_data['order_inquiry_id'];
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)) {
|
||||
Log::getInstance()->error("Im回调数据处理失败:非法订单");
|
||||
return $this->ImErrorReturn("消息内容错误,非法订单");
|
||||
}
|
||||
|
||||
@@ -745,13 +740,21 @@ class CallBackController extends AbstractController
|
||||
$data['message_custom_content'] = $request_params['CloudCustomData'] ?? "";
|
||||
$message = MessageIm::addMessage($data);
|
||||
if (empty($message)) {
|
||||
Log::getInstance()->error("Im回调数据处理失败:存储数据库失败");
|
||||
return $this->wxPayErrorReturn("存储数据库失败");
|
||||
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消息通知失败");
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// 验证失败
|
||||
Log::getInstance()->error("Im回调数据处理失败:" . $e->getMessage());
|
||||
return $this->wxPayErrorReturn($e->getMessage());
|
||||
return $this->ImErrorReturn($e->getMessage());
|
||||
}
|
||||
|
||||
Log::getInstance()->info("Im回调数据处理成功");
|
||||
@@ -765,6 +768,7 @@ class CallBackController extends AbstractController
|
||||
*/
|
||||
protected function ImErrorReturn(string $message): ResponseInterface
|
||||
{
|
||||
Log::getInstance("CallBackController-imCallBack")->error("Im回调数据处理失败:接收用户错误");
|
||||
return $this->response
|
||||
->withStatus(200)
|
||||
->withBody(
|
||||
@@ -1334,254 +1338,6 @@ class CallBackController extends AbstractController
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 检测所结果回调
|
||||
// * @return ResponseInterface
|
||||
// */
|
||||
// public function DetectionResultCallBack1(): ResponseInterface
|
||||
// {
|
||||
// $request_params = $this->request->all();
|
||||
// $auth = $this->request->header("Authorization");
|
||||
// if (empty($auth)){
|
||||
// return $this->detectionResultFailReturn("非法请求");
|
||||
// }
|
||||
//
|
||||
// Log::getInstance("CallBackController-DetectionResultCallBack")->info("处理检测所结果");
|
||||
//
|
||||
// try {
|
||||
// // 检测参数
|
||||
// if (!isset($request_params['appId'])){
|
||||
// return $this->detectionResultFailReturn("缺少appId参数");
|
||||
// }
|
||||
//
|
||||
// if (!isset($request_params['orderCode'])){
|
||||
// return $this->detectionResultFailReturn("缺少orderCode参数");
|
||||
// }
|
||||
//
|
||||
// if (!isset($request_params['detectBarcode'])){
|
||||
// return $this->detectionResultFailReturn("缺少detectBarcode参数");
|
||||
// }
|
||||
//
|
||||
// if (!isset($request_params['pdfReport'])){
|
||||
// return $this->detectionResultFailReturn("缺少pdfReport参数");
|
||||
// }
|
||||
//
|
||||
// // 检测签名
|
||||
// $params = array();
|
||||
// $params['app_id'] = $request_params['appId'];
|
||||
// $basic_detection_organ = BasicDetectionOrgan::getOne($params);
|
||||
// if (empty($basic_detection_organ)){
|
||||
// return $this->detectionResultFailReturn("非法appId");
|
||||
// }
|
||||
//
|
||||
// $time = date('Ymd');
|
||||
// $sign = md5($basic_detection_organ['app_id'] . $basic_detection_organ['app_secret'] . $time);
|
||||
// if ($auth != $sign){
|
||||
// return $this->detectionResultFailReturn("签名错误");
|
||||
// }
|
||||
//
|
||||
// // 检测pdf文件
|
||||
// $pdfData = base64_decode($request_params['pdfReport']);
|
||||
// if (!$pdfData){
|
||||
// return $this->detectionResultFailReturn("文件错误");
|
||||
// }
|
||||
//
|
||||
// // 获取检测订单数据
|
||||
// $params = array();
|
||||
// $params['detection_no'] = $request_params['orderCode'];
|
||||
// $order_detection = OrderDetection::getOne($params);
|
||||
// if (empty($order_detection)){
|
||||
// return $this->detectionResultFailReturn("非法订单");
|
||||
// }
|
||||
//
|
||||
// // 检测订单状态
|
||||
// if ($order_detection['detection_status'] != 3){
|
||||
// return $this->detectionResultFailReturn("订单状态错误,无法处理");
|
||||
// }
|
||||
//
|
||||
// if (!empty($order_detection['detection_result_pdf'])){
|
||||
// return $this->detectionResultSuccessReturn();
|
||||
// }
|
||||
//
|
||||
// if ($order_detection['detection_bar_code'] != $request_params['detectBarcode']){
|
||||
// return $this->detectionResultFailReturn("检测条码无法对应");
|
||||
// }
|
||||
//
|
||||
// // 获取医生数据
|
||||
// $params = array();
|
||||
// $params['doctor_id'] = $order_detection['doctor_id'];
|
||||
// $user_doctor = UserDoctor::getOne($params);
|
||||
// if (empty($user_doctor)){
|
||||
// return $this->detectionResultFailReturn("医生数据错误");
|
||||
// }
|
||||
//
|
||||
// // 获取检测病例数据
|
||||
// $params = array();
|
||||
// $params['order_detection_id'] = $order_detection['order_detection_id'];
|
||||
// $order_detection_case = OrderDetectionCase::getOne($params);
|
||||
// if (empty($order_detection_case)){
|
||||
// return $this->detectionResultFailReturn("订单数据错误");
|
||||
// }
|
||||
//
|
||||
// // 获取检测项目数据
|
||||
// $params = array();
|
||||
// $params['detection_project_id'] = $order_detection['detection_project_id'];
|
||||
// $detection_project = DetectionProject::getOne($params);
|
||||
// if (empty($detection_project)){
|
||||
// return $this->detectionResultFailReturn("订单数据错误");
|
||||
// }
|
||||
//
|
||||
// // 检测家庭成员是否存在
|
||||
// $params = array();
|
||||
// $params['family_id'] = $order_detection['family_id'];
|
||||
// $params['patient_id'] = $order_detection['patient_id'];
|
||||
// $patient_family = PatientFamily::getOne($params);
|
||||
// if (empty($patient_family)) {
|
||||
// return $this->detectionResultFailReturn("患者信息错误");
|
||||
// }
|
||||
//
|
||||
// // 上传处方图片至oss
|
||||
// $oss = new Oss();
|
||||
// $detection_result_pdf_name = "applet/patient/detection/pdf/" . $order_detection['order_detection_id'] . '.' . 'pdf';
|
||||
// $detection_result_pdf = $oss->putObject($detection_result_pdf_name, $pdfData);
|
||||
// $detection_result_pdf = '/' . $detection_result_pdf;
|
||||
//
|
||||
// Db::beginTransaction();
|
||||
//
|
||||
// try {
|
||||
// $generator = $this->container->get(IdGeneratorInterface::class);
|
||||
//
|
||||
// // 创建问诊订单
|
||||
// $data = array();
|
||||
// $data['user_id'] = $order_detection['user_id'];
|
||||
// $data['patient_id'] = $order_detection['patient_id'];
|
||||
// $data['doctor_id'] = $order_detection['doctor_id'];
|
||||
// $data['family_id'] = $order_detection['family_id'];
|
||||
// $data['inquiry_type'] = 5; // 订单类型(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药 5:检测)
|
||||
// $data['inquiry_mode'] = 1; // 订单问诊方式(1:图文 2:视频 3:语音 4:电话 5:会员)
|
||||
// $data['inquiry_status'] = 4; // 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
// $data['inquiry_pay_channel'] = 3; // 支付渠道(1:小程序支付 2:微信扫码支付 3:模拟支付)
|
||||
// $data['inquiry_pay_status'] = 2; // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
// $data['inquiry_no'] = $generator->generate();// 订单编号
|
||||
// $data['escrow_trade_no'] = "GD" . $generator->generate(); // 第三方支付流水号
|
||||
// $data['amount_total'] = 0;// 订单金额
|
||||
// $data['coupon_amount_total'] = 0;// 优惠卷总金额
|
||||
// $data['payment_amount_total'] = 0;// 实际付款金额
|
||||
// $data['pay_time'] = date('Y-m-d H:i:s', time());// 支付时间
|
||||
// $data['reception_time'] = date('Y-m-d H:i:s', time());// 接诊时间
|
||||
// $data['patient_name'] = $patient_family['card_name'];// 患者姓名-就诊人
|
||||
// $data['patient_name_mask'] = $patient_family['card_name_mask'];// 患者姓名-就诊人(掩码)
|
||||
// $data['patient_sex'] = $patient_family['sex'];// 患者性别-就诊人(0:未知 1:男 2:女)
|
||||
// $data['patient_age'] = $patient_family['age'];// 患者年龄-就诊人
|
||||
// $order_inquiry = OrderInquiry::addOrderInquiry($data);
|
||||
// if (empty($order_inquiry)) {
|
||||
// Db::rollBack();
|
||||
// return $this->detectionResultFailReturn("问诊订单创建失败");
|
||||
// }
|
||||
//
|
||||
// // 回填问诊订单id
|
||||
// $order_detection['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
//
|
||||
// // 增加患者问诊病例
|
||||
// $data = array();
|
||||
// $data['user_id'] = $order_detection['user_id'];
|
||||
// $data['patient_id'] = $order_detection['patient_id'];
|
||||
// $data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];// 订单-问诊id
|
||||
// $data['family_id'] = $patient_family['family_id']; // 家庭成员id
|
||||
// $data['relation'] = $patient_family['relation']; // 与患者关系(1:本人 2:父母 3:爱人 4:子女 5:亲戚 6:其他 )
|
||||
// $data['name'] = $patient_family['card_name']; // 患者名称
|
||||
// $data['sex'] = $patient_family['sex'] ?? 0; // 患者性别(0:未知 1:男 2:女)
|
||||
// $data['age'] = $patient_family['age'] ?? null; // 患者年龄
|
||||
// $data['height'] = $patient_family['height'] ?: null; // 身高(cm)
|
||||
// $data['weight'] = $patient_family['weight'] ?: null;; // 体重(kg)
|
||||
// $order_inquiry_case = OrderInquiryCase::addOrderInquiryCase($data);
|
||||
// if (empty($order_inquiry_case)) {
|
||||
// Db::rollBack();
|
||||
// return $this->detectionResultFailReturn("问诊订单病例创建失败");
|
||||
// }
|
||||
//
|
||||
// // 修改检测订单
|
||||
// $data = array();
|
||||
// $data['detection_status'] = 4;
|
||||
// $data['detection_result_pdf'] = $detection_result_pdf;
|
||||
// $data['detection_result_date'] = date('Y-m-d H:i:s',time());
|
||||
// $data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];// 订单-问诊id
|
||||
//
|
||||
// $params = array();
|
||||
// $params['order_detection_id'] = $order_detection['order_detection_id'];
|
||||
// OrderDetection::editOrderDetection($params,$data);
|
||||
//
|
||||
// // 回填检测结果字段
|
||||
// $order_detection['detection_result_pdf'] = $detection_result_pdf;
|
||||
// $order_detection['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
//
|
||||
// // 添加自动完成队列
|
||||
// $time = 1000 * 60 * 60 * 24 * 3;
|
||||
//
|
||||
// $data = array();
|
||||
// $data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
//
|
||||
// $message = new AutoCompleteInquiryDelayDirectProducer($data);
|
||||
// $message->setDelayMs($time);
|
||||
// $producer = $this->container->get(Producer::class);
|
||||
// $res = $producer->produce($message);
|
||||
// if (!$res) {
|
||||
// Db::rollBack();
|
||||
// return $this->detectionResultFailReturn("添加自动完成队列失败");
|
||||
// }
|
||||
//
|
||||
// // 发送im消息
|
||||
// $imService = new ImService();
|
||||
//
|
||||
// // 患者病例
|
||||
// $imService->patientCase(
|
||||
// $order_inquiry,
|
||||
// $user_doctor['user_id'],
|
||||
// $order_inquiry_case['disease_desc']
|
||||
// );
|
||||
//
|
||||
// // 发送IM消息-检测报告结果
|
||||
// $imService->detectionTestReport(
|
||||
// $order_detection,
|
||||
// $user_doctor['user_id'],
|
||||
// $order_detection['user_id'],
|
||||
// $order_detection_case['detection_disease_class_names'],
|
||||
// $detection_project['detection_project_name']
|
||||
// );
|
||||
//
|
||||
// Db::commit();
|
||||
// } catch (\Throwable $e) {
|
||||
// Db::rollBack();
|
||||
// return $this->detectionResultFailReturn($e->getMessage());
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// // 发送IM消息-检测报告结果-文字
|
||||
// $imService->detectionTestReportStr(
|
||||
// $order_detection,
|
||||
// $user_doctor['user_name'],
|
||||
// $detection_project['detection_project_name'],
|
||||
// $user_doctor['user_id'],
|
||||
// $order_detection['user_id']
|
||||
// );
|
||||
//
|
||||
// // 患者-新报告生成通知
|
||||
// $MessagePush = new MessagePush($order_detection['user_id']);
|
||||
// $MessagePush->patientDetectionResultNotice($order_detection['order_detection_id']);
|
||||
//
|
||||
// // 医生-通知医生患者检测报告已生成
|
||||
// $MessagePush = new MessagePush($user_doctor['user_id']);
|
||||
// $MessagePush->doctorDetectionResultNotice($order_detection['order_detection_id']);
|
||||
// }catch (\Throwable $e){
|
||||
// Log::getInstance("detectionResult")->error($e->getMessage());
|
||||
// }
|
||||
//
|
||||
// return $this->detectionResultSuccessReturn();
|
||||
// } catch (\Throwable $e) {
|
||||
// return $this->detectionResultFailReturn("异常:" . $e->getMessage());
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 检测所结果回调
|
||||
* @return ResponseInterface
|
||||
|
||||
Reference in New Issue
Block a user