Przeglądaj źródła

美团对接-回调

fang 1 rok temu
rodzic
commit
4e849d44f5

+ 2 - 1
app/api/controller/notify/MeiTuanNotifyController.php

@@ -256,7 +256,7 @@ class MeiTuanNotifyController extends BaseApiController
         //尾款结算1        //尾款结算3
         //获取工单信息
         $request = $this->request->param();
-//        $request = json_decode('{"opBizCode":"AE7MKOJAV67338LIC3UD0K5TGIO","msgType":"5810031","developerId":"114657","businessId":"58","sign":"1cd993779d2e835ef3582c5e424d52b1d580b2da","msgId":"6219413406543364268","message":"{\"orderId\":\"61374467\",\"verifyStatus\":\"2\",\"verifyChannel\":\"1\",\"type\":\"2\",\"serialNumber\":\"5831711557\"}","timestamp":"1741600285"}',true);
+//        $request = json_decode('{"opBizCode":"AE7MKOJAV67338LIC3UD0K5TGIO","msgType":"5810031","developerId":"114657","businessId":"58","sign":"d43ab164d41859ce7df2894e3e8f086d0c3182cb","msgId":"-1355174693375827369","message":"{\"orderId\":\"61659141\",\"verifyStatus\":\"2\",\"verifyChannel\":\"1\",\"type\":\"2\",\"serialNumber\":\"7843863751\"}","timestamp":"1741927727"}',true);
         Log::write('预订核销同步:'.json_encode($this->request->param(),JSON_UNESCAPED_UNICODE));
         if(!empty($request['message'])){
             Db::startTrans();
@@ -272,6 +272,7 @@ class MeiTuanNotifyController extends BaseApiController
                         $work = ServiceWork::where('id',$order['work_id'])->findOrEmpty();
                         $order->verifyStatus = 2;
                         $order->save();
+
                         if(!$work->isEmpty()){
                             $work->work_pay_status = WorkEnum::IS_PAY_STATUS;
                             $orders = \app\common\model\orders\RechargeOrder::where(['work_id'=>$order->work_id])->select()->toArray();

+ 29 - 0
app/api/controller/notify/UserConfirmController.php

@@ -0,0 +1,29 @@
+<?php
+
+namespace app\api\controller\notify;
+
+use app\api\controller\BaseApiController;
+use app\api\validate\UserConfirmValidate;
+
+/**
+ *
+ * Class UserConfirmController
+ * @package app\api\controller\notify
+ */
+class UserConfirmController extends BaseApiController
+{
+
+    public array $notNeedLogin = ['confirmDoor'];
+
+    public function ConfirmDoor()
+    {
+        $params = (new UserConfirmValidate())->post()->goCheck('confirmDoor');
+        try {
+            $decryptData = decrypt($params['code'], \think\facade\Config::get('project.work_sn_key'));
+        }catch (\Exception $e){
+            return $this->fail($e->getMessage());
+        }
+        return $this->success('已确认上门');
+    }
+
+}

+ 33 - 0
app/api/validate/UserConfirmValidate.php

@@ -0,0 +1,33 @@
+<?php
+namespace app\api\validate;
+
+
+use app\common\validate\BaseValidate;
+
+/**
+ * 用户确认验证器
+ * Class UserValidate
+ * @package app\api\validate
+ */
+class UserConfirmValidate extends BaseValidate
+{
+
+    protected $rule = [
+        'code' => 'require',
+        'phone'=>'require',
+        'sms_code'=>'require',
+    ];
+
+    protected $message = [
+        'code.require' => '参数缺失',
+        'phone.require' => '手机号缺失',
+        'sms_code.require' => '验证码缺失',
+    ];
+
+
+    public function sceneConfirmDoor()
+    {
+        return $this->only(['code','phone','sms_code']);
+    }
+
+}

+ 35 - 0
app/common.php

@@ -563,4 +563,39 @@ function getOptionDataByTable($table) {
         $lists = TableDataLogic::$table();
     }
     return $lists??[];
+}
+
+
+//加密函数
+function encrypt($data, $key) {
+    // 生成一个初始化向量(iv)
+    $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
+    // 使用AES-256-CBC加密模式进行加密
+    $encrypted = openssl_encrypt($data, 'aes-256-cbc', $key, 0, $iv);
+    // 返回加密后的数据与IV的组合,方便解密时使用
+    return base64_encode($encrypted . '::' . $iv);
+}
+
+//解密函数
+function decrypt($data, $key) {
+    try {
+        // 将 base64 编码的数据解码
+        list($encrypted_data, $iv) = explode('::', base64_decode($data), 2);
+
+        // 检查 IV 长度是否正确
+        $expectedIvLength = openssl_cipher_iv_length('aes-256-cbc');
+        if (strlen($iv) !== $expectedIvLength) {
+            throw new Exception("IV length is incorrect. Expected {$expectedIvLength} bytes, got " . strlen($iv));
+        }
+
+        // 使用相同的密钥和 IV 来解密数据
+        $decrypted = openssl_decrypt($encrypted_data, 'aes-256-cbc', $key, 0, $iv);
+        if ($decrypted === false) {
+            throw new Exception("Decryption failed.");
+        }
+        return $decrypted;
+    } catch (Exception $e) {
+        // 捕获并处理异常
+        throw new Exception('参数不合规');
+    }
 }

+ 17 - 0
app/workerapi/controller/WorksController.php

@@ -350,5 +350,22 @@ class WorksController extends BaseApiController
         return $this->success('成功', [], 1, 1);
     }
 
+    /**
+     * 上门码和完成码
+     * @return \think\response\Json
+     */
+    public function showDoorCode(): \think\response\Json
+    {
+        $params = (new ServiceWorkValidate())->get()->goCheck('doorCode', [
+            'user_id' => $this->userId,
+            'user_info' => $this->userInfo
+        ]);
+        $result = ServiceWorkLogic::confirmDoorCode($params);
+        if (false === $result) {
+            return $this->fail(ServiceWorkLogic::getError());
+        }
+        return $this->success('操作成功,工程师已上门,请用户扫码确认', $result, 1, 1);
+    }
+
 
 }

+ 3 - 0
config/project.php

@@ -129,4 +129,7 @@ return [
         'be_expire_duration' => 3600,//管理后台token临时过期前时长,自动续期
     ],
 
+    'user_website' => 'https://user.kyjlkj.com',//用户扫码域名
+    'work_sn_key' => 'sdfas4546',//工单key
+
 ];