Browse Source

feat(admin): 新增媒体圈资源变更与稿件进度通知接口

- 添加无需登录的资源批量变更通知接口
- 添加无需登录的稿件安排进度通知接口
- 实现资源变更数据解密与存储逻辑
- 实现稿件进度更新逻辑
- 新增投稿记录模型及DAO层
- 添加投稿接口服务实现
- 注册相关路由并配置权限控制
master
zhangf@suq.cn 5 hours ago
parent
commit
66b130998f
  1. 1
      app/controller/admin/ApiController.php
  2. 32
      app/controller/admin/OnlineMediasController.php
  3. 15
      app/dao/user/CreationArticleReceiveRecordsDao.php
  4. 33
      app/model/user/CreationArticleReceiveRecords.php
  5. 9
      app/route/admin.php
  6. 1
      app/route/route.php
  7. 99
      app/service/admin/ApiService.php
  8. 89
      app/service/user/ApiService.php

1
app/controller/admin/ApiController.php

@ -6,6 +6,7 @@ use support\Response;
/** /**
* 调用媒体圈接口控制器 * 调用媒体圈接口控制器
* 初始化使用一次,后续为上游推送
*/ */
class ApiController class ApiController
{ {

32
app/controller/admin/OnlineMediasController.php

@ -2,6 +2,8 @@
namespace app\controller\admin; namespace app\controller\admin;
use app\service\admin\OnlineMediasService; use app\service\admin\OnlineMediasService;
use app\service\user\ApiService;
use app\service\admin\ApiService as AdminApiService;
use support\Response; use support\Response;
class OnlineMediasController class OnlineMediasController
@ -13,4 +15,34 @@ class OnlineMediasController
]); ]);
return success($service->listData($params)); 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));
}
} }

15
app/dao/user/CreationArticleReceiveRecordsDao.php

@ -0,0 +1,15 @@
<?php
namespace app\dao\user;
use app\model\user\CreationArticleReceiveRecords;
use plugin\piadmin\app\base\UserBaseDao;
class CreationArticleReceiveRecordsDao extends UserBaseDao
{
protected function setModel(): string
{
return CreationArticleReceiveRecords::class;
}
}

33
app/model/user/CreationArticleReceiveRecords.php

@ -0,0 +1,33 @@
<?php
namespace app\model\user;
use plugin\piadmin\app\base\BaseModel;
/**
* 投稿记录模型
*/
class CreationArticleReceiveRecords extends BaseModel
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'geo_creation_article_receive_records';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = true;
}

9
app/route/admin.php

@ -10,6 +10,15 @@ use Webman\Route;
/** /**
* 运营端后台定制路由 * 运营端后台定制路由
*/ */
//无需登录
Route::group('/service/v1', function () {
//媒体圈上游资源批量变更通知到下游接⼝
Route::post('/update_batch_resource_url', [OnlineMediasController::class, 'update_batch_resource_url']);
//媒体圈上游稿件安排进度通知到下游接⼝
Route::post('/return_order_progress', [OnlineMediasController::class, 'return_order_progress']);
});
//需要登录
Route::group('/service/v1', function () { Route::group('/service/v1', function () {
//媒介圈 //媒介圈
Route::group('/meijiequan', function () { Route::group('/meijiequan', function () {

1
app/route/route.php

@ -186,6 +186,7 @@ Route::group('/service/v1', function () {
//媒体资源 //媒体资源
Route::post('/resource', [OnlineMediasController::class, 'index'])->setParams(['perm' => ['contributionResource']]); Route::post('/resource', [OnlineMediasController::class, 'index'])->setParams(['perm' => ['contributionResource']]);
//投稿 //投稿
Route::post('/receive', [OnlineMediasController::class, 'receive'])->setParams(['perm' => ['contributionReceive']]);
}); });
//全局代理IP //全局代理IP

99
app/service/admin/ApiService.php

@ -4,8 +4,8 @@ namespace app\service\admin;
use app\dao\admin\OnlineMediasDao; use app\dao\admin\OnlineMediasDao;
use app\dao\admin\SelfMediasDao; use app\dao\admin\SelfMediasDao;
use app\dao\user\CreationArticleReceiveRecordsDao;
use plugin\piadmin\app\base\BaseService; use plugin\piadmin\app\base\BaseService;
use plugin\piadmin\app\exception\ApiException;
use support\Db; use support\Db;
use think\Exception; use think\Exception;
@ -17,11 +17,13 @@ class ApiService extends BaseService
protected $onlineMediasDao; protected $onlineMediasDao;
protected $selfMediasDao; protected $selfMediasDao;
protected $recordDao;
public function __construct() public function __construct()
{ {
$this->onlineMediasDao = app()->make(OnlineMediasDao::class); $this->onlineMediasDao = app()->make(OnlineMediasDao::class);
$this->selfMediasDao = app()->make(SelfMediasDao::class); $this->selfMediasDao = app()->make(SelfMediasDao::class);
$this->recordDao = app()->make(CreationArticleReceiveRecordsDao::class);
} }
/** /**
@ -130,8 +132,8 @@ class ApiService extends BaseService
} }
} }
$sum += sizeof($resourceData); $sum += sizeof($resourceData);
Db::beginTransaction();
try {
// Db::beginTransaction();
// try {
//保存当前页码数据 //保存当前页码数据
if ($model_id == 1) { if ($model_id == 1) {
$this->onlineMediasDao->batchInsertOrUpdate($resourceData); $this->onlineMediasDao->batchInsertOrUpdate($resourceData);
@ -140,11 +142,11 @@ class ApiService extends BaseService
} else { } else {
throw new \Exception('未知资源类型'); throw new \Exception('未知资源类型');
} }
Db::commit();
} catch (Exception $exception) {
// Db::commit();
// } catch (Exception $exception) {
// Db::rollBack(); // Db::rollBack();
// throw new ApiException($exception->getMessage()); // throw new ApiException($exception->getMessage());
}
// }
// if (!empty($result['data']['next_url'])) { // if (!empty($result['data']['next_url'])) {
if ($sum < $total) { if ($sum < $total) {
$page = $page + 1; $page = $page + 1;
@ -159,4 +161,89 @@ class ApiService extends BaseService
't' => $result['t'] '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;
}
} }

89
app/service/user/ApiService.php

@ -0,0 +1,89 @@
<?php
namespace app\service\user;
use app\dao\admin\OnlineMediasDao;
use app\dao\user\CreationArticleDao;
use app\dao\user\CreationArticleReceiveRecordsDao;
use plugin\piadmin\app\base\BaseService;
use plugin\piadmin\app\exception\ApiException;
class ApiService extends BaseService
{
//投稿接口
protected $url = "http://www.meijiequan.cn/api/companyOrder/receive";
protected $appkey = 'de06270f3515bad109aa1fd2c023dd41';
protected $onlineMediasDao;
protected $creationArticleDao;
protected $creationArticleReceiveRecordsDao;
public function __construct()
{
$this->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);
}
}
Loading…
Cancel
Save