示例#1
0
 public function mediaType($wechatId, $type)
 {
     switch ($type) {
         case 'news':
             $media = WechatNews::paginate(15);
             break;
     }
     return view('ucenter.public.media.type', compact('media'));
 }
示例#2
0
 public function reply($message)
 {
     /*
      * 监听事件类型
      * 关注事件回复
      * */
     //获取公众号信息
     $public_number = $message->ToUserName;
     $wechat = Wechat::where('wechat_account', '=', $public_number)->firstOrFail();
     //获取关键词对象
     $message->Content;
     //查询关键字,预载入关键字规则
     $keyword = Keyword::with(['keywordRule' => function ($query) use($wechat) {
         $query->where('wechat_id', '=', $wechat->id);
     }])->where('keyword', 'like', "{$message->Content}")->first();
     //查询对应回复   一对多
     $replies = $keyword->keywordRule->reply;
     //dd($replies);
     foreach ($replies as $key => $reply) {
         $contents[$key] = $reply->{$reply->reply_type};
         $contents[$key]['reply_type'] = $reply->reply_type;
     }
     //取随机数
     $num = mt_rand(0, count($replies));
     $content = $contents[$num];
     switch ($content['reply_type']) {
         case 'text':
         case 'image':
         case 'voice':
         case 'video':
         case 'location':
             return Message::make($content['reply_type'])->content($content->content);
             break;
         default:
             return Message::make($content['reply_type'])->content($content->content);
             break;
         case 'news':
             //查询内容
             $news = WechatNews::find($content->content);
             return Message::make('news')->items(function () use($news) {
                 return array(Message::make('news_item')->title($news->title)->url($news->news_url)->picUrl($news->cover));
             });
             breadk;
     }
 }
示例#3
0
 public function update(array $data, $id)
 {
     $news = WechatNews::find($id)->update($data);
     return $news;
 }
示例#4
0
 public function edit($wechatId, $id)
 {
     $news = WechatNews::find($id);
     $type = 'edit';
     return view('ucenter.public.media.create_edit_news', compact('type', 'news'));
 }