微信第三方開放平臺全網發佈驗證

咱們的業務是把大量客戶的微信公衆號 經過受權 給微信第三方開放平臺的方式,經過第三方開放平臺對客戶公衆號接口進行代操做。html

其中的微信第三方開放平臺在測試階段(未全網發佈),能受權的公衆號只能是加入到白名單中的。因此託管大量的公衆號,必需要對其全網發佈。laravel

 

而全網發佈的時候,微信方會進行模擬公衆號和粉絲微信號對你的第三方開放平臺進行驗證:json

laravel下面的部分驗證代碼以下:api

 1      if($app_id == 'wx570bc396a51b8ff8'){
 2             if($MsgType == 'text'){//普通文本驗證
 3                 $repType = "text";
 4                 $content = $this->getRecMsg_Content();
 5                 if($content == 'TESTCOMPONENT_MSG_TYPE_TEXT'){
 6                     $repCont = 'TESTCOMPONENT_MSG_TYPE_TEXT_callback';
 7                 }else{//API驗證
 8                     $repCont =  explode(":",$content)[1];//接受微信放發來的query_auth_code
 9                     $msgcontent = ["content"=>$repCont.'_from_api'];
10                      //獲取access_token
11                     $Client = new Client(['base_uri' => 'https://api.weixin.qq.com/cgi-bin/component/api_query_auth']);
12                     $client_result = $Client->post('?component_access_token=此時有效的第三方開放平臺access_token',['json' => ['component_appid'=>'你的component_appid', 'authorization_code'=>$repCont], "proxy" => "若有須要填寫代理ip"])->getBody();
13                     $access_token = json_decode($client_result,true)['authorization_info']['authorizer_access_token'];
14                     //發客服消息
15                     App::make('weixin.cp')->setAuthorizerToken($access_token)->sendKeFuMsg($this->getFromUserName(),'text',$msgcontent);
16                     $repCont = $repCont.'_from_api';
17                 }
18             }elseif($MsgType == 'event'){//事件驗證
19                 $repType = "text";
20                 $repCont = $MsgEvent."from_callback";
21             }

         //返回給微信xml
22 $weixin_mp = App::make('weixin.mp'); 23 $weixin_mp->on($repType, function() use($repType,$repCont) { 24 return App::make('weixin.mp')->makeMessage($repType ,$repCont); 25 }); 26 $response = $weixin_mp->trigger($repType); 27 return $response; 28 }

 

開始檢測,好緊張:微信

 

而後結果是:app

成功!!!post

 

 

 

 

微信的官方手冊:測試

網布發佈驗證手冊this

https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419318611&token=&lang=zh_CNspa

第四步:使用受權碼換取公衆號的接口調用憑據和受權信息

https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1453779503&token=&lang=zh_CN

發客服消息:

http://mp.weixin.qq.com/wiki/11/c88c270ae8935291626538f9c64bd123.html

相關文章
相關標籤/搜索