Blogger Information
Blog 55
fans 0
comment 0
visits 30404
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
5月31日作业
老专的博客
Original
833 people have browsed it

5月31日作业

获得 signature 步骤:

安装 ngrok 登录下列网站:

https://github.com/getlantern/forum

https://dashboard.ngrok.com/user/signup

https://github.com/

获取 :Authtoken:2t9hNumjcR0n4LyYGAZRp_2c4AEHfEQGk629zugcGU3

wid 视窗安装:D:\PHPTOOL\myphp_www\PHPTutorial\WWW\www.php.wx>ngrok authtoken 2t9hNumjcR0n4LyYGAZRp_2c4AEHfEQGk629zugcGU3

安装成功:Authtoken saved to configuration file: C:\Users\Administrator/.ngrok2/ngrok.yml

输入:D:\PHPTOOL\myphp_www\PHPTutorial\WWW\www.php.wx>ngrok http 80 回车

结果:

    ngrok by @inconshreveable                                                                                 

    Session Status                online

    Account                       zouhaifu (Plan: Free)

    Version                       2.2.8

    Region                        United States (us)

    Web Interface       http://127.0.0.1:4040

    Forwarding           http://65869e5e.ngrok.io -> localhost:80

    Forwarding           https://65869e5e.ngrok.io -> localhost:80


    Connections        ttl     opn     rt1     rt5     p50     p90

                        0       0       0.00    0.00    0.00    0.00

                 

打开微信公众平台 -> 开发 -> 基本配置

服务器地址(URL)

http://65869e5e.ngrok.io/index.php/index/weixin/index

服务器地址(URL)

http://65869e5e.ngrok.io/index.php/index/weixin/index

消息加解密方式 : 明文模式 

打开微信公众平台 -> 开发 -> 开发工具-> 公众平台测试号

测试系列程序:

URL:www.php.wx/index.php/index/weixin/index

实例

<?php
namespace app\index\controller;
use think\Controller;
use think\facade\Cache;

class Weixin extends Controller
{
    //微信推送事件
    public function index()
    {
       
        //校验本地服务器和微信接口密匙(演示时放在控制器里,案例时放在 model 里)
        $signature = input('get.signature');
        //$signature = '3fcd6b042919271ce5556a47e1e499c983681604';
        $timestamp = input('get.timestamp');
        //$timestamp='1527910882';
        $nonce = input('get.nonce');
        //$nonce='2989593598';
        $echostr = input('get.echostr');
        //$echostr='10274049140752292859';
        //$token = 'cairc';//在 config /app.php 设置 如下
        $token = config('app.weixintoken');
       
        //本地测试数据接收
        file_put_contents('D://data.txt', 'signature='.$signature.' timemstamp='.$timestamp.' nonce='.$nonce.' echostr='.$echostr);
       halt();
       
        $tmpArr = array($timestamp, $nonce, $token); //获取数据
        sort($tmpArr, SORT_STRING); //转换为字符串
        //halt($tmpArr);
            //array(3) {
                //[0] => string(10) "1527910882"
                //[1] => string(10) "2989593598"
                //[2] => string(5) "cairc"
            //}
        //$str = implode('===', $tmpArr);
        //echo $str;
        $str = implode($tmpArr);//拼接字符串
        $sign = sha1($str); //字符串 sha1 加密
        //echo $sing; //结果:3fcd6b042919271ce5556a47e1e499c983681604
        if($sign != $signature){
            exit('signature error');
        }
        exit($echostr);
        //exit();
    }
 
    public function demo1()
    {
        echo '微信连接测试';
    }
   
}

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post