我是靠谱客的博主 缓慢黑猫,最近开发中收集的这篇文章主要介绍failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

PHP Warning 'yiibaseErrorException' with message 'file_get_contents(https://img12.360buyimg.com/n5/s1200x800_jfs/t1/69307/10/5911/292411/5d3e610cEce4e6f5a/b69fbf56874af00d.jpg): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found

上面问题很多种处理方案;比如使用curl等可以参考其他使用产景

定时任务脚本中存在一个批量遍历去请求图片的接口;特别是脚本中,一定的要兼容好,比如try等

 /**
     * Created by XX
     * description: 批量同步支付宝商品文件
     */
    public function actionSyncAlipayGoodsFile()
    {
        set_time_limit(0);
        date_default_timezone_set("PRC");
        $store_list = array_column(Store::find()->where(['is_delete' => 0, 'is_recycle' => 0])->select(['id'])->asArray()->all(), 'id');
        if (empty($store_list)) {
            return;
        }
        //遍历商户
        foreach ($store_list as $store_id) {
            $key = CacheKeyEnum::ALIPAY_GOODS_FILE.$store_id;
            $redis = Yii::$app->redis;
            $len = $redis->llen($key);
            if(!$len){
                continue;
            }
            $successCount = $errorCount = 0;
            for ($i=1; $i<=$len; $i++) {
                $good = $redis->rpop($key);
                if($good){
                    $good = json_decode($good,true);
                    if($good['cover_pic']){

                        //避免图片不存在导致脚本中断问题
                        if(!@fopen($good['cover_pic'], 'r' )){
                            continue;
                        }
                        $file_content = saveAlipayTempImage(file_get_contents($good['cover_pic']));
                        $config = MpConfig::get($store_id);
                        //避免未知原因实例化失败导致其他商户受影响
                        try {
                            $aop = $config->getClient();
                        } catch (InvalidArgumentException $ex) {
                            continue;
                        }

                        try {
                            $request = AlipayRequestFactory::create('alipay.merchant.item.file.upload', [
                                'scene'=> 'SYNC_ORDER',
                                'file_content'=> '@'.$file_content
                            ]);
                            $response = $aop->execute($request);
                            $data = $response->getData();
                            if(isset($data['material_id']) && $data['material_id']){
                                appmodelsGoods::updateAll(['material_id'=>$data['material_id'],'material_key'=>$data['material_key'],'material_status'=>1],['id'=>$good['id']]);
                                $successCount+=1;
                                Yii::$app->redis->incr(CacheKeyEnum::ALIPAY_GOODS_FILE_SUCCESS.$store_id);
                            }else{
                                appmodelsGoods::updateAll(['material_reason'=>$data['sub_msg'],'material_status'=>2],['id'=>$good['id']]);
                                $errorCount+=1;
                                Yii::$app->redis->incr(CacheKeyEnum::ALIPAY_GOODS_FILE_FAIL.$store_id);
                            }
                        }catch (AlipayException $ex) {
                            $errorCount+=1;
                            Yii::$app->redis->incr(CacheKeyEnum::ALIPAY_GOODS_FILE_FAIL.$store_id);
                            Yii::error(['data' => $ex->getMessage()], '支付宝订单中心:商品文件上传失败');
                        }
                    }
                }
            }
            Yii::$app->redis->del(CacheKeyEnum::ALIPAY_GOODS_FILE.$store_id.'TotalCount');
        }
        echo 'batch sync alipay goods file success'. "n";
    }

最后

以上就是缓慢黑猫为你收集整理的failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found的全部内容,希望文章能够帮你解决failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(62)

评论列表共有 0 条评论

立即
投稿
返回
顶部