当前位置:首页 > PHP > 正文内容

达摩-营销素材自动上传接口备份代码

高老师2个月前 (02-24)PHP194

上传图片代码:

ActionScript
/**
 * uploadImage
 * @param $imagePath
 * @return mixed
 * @throws BusinessException
 */
public function uploadImage($imagePath)
{
    echo '正在上传图片' . $imagePath . PHP_EOL;
    $this->checkCookie();
    $baseInfo = pathinfo($imagePath);
    $url = 'https://hope.demogic.com/api-marketing/content/upload-image?wxFlag=1&requestProject=marketing';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    $headers = array(
        'Accept: application/json, text/plain, */*',
        'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8',
        'Connection: keep-alive',
        'Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryjIc86qFLxj5NjvGi',
        'Cookie: ' . $this->cookie,
        'Origin: https://hope.demogic.com',
        'Referer: https://hope.demogic.com/content-center/',
        'Sec-Fetch-Dest: empty',
        'Sec-Fetch-Mode: cors',
        'Sec-Fetch-Site: same-origin',
        'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
        'channelEntrance: merchant_backstage',
        'sec-ch-ua: "Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
        'sec-ch-ua-mobile: ?0',
        'sec-ch-ua-platform: "Windows"'
    );
    $data = array(
        'file' => new CURLFile($imagePath, 'image/jpeg', $baseInfo['basename']),
        'uuid' => '7a763df7-5723-451e-b672-caa7ba7c057e'
    );
    $response = curl($url, $data, false, $headers, 3, 1);
    if (!$response) {
        throw new BusinessException('请求达摩上传文件接口失败');
    }
    $responseData = json_decode($response, true);
    if (!$responseData) {
        throw new BusinessException('转换达摩上传文件接口数据失败');
    }
    $this->checkLogin($responseData);
    return $responseData;
}

发布素材接口:

ActionScript
/**
 * 发布素材
 * @return array
 */
public function saveMaterial($materialTitle, $materialImageSource, $contentGoodsIdList, $thirdGoodsList, $contentCategoryId, $producerId)
{
    $this->checkCookie();

    // 提取全部图片
    $materialImageUrls = array_column($materialImageSource, 'url');

    // 提取全部图片配置
    $materialImageInfos = [];
    foreach ($materialImageSource as $value) {
        unset($value['url']);
        $materialImageInfos[] = json_encode($value, 256);
    }
    $materialImageInfosText = join('|', $materialImageInfos);

    // 请求地址
    $url = 'https://hope.demogic.com/api-marketing/content/save-material?requestProject=marketing';
    $data = array(
        'pageId' => '',
        'shareLinkFlag' => 1,
        'materialSubTitle' => '',
        'materialLink' => '',
        'materialFirstImageUrl' => '',
        'additionalList' => array(),
        'materialPurpose' => 1,
        'contentMaterialId' => '',
        'materialTitle' => $materialTitle, //标题
        'materialType' => 3,
        'shelfStatus' => 1,
        'publishType' => 1,  // 0.暂不发布 1.发布
        'publishBeginTime' => '',
        'publishEndTime' => '',
        'materialContent' => '',
        'materialImageUrls' => join(',', $materialImageUrls), // 图片地址逗号隔开
        'materialThumbnailImageUrls' => join(',', $materialImageUrls), // 图片地址逗号隔开,
        'materialVideoUrl' => '',
        'materialVideoImageUrl' => '',
        'materialVideoFirstImageUrl' => '',
        'ruleId' => '',
        'contentTagIdList' =>
            array(
                0 => '509419425271668780', //标签-固定为其他内容
            ),
        'contentColumnIdList' =>
            array(),
        'contentCategoryId' => $contentCategoryId, //分类编号
        'contentGoodsIdList' => $contentGoodsIdList, //关联商品编号
        'duration' => '',
        'producerId' => $producerId, //发布人编号
        'materialImageInfos' => $materialImageInfosText,
        'materialVideoInfo' => '',
        'materialVideoImageInfo' => '',
        'materialVideoFirstImageInfo' => '',
        'materialFirstImageInfo' => '',
        'producer' => NULL,
        'thirdGoodsList' => $thirdGoodsList
    );

    $headers = array();
    $headers[] = 'Accept: application/json, text/plain, */*';
    $headers[] = 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8';
    $headers[] = 'Connection: keep-alive';
    $headers[] = 'Content-Type: application/json;charset=UTF-8';
    $headers[] = 'Cookie:' . $this->cookie;
    $headers[] = 'Origin: https://hope.demogic.com';
    $headers[] = 'Referer: https://hope.demogic.com/content-center/';
    $headers[] = 'Sec-Fetch-Dest: empty';
    $headers[] = 'Sec-Fetch-Mode: cors';
    $headers[] = 'Sec-Fetch-Site: same-origin';
    $headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36';
    $headers[] = 'channelEntrance: merchant_backstage';
    $headers[] = 'sec-ch-ua: "Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"';
    $headers[] = 'sec-ch-ua-mobile: ?0';
    $headers[] = 'sec-ch-ua-platform: "Windows"';
    $response = curl($url, json_encode($data), false, $headers, 1, 0);
    if (!$response) {
        throw new BusinessException('请求达摩发布素材接口失败,接口未响应数据');
    }
    $responseData = json_decode($response, true);
    if (!$responseData) {
        throw new BusinessException('请求达摩发布素材接口失败,接口返回非Json数据');
    }
    $this->checkLogin($responseData);
    return $responseData;
}

