我們的業務是把大量客戶的微信公眾號 通過授權 給微信第三方開放平台的方式,通過第三方開放平台對客戶公眾號接口進行代操作。
其中的微信第三方開放平台在測試階段(未全網發布),能授權的公眾號只能是加入到白名單中的。所以托管大量的公眾號,必須要對其全網發布。
而全網發布的時候,微信方會進行模擬公眾號和粉絲微信號對你的第三方開放平台進行驗證:
laravel下面的部分驗證代碼如下:
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]])->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 }
微信的官方手冊:
網布發布驗證手冊
https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419318611&token=&lang=zh_CN
第四步:使用授權碼換取公眾號的接口調用憑據和授權信息
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