首页 > PHP
ThinkPHP6配置微信小程序客服消息接口
来源:TP课堂 时间:2021-02-16 点击:1247

使用情景如下:

image.png


代码:

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
public function istoken()//验证微信接口,如果确认是微信就返回它传来的echostr参数
 
    {
   
       $echoStr $_GET["echostr"];
   
       if ($this->checkSignature()) {
   
            echo $echoStr;
   
       exit;
   
       }
   
    }
   
    public function checkSignature(){ //官方的验证函数
   
        $signature $_GET["signature"];
     
        $timestamp $_GET["timestamp"];
     
        $nonce $_GET["nonce"];
     
        $token 'wangxiaoqin';
     
        $tmpArr array($token$timestamp$nonce);
     
        sort($tmpArr, SORT_STRING);
     
        $tmpStr = implode( $tmpArr );
     
        $tmpStr = sha1( $tmpStr );
     
        if$tmpStr == $signature ){
     
            return true;
     
        }else{
     
            return false;
     
        }
   
    }


在线客服:

通过微信客服助手,在微信上即可实时沟通。


image.png