PHP Warning 'yii\base\ErrorException' 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等可以参考其他使用产景文章来源:https://www.toymoban.com/news/detail-743959.html
定时任务脚本中存在一个批量遍历去请求图片的接口;特别是脚本中,一定的要兼容好,比如try等文章来源地址https://www.toymoban.com/news/detail-743959.html
/**
* 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']){
\app\models\Goods::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{
\app\models\Goods::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的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!