[已解决]模型里发送curl请求,就会导致多次重复执行

帝国大将

问题描述

问题已自行解决,原因是回调里有代码一直调用模型导致的

只要进行了curl请求,就会导致多次重复执行

程序代码或配置

//开始执行
  $ids = (new PingtaiModel())->chadianbiaoxinxi;
            $res = (new PingtaiUseModel())->whereIn('config_id',$ids)->where(['status'=>2,'id'=>11])->select()->each(function ($v){
                (new DianbiaoModel())->tongbu($v['code']);
            });

//这是模型内的逻辑
$dianchong = (new DianbiaoChongModel())->where(['code' => $code,'status'=>1])->find();
                if(!$dianchong)break;
                if($dianchong['status'] == 2)break;
                if($dianchong['money'] <= 0)break;

                $dianbiao = (new DianbiaoModel())->where(['id' => $dianchong['dianbiao_id']])->find();
                if(!$dianbiao)break;
                $dianbiao = (new DianbiaoModel())->simple($dianbiao);
                $use = (new PingtaiUseModel())
                    ->where([
                        ['admin_id','=',$dianbiao['admin_id']],
                        ['status','=',2],
                        ['dianbiao_ids','like',"%.{$dianbiao['id']}.%"],
                    ])
                    ->find();
                if(!$use)break;

                $bill = (new UserBillModel())->where(['code'=>$code,'status'=>1])->find();
                if($bill){
                    if($bill['status'] == 2)break;
                    if($bill['money'] <= 0)break;
                }

                $json = json_decode($use['json'],true);
                $auth = '';
                $nonce = '';

                foreach ($json as $v){
                    foreach ($v as $key => $val){
                        if($key == 'auth'){
                            $auth = $val;
                        }
                        if($key == 'nonce'){
                            $nonce = $val;
                        }
                    }
                }
                if($auth == '' || $nonce == ''){
                    (new Base())->yichang('口令或混淆字符串缺失');
                }
                $url = $use['url'];
                $time = time();

                (new BiaoNotifyModel())->save([
                    'code' => $code,
                    'name' => '电表充值',
                    'admin_id' => $dianbiao['admin_id'],
                    'cate' => (new BiaoNotifyModel())->dianbiao,
                ]);

                $request_content = [
                    [
                        "opr_id" => "$code",
                        "time_out" => 0,
                        "must_online" => false,
                        "retry_times" => 1,
                        "cid" => "{$dianbiao['base']['collectorid']}",
                        "address" => "{$dianbiao['base']['address']}",
                        "params" => [
                            "money" => $dianchong['money']
                        ]
                    ]
                ];

                $request_content = json_encode($request_content);
                $arr = [
                    'auth_code' => "{$auth}",
                    'timestamp' => $time,
                    'request_content' => $request_content,
                    'notify_url' => (new Base())->https."/api/notifyBiao/dianbiaoCharge?sn={$dianbiao['sn']}"
                ];
                $sign = $this->getSign($arr,$nonce);
                $arr['sign'] = $sign;
                $postdata = http_build_query($arr);
                $options = array(
                    'http' => array(
                        'method' => 'POST',
                        'header' => 'Content-type:application/x-www-form-urlencoded',
                        'content' => $postdata,
                        'timeout' => 15 * 60 // 超时时间(单位:s)
                    )
                );

                $context = stream_context_create($options);

                //这里就是问题的来源
                $res = file_get_contents($url, false, $context);

                $status = 1;

                (new BiaoNotifyModel())->where(['code' => $code])->save([
                    'param' => json_encode($arr, JSON_UNESCAPED_UNICODE),
                    'json' => $res,
                    'status' => $status
                ]);

重现问题的步骤

操作系统环境及workerman/webman等具体版本

"workerman/webman-framework": "^1.5.0",
centos7.8

454 1 0
1个回答

帝国大将

break是因为外面我还进行了switch,那部分就不粘贴了

🔝