扫描二维码推送至手机访问。

版权声明:本文由高久峰个人博客发布,如需转载请注明出处。

本文链接:https://blog.20230611.cn/post/878.html

“达摩-营销素材自动上传接口备份代码” 的相关文章

抛弃salt,使用password_hash()加密

抛弃salt,使用password_hash()加密

md5/sha1+salt方式是目前各大cms常用的加密方式,虽然salt安全,但是各大md5网站也在研究这个方向,那么我们应该选择password_hash动态hash来助力,一种密码有多种hash结果.看代码模拟登陆.<?php //01.注册 $user ='zhang...

redis订阅和发布,redis消息订阅与发布, phpredis订阅和发布

redis订阅和发布,redis消息订阅与发布, phpredis订阅和发布

Redis提供了发布订阅功能,可以用于消息的传输,Redis的发布订阅机制包括三个部分,发布者(publisher),订阅者(subscriber)和频道(channel)。 发布者和订阅者都是Redis客户端,Channel则为Redis服务器端,发布者将消息发送到某个的频道,订阅了这个...

php redis事务

php redis事务

概念请参考w3school文章: redis watch ,redis exec (看完基本秒懂)(1)基本事务://连接本地的 Redis 服务 $redis = new Redis(); $redis->con...

php位运算符详解

php位运算符详解

文章篇幅较长,如果不喜欢看文章的,此处抛出韩顺丰老师的位运算视频,韩老师应该是全网讲php位运算符最详细的一个老师了。链接:https://pan.baidu.com/s/14xj7er8eVSUcJ-jYXyA0GA  提取码:731m 链接:https://pan.baidu.com...

php中0和字符串比较时注意的问题

php中0和字符串比较时注意的问题

在正式介绍前先抛出一段代码:<?php //输入的密码 $password = empty($_POST['password']) ? 0 : $_POST['password']; //设置的密码...

thinkphp5整合workerman,tp5整合workerman

thinkphp5整合workerman,tp5整合workerman

由于workerman底层直接读取$_SERVER['argv']的命令行参数,没有提供独立的方法start/stop,而tp的命令行参数无法适配workerman,虽然thinkphp官方专门做了一个适配的版本,但是看了下评论问题挺多的。于是自己来搞一个.(1).在applicat...