'wxe81efa7fd6a5fd53', 'secret' => '7d22f52938e4c9fbb5f2d07e8f5b83b6', 'token' => '6lfq90croi6nsyia63vbhaqnq4lzm66d', 'aes_key' => 'uOIvZHtyDKKd7xT4KKgpikGOtgW7ZskeOzVIFgIs2SM' ]; /** * Display a listing of the resource. * * @return Response */ public function index(Request $request) { $this->request = $request;; try { $openPlatform = Factory::openPlatform($this->config); // 第三方平台接入处理 $server = $openPlatform->server; return $server->serve(); // 处理授权成功事件 if (!empty($request["auth_code"])) { // $server->push(function ($event) use ($openPlatform) { // DB::table("test_content")->insert(array("test"=>json_encode($request["auth_code"]))); // //获取(刷新)授权公众号或小程序的接口调用凭据(令牌) // $res = $openPlatform->handleAuthorize($request["auth_code"]); // $appid2 = $res['authorization_info']['authorizer_appid']; // $refresh_token = $res['authorization_info']['authorizer_refresh_token']; // // //获取授权方的帐号基本信息 // $data = $openPlatform->getAuthorizer($appid2); // $account = WechatConfig::where('app_id', $appid2)->first(); // $info2 = $data['authorizer_info']; // $info1 = $data['authorization_info']; // if (is_null($account)) { // $account = WechatConfig::create([ // 'app_id' => $info1['authorizer_appid'], // 'refresh_token' => $refresh_token, // 'name' => $info2['nick_name'], // 'head_img' => $info2['head_img'], // 'original' => $info2['user_name'], // 'com_main_body' => $info2['principal_name'], // 'headimg' => $info2['qrcode_url'], //二维码 // 'status' => 1, // 'level' => $this->getLevel($info2), // 'type' => 1, //// 'token' => random(32), //// 'encodingaeskey' => random(43) // ]); // } else { // $account->refresh_token = $refresh_token; // $account->name = $info2['nick_name']; // $account->type = 3; // $account->original = $info2['user_name']; // $account->level = $this->getLevel($info2); // $account->head_img = $info2['head_img']; // $account->save(); // } // }, Guard::EVENT_AUTHORIZED); } // 处理授权更新事件 $server->push(function ($event) use ($openPlatform) { // DB::table("test_content")->insert(array("test"=>json_encode($event))); // // $vl=json_encode($event); // $event=json_decode($vl); }, Guard::EVENT_UPDATE_AUTHORIZED); // 处理授权取消事件 $server->push(function ($event) { // DB::table("test_content")->insert(array("test"=>json_encode($event))); // // $vl=json_encode($event); // $event=json_decode($vl); // $appid = $event->AuthorizerAppid; // $account = WechatConfig::where('appid', $appid)->first(); // if (!is_null($account)) { // $account->refresh_token = ''; // $account->save(); // } }, Guard::EVENT_UNAUTHORIZED); //VerifyTicket component_verify_ticket协议推送 $server->push(function ($event) use ($openPlatform) { // $vl=json_encode($event); // $event=json_decode($vl); // $appid = $event->AppId; // $ticket = $event->ComponentVerifyTicket; // //保存component_verify_ticket协议 // Redis::set($appid . '_component_verify_ticket', $ticket);//存储起来方便后续多台服务器并发调用 //// $wechatTicket = WechatTicket::where('appid', $appid)->orderBy('id')->first(); // $wechatTicket = DB::table("wechat_ticket")->where('appid', $appid)->orderBy('id')->first(); // if (empty($wechatTicket)) { // $wechatTicket = DB::table("wechat_ticket")->insert(array('appid'=>$appid,'ticket'=>$ticket // ,'create_time'=>time(),'update_time' =>time())); // } else { // DB::table("wechat_ticket")->where('appid', $appid)->update(array( // 'ticket' => $ticket, // 'update_time' => time() // )); //// $wechatTicket->ticket = $ticket; //// $wechatTicket->update_time = time(); //// $wechatTicket->save(); // } }, Guard::EVENT_COMPONENT_VERIFY_TICKET); return $server->serve(); } catch (\Exception $e) { if (env('APP_DEBUG')) { echo $e->getMessage(); } else { abort(404); } } } public function auth(Request $request) { try { $openPlatform = Factory::openPlatform($this->config); // 获取跳转的链接 $url = $openPlatform->getPreAuthorizationUrl('http://zyyd-api.qingerai.com/admin/openweixin/index'); // 获取跳转的链接 echo '点击第三方授权'; } catch (\Exception $e) { echo $e->getMessage(); $url = ''; } //return view('admin.auth.note', compact('url')); } public function callback(Request $request) { // echo \GuzzleHttp\json_encode($filter);exit; // return redirect()->to(site_path('account/wechat', 'admin'))->with('message', '第三方接入成功!'); return redirect()->to('http://zyyd-api.qingerai.com/admin/openweixin/index')->with('message', '第三方接入成功!'); } public function getThirdToken(Request $request) { $wechatTicket = SpecialistInfogbapp::first()['name']; echo \GuzzleHttp\json_encode($wechatTicket); // $openPlatform = Factory::openPlatform($this->config); // // 第三方平台接入处理 // $server = $openPlatform->getAuthorizer("wx382b6315fd4f1760"); // echo \GuzzleHttp\json_encode($server);exit; // return redirect()->to(site_path('account/wechat', 'admin'))->with('message', '第三方接入成功!'); } // 公众号分组 public function getLevel($info = array()) { $level = 0; if (!empty($info['MiniProgramInfo'])) { $level = 5; } else if ($info['service_type_info']['id'] == 0 || $info['service_type_info']['id'] == 1) { //订阅号 if ($info['verify_type_info']['id'] >= 0) { //已认证 $level = 3; } else { $level = 1; } } else if ($info['service_type_info']['id'] == 2) { //服务号 if ($info['verify_type_info']['id'] >= 0) { //已认证 $level = 4; } else { $level = 2; } } return $level; } }