Le message de l'applet WeChat pousse la vérification du serveur PHP

PHPz
Libérer: 2017-04-04 11:42:56
original
2645 Les gens l'ont consulté

Page Paramètres (Paramètres>>Paramètres de développement) :


  1. Paramètres Nom de domaine du serveur
    Par exemple : https://hosts.com
    Notez la différence entre les protocoles http et https.

  2. Configurer le message push
    2.1 Ajouter le serveur interface test.php à votre serveur Le contenu de l'interface test.php est principalement de vérifier si le message. se fait via token. Envoyé depuis WeChat, le code fait référence à l'exemple officiel :
    define("TOKEN", "xxxxx");/ Le token renseigné en arrière-plan<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 = new
    wechatAPI();
    $wechatObj->isValid();
    class wechatAPI{
    public function isValid()//Vérifiez l'interface WeChat, si elle est confirmé comme étant WeChat, renvoyez le message qu'il a envoyéechoparamètre str{
    $echoStr = $_GET["echostr"];
    if
    ($this- >checkSignature()) {

    echo $ echoStr;
  3. exit;
}>fonction privée checkSignature() //Vérification officielleFonction{ $signature = $_GET["signature"]; $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; $token = JETON; $tmpArr = array($token, $timestamp, $ nonce); sort($tmpArr, SORT_STRING) ; $tmpStr = implode( $tmpArr ); $tmpStr = sha1( $tmpStr ); if( $tmpStr == $signature ){ return true; }Token : toute chaîne conforme à la spécification, telle comme "xxxxx" défini ci-dessus EncodingAESKey(Clé de cryptage du message) : (Générée aléatoirement, enregistrez-la vous-même, elle n'est utilisée que pour le cryptage et le déchiffrement) Méthode de cryptage du message : sélectionnez le texte en clair pour le moment, sans avoir à considérer les problèmes de chiffrement et de déchiffrement. Format des données : Choisissez en fonction de vos besoins. Envoyez, cela réussira s'il n'y a pas de problèmes. (S'il y a un problème, vous pouvez utiliser de fausses données pour réussir le test du navigateur)

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!