1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace App\Service;
- use App\Log;
- use App\Models\AccountLicense;
- use App\RedisModel;
- use App\Support\EmailQueue;
- class SystemCallbackService
- {
- /**
- * 系统回调事件处理
- * */
- public static function responseDeal($msgStr)
- {
- try {
- if(!empty($msgStr)) {
- $msgObj = simplexml_load_string($msgStr, 'SimpleXMLElement', LIBXML_NOCDATA);
- $infoType = trim($msgObj->Event);
- if(empty($infoType)) {
- $infoType = trim($msgObj->InfoType);
- }
- switch ($infoType) {
- case 'license_pay_success': // 客服许可购买
- $corpid = trim($msgObj->AuthCorpId);
- $orderId = trim($msgObj->OrderId);
- $buyerUserId = trim($msgObj->BuyerUserId);
- if(empty($corpid) || empty($orderId)) {
- EmailQueue::rPush('客服许可购买系统消息内容异常', $msgStr, ['xiaohua.hou@kuxuan-inc.com'], '猎羽');
- Log::logError('客服许可购买系统消息内容异常', ['msg' => $msgStr], 'ResponseSystemMsg');
- return false;
- }
- # 录入Redis
- $data = array('corpid' => $corpid, 'order_id' => $orderId, 'buyer_user_id' => $buyerUserId);
- RedisModel::lPush(AccountLicense::LICENSE_ORDER_RDS, json_encode($data));
- break;
- case 'license_refund': // 退款结果通知
- $corpid = trim($msgObj->AuthCorpId);
- $orderId = trim($msgObj->OrderId);
- $orderStatus = trim($msgObj->OrderStatus);
- if(empty($corpid) || empty($orderId)) {
- EmailQueue::rPush('许可订单退款消息内容异常', $msgStr, ['xiaohua.hou@kuxuan-inc.com'], '猎羽');
- Log::logError('许可订单退款消息内容异常', ['msg' => $msgStr], 'ResponseSystemMsg');
- return false;
- }
- if($orderStatus == 1) { // 退款成功
- # 录入Redis
- $data = array('corpid' => $corpid, 'order_id' => $orderId);
- RedisModel::lPush(AccountLicense::LICENSE_REFUND_ORDER_RDS, json_encode($data));
- }
- break;
- default:
- Log::logInfo('未处理的系统消息', ['msg' => $msgStr], 'UncaughtResponseSystemMsg');
- break;
- }
- } else {
- # 写入日志
- Log::logError($msgStr, [], 'ResponseSystemMsg');
- return false;
- }
- } catch (\Exception $e) {
- EmailQueue::rPush('处理系统消息回调数据发生异常', $msgStr, ['xiaohua.hou@kuxuan-inc.com'], '猎羽');
- Log::logError('处理系统消息回调数据发生异常', [
- 'line' => $e->getLine(),
- 'msg' => $e->getMessage(),
- 'data' => $msgStr
- ], 'ResponseSystemMsg');
- return false;
- }
- return true;
- }
- }
|