From 66b130998fa9c2b2ca238d86dbbcf9f2e01c01f1 Mon Sep 17 00:00:00 2001 From: "zhangf@suq.cn" Date: Wed, 17 Dec 2025 10:25:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(admin):=20=E6=96=B0=E5=A2=9E=E5=AA=92?= =?UTF-8?q?=E4=BD=93=E5=9C=88=E8=B5=84=E6=BA=90=E5=8F=98=E6=9B=B4=E4=B8=8E?= =?UTF-8?q?=E7=A8=BF=E4=BB=B6=E8=BF=9B=E5=BA=A6=E9=80=9A=E7=9F=A5=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加无需登录的资源批量变更通知接口 - 添加无需登录的稿件安排进度通知接口 - 实现资源变更数据解密与存储逻辑 - 实现稿件进度更新逻辑 - 新增投稿记录模型及DAO层 - 添加投稿接口服务实现 - 注册相关路由并配置权限控制 --- app/controller/admin/ApiController.php | 1 + app/controller/admin/OnlineMediasController.php | 32 ++++++++ app/dao/user/CreationArticleReceiveRecordsDao.php | 15 ++++ app/model/user/CreationArticleReceiveRecords.php | 33 ++++++++ app/route/admin.php | 9 +++ app/route/route.php | 1 + app/service/admin/ApiService.php | 99 +++++++++++++++++++++-- app/service/user/ApiService.php | 89 ++++++++++++++++++++ 8 files changed, 273 insertions(+), 6 deletions(-) create mode 100644 app/dao/user/CreationArticleReceiveRecordsDao.php create mode 100644 app/model/user/CreationArticleReceiveRecords.php create mode 100644 app/service/user/ApiService.php diff --git a/app/controller/admin/ApiController.php b/app/controller/admin/ApiController.php index e4103f9..4b16514 100644 --- a/app/controller/admin/ApiController.php +++ b/app/controller/admin/ApiController.php @@ -6,6 +6,7 @@ use support\Response; /** * 调用媒体圈接口控制器 + * 初始化使用一次,后续为上游推送 */ class ApiController { diff --git a/app/controller/admin/OnlineMediasController.php b/app/controller/admin/OnlineMediasController.php index 149e6ab..e80d6eb 100644 --- a/app/controller/admin/OnlineMediasController.php +++ b/app/controller/admin/OnlineMediasController.php @@ -2,6 +2,8 @@ namespace app\controller\admin; use app\service\admin\OnlineMediasService; +use app\service\user\ApiService; +use app\service\admin\ApiService as AdminApiService; use support\Response; class OnlineMediasController @@ -13,4 +15,34 @@ class OnlineMediasController ]); return success($service->listData($params)); } + + /** + * 投稿 + */ + public function receive(ApiService $service) + { + $params = requestOnly([ + 'media_id' => '', + 'article_id' => '' + ]); + return success($service->receive($params)); + } + + /** + * 媒体圈上游资源批量变更通知到下游接⼝ + */ + public function update_batch_resource_url(AdminApiService $service) + { + $data = request()->post(); + return success($service->update_batch_resource_url($data)); + } + + /** + * 媒体圈上游稿件安排进度通知到下游接⼝ + */ + public function return_order_progress(AdminApiService $service) + { + $data = request()->post(); + return success($service->return_order_progress($data)); + } } \ No newline at end of file diff --git a/app/dao/user/CreationArticleReceiveRecordsDao.php b/app/dao/user/CreationArticleReceiveRecordsDao.php new file mode 100644 index 0000000..f90cd68 --- /dev/null +++ b/app/dao/user/CreationArticleReceiveRecordsDao.php @@ -0,0 +1,15 @@ +setParams(['perm' => ['contributionResource']]); //投稿 + Route::post('/receive', [OnlineMediasController::class, 'receive'])->setParams(['perm' => ['contributionReceive']]); }); //全局代理IP diff --git a/app/service/admin/ApiService.php b/app/service/admin/ApiService.php index 2e728de..b0d50d2 100644 --- a/app/service/admin/ApiService.php +++ b/app/service/admin/ApiService.php @@ -4,8 +4,8 @@ namespace app\service\admin; use app\dao\admin\OnlineMediasDao; use app\dao\admin\SelfMediasDao; +use app\dao\user\CreationArticleReceiveRecordsDao; use plugin\piadmin\app\base\BaseService; -use plugin\piadmin\app\exception\ApiException; use support\Db; use think\Exception; @@ -17,11 +17,13 @@ class ApiService extends BaseService protected $onlineMediasDao; protected $selfMediasDao; + protected $recordDao; public function __construct() { $this->onlineMediasDao = app()->make(OnlineMediasDao::class); $this->selfMediasDao = app()->make(SelfMediasDao::class); + $this->recordDao = app()->make(CreationArticleReceiveRecordsDao::class); } /** @@ -130,8 +132,8 @@ class ApiService extends BaseService } } $sum += sizeof($resourceData); - Db::beginTransaction(); - try { +// Db::beginTransaction(); +// try { //保存当前页码数据 if ($model_id == 1) { $this->onlineMediasDao->batchInsertOrUpdate($resourceData); @@ -140,11 +142,11 @@ class ApiService extends BaseService } else { throw new \Exception('未知资源类型'); } - Db::commit(); - } catch (Exception $exception) { +// Db::commit(); +// } catch (Exception $exception) { // Db::rollBack(); // throw new ApiException($exception->getMessage()); - } +// } // if (!empty($result['data']['next_url'])) { if ($sum < $total) { $page = $page + 1; @@ -159,4 +161,89 @@ class ApiService extends BaseService 't' => $result['t'] ]; } + + public function update_batch_resource_url($data) + { + //解密 + $response = json_decode(base64_decode($data['response'], true),true); + $iv = base64_decode($response['iv']); + $decrypted = \openssl_decrypt($response['value'], 'AES-256-CBC', $data ['app_key'], 0, + $iv); + $response = unserialize($decrypted); + //网媒 + if ($response['$model_id'] == 1) { + //封装数据 + $res = $this->onlineMediasDao->save([ + 'id' => $response['id'] ?? '', + 'model_id' => $response['model_id'] ?? '', + 'name' => $response['name'] ?? '', + 'price_assign' => $response['price_assign'] ?? '', + 'pindaoleixing' => $response['pindaoleixing'] ?? '', + 'zonghemenhu' => $response['zonghemenhu'] ?? '', + 'quyu' => $response['quyu'] ?? '', + 'meitianli' => $response['meitianli'] ?? '', + 'lianjieleixing' => $response['lianjieleixing'] ?? '', + 'shouluxiaoguo' => $response['shouluxiaoguo'] ?? '', + 'weekend_active' => $response['weekend_active'] ?? '', + 'meitiquanzhong' => $response['meitiquanzhong'] ?? '', + 'tebiehangye' => $response['tebiehangye'] ?? '', + 'jiegaoshijian' => $response['jiegaoshijian'] ?? '', + 'baikelaiyuan' => $response['baikelaiyuan'] ?? '', + 'wanshangkechu' => $response['wanshangkechu'] ?? '', + 'kedaishipin' => $response['kedaishipin'] ?? '', + 'jierikefa' => $response['jierikefa'] ?? '', + 'anlijietu' => $response['anlijietu'] ?? '', + 'no_disclaimer' => $response['no_disclaimer'] ?? '', + 'can_sign' => $response['can_sign'] ?? '', + 'wechat_open' => $response['wechat_open'] ?? '', + 'has_read_count' => $response['has_read_count'] ?? '', + 'avg_delivery_speed' => $response['avg_delivery_speed'] ?? '', + 'publish_rate' => $response['publish_rate'] ?? '', + 'ai_include' => $response['ai_include'] ?? '', + 'meitibeizhu' => $response['meitibeizhu'] ?? '', + 'status' => $response['status'] ?? '', + ]); + } else if ($response['$model_id'] == 2) { + //自媒体 + $res = $this->selfMediasDao->save([ + 'id' => $response['id'] ?? '', + 'model_id' => $response['model_id'] ?? '', + 'name' => $response['name'] ?? '', + 'price_assign' => $response['price_assign'] ?? '', + 'pingtai' => $response['pingtai'] ?? '', + 'hangyefenlei' => $response['hangyefenlei'] ?? '', + 'meitianli' => $response['meitianli'] ?? '', + 'cankaofensishu' => $response['cankaofensishu'] ?? '', + 'huangv' => $response['huangv'] ?? '', + 'meitihao' => $response['meitihao'] ?? '', + 'shipinleixing' => $response['shipinleixing'] ?? '', + 'wanshangkechu' => $response['wanshangkechu'] ?? '', + 'jierikefa' => $response['jierikefa'] ?? '', + 'avg_delivery_speed' => $response['avg_delivery_speed'] ?? '', + 'publish_rate' => $response['publish_rate'] ?? '', + 'meitibeizhu' => $response['meitibeizhu'] ?? '', + 'status' => $response['status'] ?? '', + ]); + } else { + throw new \Exception('未知资源类型'); + } + return $res; + } + + public function return_order_progress($data) + { + //解密 + $response = json_decode(base64_decode($data['response']), true); + $iv = base64_decode($response->iv); + $decrypted = \openssl_decrypt($response->value, 'AES-256-CBC', $data ['app_key'], 0, $iv); + $response = unserialize($decrypted); + + $res = $this->recordDao->update([ + 'model_id' => $response['model_id'], + 'id' => $response['customer_order_id'], + ], [ + 'status' => $response['order_progress'], + ]); + return $res; + } } \ No newline at end of file diff --git a/app/service/user/ApiService.php b/app/service/user/ApiService.php new file mode 100644 index 0000000..519bb3e --- /dev/null +++ b/app/service/user/ApiService.php @@ -0,0 +1,89 @@ +onlineMediasDao = app()->make(OnlineMediasDao::class); + $this->creationArticleDao = app()->make(CreationArticleDao::class); + $this->creationArticleReceiveRecordsDao = app()->make(CreationArticleReceiveRecordsDao::class); + } + + public function receive($params) + { + $article = $this->creationArticleDao->get($params['article_id']); + $media = $this->onlineMediasDao->get($params['media_id']); + $time_out = 60; + $url = $this->url; + //保存投稿记录 + $record = $this->creationArticleReceiveRecordsDao->save([ + 'model_id' => $media['model_id'], + 'article_id' => $article['id'], + 'title' => $article['title'], + 'content' => $article['content'], + 'price_assign' => $media['price_assign'] + ]); + if (!$record) { + throw new ApiException('投稿失败'); + } + //查文章,封装数据 + $prop = [ + 'biaoti' => $article['title'], + 'neirong' => $article['content'], + 'laiyuan' => '', + 'miaoshu' => '', + 'leixing' => 1 + ]; + //查媒体,封装数据 + $data = array ( + "model_id" => $media['model_id'], + "resource_id" => $media['id'], + "customer_order_id" => $record['id'], + "customer_batch_id" => $record['id'], + "out_model_id" => $media['model_id'], + "out_resource_id" => $media['id'], + "sale_id" => "0", + "sale_name" => "", + "prop"=> json_encode($prop, JSON_UNESCAPED_UNICODE) + ); + //加密 + $app_key = $this->appkey; + $data_info = serialize($data); + $iv = random_bytes(16); + $info['iv'] = base64_encode($iv); + $info['value'] = openssl_encrypt($data_info, 'AES-256-CBC', $app_key, 0, + base64_decode($info['iv'])); + $encrypt = base64_encode(json_encode($info)); + $sign = md5($encrypt); + $result = ['response' => $encrypt, 'sign' => $sign, 'app_key' => $app_key]; + //curl + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60); + curl_setopt($ch, CURLOPT_TIMEOUT, $time_out); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $result); + $output = curl_exec($ch); + curl_close($ch); + return json_decode($output, true); + } + +} \ No newline at end of file