저희 사업은 다수의 고객의 WeChat 공개 계정을 WeChat 제3자 오픈 플랫폼에 승인하고, 제3자 오픈 플랫폼을 통해 고객 공개 계정 인터페이스를 운영하는 것입니다.
WeChat 제3자 개방형 플랫폼은 테스트 단계에 있으며(아직 전체 네트워크에 출시되지 않음) 승인된 공개 계정만 화이트리스트에 추가할 수 있습니다. 따라서 다수의 공개 계정을 호스팅하는 것은 전체 네트워크에 게시되어야 합니다.
전체 네트워크에 게시할 때 WeChat은 공개 계정과 팬 WeChat ID를 시뮬레이션하여 제3자 개방형 플랫폼을 확인합니다.
laravel 아래 인증코드 일부는 다음과 같습니다.
<span style="color: #008080;"> 1 </span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$app_id</span> == 'wx570bc396a51b8ff8'<span style="color: #000000;">){ </span><span style="color: #008080;"> 2</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$MsgType</span> == 'text'){<span style="color: #008000;">//</span><span style="color: #008000;">普通文本验证</span> <span style="color: #008080;"> 3</span> <span style="color: #800080;">$repType</span> = "text"<span style="color: #000000;">; </span><span style="color: #008080;"> 4</span> <span style="color: #800080;">$content</span> = <span style="color: #800080;">$this</span>-><span style="color: #000000;">getRecMsg_Content(); </span><span style="color: #008080;"> 5</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$content</span> == 'TESTCOMPONENT_MSG_TYPE_TEXT'<span style="color: #000000;">){ </span><span style="color: #008080;"> 6</span> <span style="color: #800080;">$repCont</span> = 'TESTCOMPONENT_MSG_TYPE_TEXT_callback'<span style="color: #000000;">; </span><span style="color: #008080;"> 7</span> }<span style="color: #0000ff;">else</span>{<span style="color: #008000;">//</span><span style="color: #008000;">API验证</span> <span style="color: #008080;"> 8</span> <span style="color: #800080;">$repCont</span> = <span style="color: #008080;">explode</span>(":",<span style="color: #800080;">$content</span>)[1];<span style="color: #008000;">//</span><span style="color: #008000;">接受微信放发来的query_auth_code</span> <span style="color: #008080;"> 9</span> <span style="color: #800080;">$msgcontent</span> = ["content"=><span style="color: #800080;">$repCont</span>.'_from_api'<span style="color: #000000;">]; </span><span style="color: #008080;">10</span> <span style="color: #008000;">//</span><span style="color: #008000;">获取access_token</span> <span style="color: #008080;">11</span> <span style="color: #800080;">$Client</span> = <span style="color: #0000ff;">new</span> Client(['base_uri' => 'https://api.weixin.qq.com/cgi-bin/component/api_query_auth'<span style="color: #000000;">]); </span><span style="color: #008080;">12</span> <span style="color: #800080;">$client_result</span> = <span style="color: #800080;">$Client</span>->post('?component_access_token=此时有效的第三方开放平台access_token',['json' => ['component_appid'=>'你的component_appid', 'authorization_code'=><span style="color: #800080;">$repCont</span>]])-><span style="color: #000000;">getBody(); </span><span style="color: #008080;">13</span> <span style="color: #800080;">$access_token</span> = json_decode(<span style="color: #800080;">$client_result</span>,<span style="color: #0000ff;">true</span>)['authorization_info']['authorizer_access_token'<span style="color: #000000;">]; </span><span style="color: #008080;">14</span> <span style="color: #008000;">//</span><span style="color: #008000;">发客服消息</span> <span style="color: #008080;">15</span> App::make('weixin.cp')->setAuthorizerToken(<span style="color: #800080;">$access_token</span>)->sendKeFuMsg(<span style="color: #800080;">$this</span>->getFromUserName(),'text',<span style="color: #800080;">$msgcontent</span><span style="color: #000000;">); </span><span style="color: #008080;">16</span> <span style="color: #800080;">$repCont</span> = <span style="color: #800080;">$repCont</span>.'_from_api'<span style="color: #000000;">; </span><span style="color: #008080;">17</span> <span style="color: #000000;"> } </span><span style="color: #008080;">18</span> }<span style="color: #0000ff;">elseif</span>(<span style="color: #800080;">$MsgType</span> == 'event'){<span style="color: #008000;">//事件</span><span style="color: #008000;">验证</span> <span style="color: #008080;">19</span> <span style="color: #800080;">$repType</span> = "text"<span style="color: #000000;">; </span><span style="color: #008080;">20</span> <span style="color: #800080;">$repCont</span> = <span style="color: #800080;">$MsgEvent</span>."from_callback"<span style="color: #000000;">; </span><span style="color: #008080;">21</span> <span style="color: #000000;"> }<br><br> //返回给微信xml </span><span style="color: #008080;">22</span> <span style="color: #800080;">$weixin_mp</span> = App::make('weixin.mp'<span style="color: #000000;">); </span><span style="color: #008080;">23</span> <span style="color: #800080;">$weixin_mp</span>->on(<span style="color: #800080;">$repType</span>, <span style="color: #0000ff;">function</span>() <span style="color: #0000ff;">use</span>(<span style="color: #800080;">$repType</span>,<span style="color: #800080;">$repCont</span><span style="color: #000000;">) { </span><span style="color: #008080;">24</span> <span style="color: #0000ff;">return</span> App::make('weixin.mp')->makeMessage(<span style="color: #800080;">$repType</span> ,<span style="color: #800080;">$repCont</span><span style="color: #000000;">); </span><span style="color: #008080;">25</span> <span style="color: #000000;"> }); </span><span style="color: #008080;">26</span> <span style="color: #800080;">$response</span> = <span style="color: #800080;">$weixin_mp</span>->trigger(<span style="color: #800080;">$repType</span><span style="color: #000000;">); </span><span style="color: #008080;">27</span> <span style="color: #0000ff;">return</span> <span style="color: #800080;">$response</span><span style="color: #000000;">; </span><span style="color: #008080;">28</span> }
테스트 시작, 너무 긴장됨:
그 결과는 다음과 같습니다.
성공! ! !
WeChat 공식 매뉴얼:
웹 퍼블리싱 검증 매뉴얼
https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419318611&token=&lang=zh_CN
4단계: 인증 코드를 사용하여 공식 계정의 인터페이스 통화 자격 증명 및 인증 정보를 교환합니다
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