我设置的前提条件:

已购买阿里云服务器,开通了80端口,且网站已备案。

1、在网站文件中新建index.php文件。该文件内容如下:

把 define("TOKEN", "weixin"); 中的weixin,改成自定义字符串,比如 mytoken

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
  * wechat php test
  */
//define your token
define("TOKEN", "weixin");
$wechatObj = new wechatCallbackapiTest();
$wechatObj->valid();
class wechatCallbackapiTest
{
public function valid()
    {
        $echoStr = $_GET["echostr"];
        //valid signature , option
        if($this->checkSignature()){
        echo $echoStr;
        exit;
        }
    }
    public function responseMsg()
    {
//get post data, May be due to the different environments
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
      //extract post data
if (!empty($postStr)){
                 
              $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
                $fromUsername = $postObj->FromUserName;
                $toUsername = $postObj->ToUserName;
                $keyword = trim($postObj->Content);
                $time = time();
                $textTpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>
<Content><![CDATA[%s]]></Content>
<FuncFlag>0</FuncFlag>
</xml>";            
if(!empty( $keyword ))
                {
              $msgType = "text";
                $contentStr = "Welcome to wechat world!";
                $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
                echo $resultStr;
                }else{
                echo "Input something...";
                }
        }else {
        echo "";
        exit;
        }
    }
private function checkSignature()
{
        $signature = $_GET["signature"];
        $timestamp = $_GET["timestamp"];
        $nonce = $_GET["nonce"];
        
$token = TOKEN;
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature ){
return true;
}else{
return false;
}
}
}
?>

  

2、回到申请测试号页面,url一栏就填写上一步的文件网址。比如http://xxxxxx/index.php

3、token 就填写 第一步中自定义的字符串,比如 mytoken

 

ref: https://www.cnblogs.com/zy20160429/p/7644963.html

posted @ 2021-06-15 11:22 圆旭 阅读(1491) 评论(0) 推荐(0) 编辑
摘要: 先要安装工具,命令如下: yum install nfs-utils -y 然后开始挂载: sudo mount -t nfs -o vers=3,nolock,proto=tcp,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresv 阅读全文
posted @ 2021-04-29 14:46 圆旭 阅读(350) 评论(0) 推荐(0) 编辑
摘要: 环境: centos7 下载nginx-1.19.1.tar.gz 并解压。安装依赖 yum -y install pcre-devel yum -y install openssl openssl-devel yum install -y zlib yum install -y zlib-deve 阅读全文
posted @ 2021-04-03 19:32 圆旭 阅读(111) 评论(0) 推荐(0) 编辑
摘要: ref: https://bbs.csdn.net/topics/30475476 cat flask.log | grep "a" | grep "b" | grep 'c' 阅读全文
posted @ 2020-10-15 14:23 圆旭 阅读(829) 评论(0) 推荐(0) 编辑
摘要: git强制覆盖: git fetch --all git reset --hard origin/master git pullgit强制覆盖本地命令(单条执行): git fetch --all && git reset --hard origin/master && git pull—————— 阅读全文
posted @ 2019-09-26 17:26 圆旭 阅读(6510) 评论(0) 推荐(0) 编辑
摘要: 使用-copy参数: CLI压缩视频时保持音频不变 阅读全文
posted @ 2019-03-13 23:17 圆旭 阅读(330) 评论(0) 推荐(0) 编辑
摘要: 电脑使用时间太久会落伍卡顿,改造的步骤如下: 1,32位操作系统要换成64位。 2,增加内存。 3,换固态硬盘。 4,换电池如果亏损太多。 阅读全文
posted @ 2019-02-12 18:52 圆旭 阅读(320) 评论(0) 推荐(0) 编辑
摘要: macbook型号:air 2012 mid 当前操作系统:mojave 安装工具:boot camp assistant 要安装的双系统:windows 10家庭版 安装教程:百度搜一堆 安装过程中遇到两个坑: (1)win10 iso文件大于4GB,而boot camp制作的u盘启动盘是fat3 阅读全文
posted @ 2019-02-06 23:50 圆旭 阅读(5335) 评论(1) 推荐(0) 编辑
摘要: 如下: 阅读全文
posted @ 2019-01-20 08:46 圆旭 阅读(444) 评论(0) 推荐(0) 编辑
摘要: version: Phalcon 3 如果DB存在一条记录phone='13012345678 '(后边有一个空格), 则在查询User::findFirst("phone = '13012345678'")时,即使末尾少了一个空格,也会匹配上,并返回结果。 阅读全文
posted @ 2019-01-16 14:38 圆旭 阅读(588) 评论(0) 推荐(0) 编辑
点击右上角即可分享
微信分享提示