argument('appId'), $this->argument('batchId'), $this->argument('channelId')]; // 获取参数 if (!$appId || !$batchId || !$channelId) { return false; } // 获取msg信息,未查询到数据或者media_id已存在则不再继续往下执行 $msgInfo = WechatMaterialSendMsg::getMsgByAppBatchChannelId($appId, $batchId, $channelId); \Log::info($this->_task . 'msgInfo'); \Log::info($msgInfo); if (!$msgInfo) { return false; } // 获取素材数据 $materials = WechatMaterial::getWeChatMaterials($batchId); $materials = $materials ? $materials->toArray() : []; \Log::info($this->_task . 'materials_ids'); \Log::info(array_column($materials, 'id')); if (!$materials) { return false; } // 筛选出内容中的所有图片 $contents = implode(',', array_column($materials, 'content')); $images = CustomMsgService::extract_content_images($contents); \Log::info($this->_task . 'extract_content_image_urls'); \Log::info($images); // 上传内容中的图片,替换内容中图片链接 $upImagesRes = CustomMsgService::multi_upload_material_imgs($appId, $images); [$oldUrls, $newUrls] = [array_column($upImagesRes['urls'], 'old_url'), array_column($upImagesRes['urls'], 'new_url')]; $materials = CustomMsgService::replace_content_images($materials, $oldUrls, $newUrls); dd($images, $upImagesRes, $oldUrls, $newUrls, $materials); // 批量上传缩略图 $thumbImages = array_column($materials, 'cover_url'); $upThumbsRes = CustomMsgService::multi_upload_material_imgs($appId, $thumbImages, 'thumb'); // 上传article $upArticleRes = CustomMsgService::upload_articles($channelId, $msgInfo, $materials, $upThumbsRes['urls']); $wxMediaId = getProp($upArticleRes['data'], 'media_id'); if ($wxMediaId) { // 更新media_id WechatMaterialSendMsg::where('id', getProp($msgInfo, 'id'))->update([ 'wechat_media_id' => $wxMediaId, 'upload_result' => json_encode([ 'up_images' => $upImagesRes['urls'], 'up_thumbs' => $upThumbsRes['urls'], 'up_articles' => $upArticleRes ]), 'status' => 'push_wechat_material', 'updated_at' => date('Y-m-d H:i:s') ]); // 更新batch同步状态 BatchWechatMaterial::where('id', $batchId)->update([ 'status' => 'push_wechat_material', 'updated_at' => date('Y-m-d H:i:s') ]); } else { $msg = 'upload fail'; if ($upArticleRes && !$upArticleRes['code']) $msg = $upArticleRes['msg']; if (getProp($upThumbsRes['error'], 'thumb')) $msg = getProp($upThumbsRes['error'], 'thumb'); if (getProp($upImagesRes['error'], 'common')) $msg = getProp($upImagesRes['error'], 'common'); // 更新上传结果 WechatMaterialSendMsg::where('id', getProp($msgInfo, 'id'))->update([ 'upload_result' => $msg, 'status' => 'fail_push_wechat_material', 'updated_at' => date('Y-m-d H:i:s') ]); } } }