【操盘手】 朋友圈自动同步

This commit is contained in:
wong
2025-05-23 16:48:13 +08:00
parent c2497ec433
commit db5e4d8726
4 changed files with 65 additions and 39 deletions

View File

@@ -83,19 +83,12 @@ class MomentsController extends BaseController
// 发送请求发布朋友圈
$result = requestCurl($this->baseUrl . 'api/JobPublishWechatMoments/addJob', $params, 'POST', $header, 'json');
// 处理响应
if (is_numeric($result)) {
return successJson(['jobId' => $result], '朋友圈任务创建成功');
if (empty($result)) {
return successJson([], '朋友圈任务创建成功');
} else {
// 尝试解析JSON
$response = json_decode($result, true);
if (json_last_error() === JSON_ERROR_NONE && isset($response['id'])) {
return successJson(['jobId' => $response['id']], '朋友圈任务创建成功');
}
// 如果返回的是错误信息
return errorJson(is_string($result) ? $result : '创建朋友圈任务失败');
return errorJson($result);
}
} catch (\Exception $e) {
return errorJson('发布朋友圈失败:' . $e->getMessage());

View File

@@ -125,6 +125,35 @@ class WorkbenchMomentsJob
// 转换内容类型
$momentContentType = self::CONTENT_TYPE_MAP[$contentLibrary['contentType']] ?? 1;
$sendTime = !empty($contentLibrary['sendTime']) ? $contentLibrary['sendTime'] : time();
// 图片url
if($momentContentType == 2){
$picUrlList = json_decode($contentLibrary['resUrls'], true);
}else{
$picUrlList = [];
}
// 视频url
if($momentContentType == 3){
$videoUrl = json_decode($contentLibrary['urls'], true);
$videoUrl = $videoUrl[0] ?? '';
}else{
$videoUrl = '';
}
// 链接url
if($momentContentType == 4){
$urls = json_decode($contentLibrary['urls'],true);
$url = $urls[0] ?? [];
$link = [
'desc' => $url['desc'] ?? '',
'image' => $url['image'] ?? '',
'url' => $url['url'] ?? ''
];
}else{
$link = ['image' => ''];
}
// 准备发送参数
$data = [
'altList' => '',
@@ -133,26 +162,21 @@ class WorkbenchMomentsJob
'jobPublishWechatMomentsItems' => $jobPublishWechatMomentsItems,
'lat' => 0,
'lng' => 0,
'link' => ['image' => ''],
'link' => $link,
'momentContentType' => $momentContentType,
'picUrlList' => json_decode($contentLibrary['resUrls'], true),
'picUrlList' => $picUrlList,
'poiAddress' => '',
'poiName' => '',
'publicMode' => '',
'text' => $contentLibrary['content'],
'timingTime' => date('Y-m-d H:i:s', $sendTime),
'beginTime' => date('Y-m-d H:i:s', $sendTime),
'endTime' => date('Y-m-d H:i:s', $sendTime + 60),
'videoUrl' => '',
'endTime' => date('Y-m-d H:i:s', $sendTime + 600),
'videoUrl' => $videoUrl,
];
print_r($data);
exit;
// 发送朋友圈
$moments = new Moments();
$moments->addJob($data);
// 记录发送记录
$this->recordSendHistory($workbench, $devices, $contentLibrary);
}
@@ -168,16 +192,16 @@ class WorkbenchMomentsJob
$now = time();
$data = [];
foreach ($devices as $device) {
$data[] = [
$data = [
'workbenchId' => $workbench->id,
'deviceId' => $device['deviceId'],
'contentId' => $contentLibrary['id'],
'libraryId' => $contentLibrary['libraryId'],
'wechatAccountId' => $device['wechatAccountId'],
'createTime' => $now,
'updateTime' => $now
];
Db::name('workbench_moments_sync_item')->insert($data);
}
Db::name('workbench_moments_sync_item')->insertAll($data);
}
/**