homepagePHP/app/Gy_Library/HomeController.class.php

77 lines
2.2 KiB
PHP
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Gy_Library;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
use EasyWeChat\Factory;
use Think\Log;
class HomeController extends GyController{
public function __construct()
{
parent::__construct();
$this->_link();
$this->_seoSearch();
//微信分享
$config = [
'app_id' => env('WX_APPID'),
'secret' => env('WX_APPSECRET'),
// 指定 API 调用返回结果的类型array(default)/collection/object/raw/自定义类名
'response_type' => 'array',
];
try {
if (is_weixin()) {
$app = Factory::officialAccount($config);
$signPackage = $app->jssdk->buildConfig([
'onMenuShareTimeline',
'onMenuShareAppMessage',
'onMenuShareQQ',
'onMenuShareQZone',
]);
}
}catch (\Exception $e) {
// show_bug($e->getMessage());
Log::write($e->getMessage());
}
// $this->share_img=HTTP_PROTOCOL.'://'.SITE_URL.'/'.asset('img/share_img.jpg');
$this->assign('signPackage', $signPackage);
}
private function _link()
{
$links = D('Links')->where(['status'=>DBCont::NORMAL_STATUS])->order('sort asc,id desc')->select();
if (!empty($links)) {
$this->links = $links;
}
}
private function _seoSearch()
{
if(CONTROLLER_NAME==='News'&&ACTION_NAME==='detail') {
$id = I('get.id');
$news = D('News')->where(['id' => $id])->find();
if (!empty($news)) {
foreach (explode(',',$news['keywords_id']) as &$item){
$words= D('Keywords')->where(['id'=>$item])->getField('name');
if(!empty($words))
$keywords_arr[]=$words;
}
$this->keywords_seo=!empty($keywords_arr) ? implode(',', $keywords_arr) : '';
$this->description=cutLength($news['content_res'],'50');
}
}
}
}