WeChat 애플릿 메시지 푸시 PHP 서버 확인

PHPz
풀어 주다: 2017-04-04 11:42:56
원래의
2645명이 탐색했습니다.

설정 페이지(설정>>개발 설정):


  1. 설정 서버 도메인 이름
    예: https://hosts.com
    http 프로토콜과 https 프로토콜의 차이점에 유의하세요.

  2. 메시지 푸시 설정
    2.1 서버 인터페이스 test.php를 서버에 추가합니다. test.php 인터페이스의 내용은 주로 메시지 여부를 확인하는 것입니다. 토큰을 통해 전송되며, 코드는 공식 예를 참조합니다:
    define("TOKEN", "xxxxx");/ 백그라운드에 채워진 토큰<code>define("TOKEN","xxxxx");/ 后台填写的token<br>$wechatObj = <a href="http://www.php.cn/wiki/165.html" target="_blank">new</a> wechatAPI();<br>$wechatObj->isValid();<br><a href="http://www.php.cn/wiki/164.html" target="_blank">class</a> wechatAPI<br>{<br>public function isValid()//验证微信接口,如果确认是微信就返回它传来的<a href="http://www.php.cn/wiki/1343.html" target="_blank">echo</a>str参数<br>{<br> $echoStr = $_GET["echostr"];<br> <a href="http://www.php.cn/wiki/109.html" target="_blank">if</a> ($this->checkSignature()) {<br>   echo $echoStr;<br>   exit;<br> }<br>}<br>private function checkSignature()   //官方的验证<a href="http://www.php.cn/wiki/145.html" target="_blank">函数</a><br>{<br> $signature = $_GET["signature"];<br> $<a href="http://www.php.cn/wiki/1268.html" target="_blank">time</a>stamp = $_GET["timestamp"];<br> $nonce = $_GET["nonce"];<br> $token = TOKEN;<br> $tmpArr = <a href="http://www.php.cn/wiki/58.html" target="_blank">array</a>($token, $timestamp, $nonce);<br> <a href="http://www.php.cn/wiki/1087.html" target="_blank">sort</a>($tmpArr, SORT_<a href="http://www.php.cn/wiki/57.html" target="_blank">STRING</a>);<br> $tmpStr = <a href="http://www.php.cn/wiki/1336.html" target="_blank">implode</a>( $tmpArr );<br> $tmpStr = <a href="http://www.php.cn/wiki/1366.html" target="_blank">sha1</a>( $tmpStr );<br> if( $tmpStr == $signature ){<br>   <a href="http://www.php.cn/wiki/135.html" target="_blank">return</a> true;<br> }<a href="http://www.php.cn/wiki/111.html" target="_blank">else</a>{<br>   return false;<br> }<br>}<br>};$wechatObj = 새로운
    wechatAPI();
    $wechatObj->isValid();
    class wechatAPI{
    public function isValid()//WeChat 인터페이스를 확인하세요. WeChat인 것으로 확인되면 보낸 메시지를 반환합니다.echostr 매개변수{
    $echoStr = $_GET["echostr"]
    if
    ($this- >checkSignature()) {

    echo $ echoStr;
  3. exit;
}}비공개 함수 checkSignature() //공식 확인함수{ $signature = $_GET["signature"]; $시간stamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; $token = 토큰; $tmpArr = 배열($token, $timestamp, $ nonce); 정렬($tmpArr, SORT_STRING) ; $tmpStr = 내파( $tmpArr ); $tmpStr = sha1( $tmpStr ); if( $tmpStr == $signature ){ return true; }토큰: 사양을 준수하는 모든 문자열 위에서 정의한 "xxxxx"로 EncodingAES키(메시지 암호화 키): (무작위로 생성되므로 직접 저장하세요. 암호화 및 복호화에만 사용됩니다.) 메시지 암호화 방법: 일반 텍스트 선택 당분간은 암호화 및 복호화 문제를 고려할 필요가 없습니다. 데이터 형식: 필요에 따라 선택하세요. 제출, 문제가 없으면 성공입니다. (문제가 있는 경우 가짜 데이터를 사용하여 브라우저 테스트를 통과할 수 있습니다)

위 내용은 WeChat 애플릿 메시지 푸시 PHP 서버 확인의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!