微信第三方开放平台全网发布验证

咱们的业务是把大量客户的微信公众号 经过受权 给微信第三方开放平台的方式,经过第三方开放平台对客户公众号接口进行代操做。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

相关文章
相关标签/搜索