企微短剧业务系统

SystemCallbackService.php 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace App\Service;
  3. use App\Log;
  4. use App\Models\AccountLicense;
  5. use App\RedisModel;
  6. use App\Support\EmailQueue;
  7. class SystemCallbackService
  8. {
  9. /**
  10. * 系统回调事件处理
  11. * */
  12. public static function responseDeal($msgStr)
  13. {
  14. try {
  15. if(!empty($msgStr)) {
  16. $msgObj = simplexml_load_string($msgStr, 'SimpleXMLElement', LIBXML_NOCDATA);
  17. $infoType = trim($msgObj->Event);
  18. if(empty($infoType)) {
  19. $infoType = trim($msgObj->InfoType);
  20. }
  21. switch ($infoType) {
  22. case 'license_pay_success': // 客服许可购买
  23. $corpid = trim($msgObj->AuthCorpId);
  24. $orderId = trim($msgObj->OrderId);
  25. $buyerUserId = trim($msgObj->BuyerUserId);
  26. if(empty($corpid) || empty($orderId)) {
  27. EmailQueue::rPush('客服许可购买系统消息内容异常', $msgStr, ['xiaohua.hou@kuxuan-inc.com'], '猎羽');
  28. Log::logError('客服许可购买系统消息内容异常', ['msg' => $msgStr], 'ResponseSystemMsg');
  29. return false;
  30. }
  31. # 录入Redis
  32. $data = array('corpid' => $corpid, 'order_id' => $orderId, 'buyer_user_id' => $buyerUserId);
  33. RedisModel::lPush(AccountLicense::LICENSE_ORDER_RDS, json_encode($data));
  34. break;
  35. case 'license_refund': // 退款结果通知
  36. $corpid = trim($msgObj->AuthCorpId);
  37. $orderId = trim($msgObj->OrderId);
  38. $orderStatus = trim($msgObj->OrderStatus);
  39. if(empty($corpid) || empty($orderId)) {
  40. EmailQueue::rPush('许可订单退款消息内容异常', $msgStr, ['xiaohua.hou@kuxuan-inc.com'], '猎羽');
  41. Log::logError('许可订单退款消息内容异常', ['msg' => $msgStr], 'ResponseSystemMsg');
  42. return false;
  43. }
  44. if($orderStatus == 1) { // 退款成功
  45. # 录入Redis
  46. $data = array('corpid' => $corpid, 'order_id' => $orderId);
  47. RedisModel::lPush(AccountLicense::LICENSE_REFUND_ORDER_RDS, json_encode($data));
  48. }
  49. break;
  50. default:
  51. Log::logInfo('未处理的系统消息', ['msg' => $msgStr], 'UncaughtResponseSystemMsg');
  52. break;
  53. }
  54. } else {
  55. # 写入日志
  56. Log::logError($msgStr, [], 'ResponseSystemMsg');
  57. return false;
  58. }
  59. } catch (\Exception $e) {
  60. EmailQueue::rPush('处理系统消息回调数据发生异常', $msgStr, ['xiaohua.hou@kuxuan-inc.com'], '猎羽');
  61. Log::logError('处理系统消息回调数据发生异常', [
  62. 'line' => $e->getLine(),
  63. 'msg' => $e->getMessage(),
  64. 'data' => $msgStr
  65. ], 'ResponseSystemMsg');
  66. return false;
  67. }
  68. return true;
  69. }
  70. }