You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.4 KiB

<?php
namespace app\base\model\wechat;
use app\base\model\Base;
use think\model\concern\SoftDelete;
class WechatNews extends Base
{
use SoftDelete;
// 设置当前模型对应的完整数据表名称
protected $table = 'base_wechat_news';
protected $type = [
'content' => 'serialize',
'platform_news_content' => 'serialize',
];
/**
* 获取器-添加类型文本
* @date 2020-10-20
*/
public function getTypeTextAttr($value, $data)
{
$text = [
1 => '后台添加',
2 => '平台更新',
];
return $text[$data['type']];
}
/**
* 获取单条图文并且转换成微信识别的格式
* @param array $news_id 图文消息ID
* @param array $wechat_type 1--订阅号 2--服务号 3--小程序
* @param string $openid 用户OPENID
* @date 2020-07-28
*/
public function getNews($news_id, $wechat_type = 2, $openid = '')
{
$wechat_news = $this->getOneData(['id' => $news_id]);
if (!empty($wechat_news['content'])) {
foreach ($wechat_news->getAttr('content') as $k => &$v) {
$v['image'] = urlToAbsolute($v['image']);
if ($wechat_type == 1 && strpos($v['url'], '/openid/')) { //订阅号必须通过图文消息获取OPENID
$v['url'] = $v['url'] . $openid;
}
}
}
return $wechat_news['content'];
}
}