Ejemplo n.º 1
0
 public function update(array $data, $id)
 {
     $wechat = Wechat::find($id);
     $wechat->public_name = $data['public_name'];
     $wechat->original_id = $data['original_id'];
     $wechat->wechat_account = $data['wechat_account'];
     $wechat->avatar = $data['avatar'];
     $wechat->app_id = $data['app_id'];
     $wechat->secret = $data['secret'];
     $wechat->encoding_aes_key = $data['encoding_aes_key'];
     $wechat->wechat_token = $data['wechat_token'];
     $wechat->save();
     return $wechat;
 }
Ejemplo n.º 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;
     }
 }
Ejemplo n.º 3
0
 public function index()
 {
     $wechats = Wechat::paginate(15);
     return view('ucenter.index', compact('wechats'));
 }
Ejemplo n.º 4
0
 public function edit($wechatId)
 {
     $wechat = Wechat::find($wechatId);
     return view('ucenter.public.edit', compact('wechat'));
 }
Ejemplo n.º 5
0
 public function edit($id)
 {
     $wechat = Wechat::find($id);
     return view('admin.public.edit', compact('wechat'));
 }