微信公众号开发一:接口配置信息(url接入校验)

公众号信息

 

appid:是公众号开发识别码,配合开发者密码可调用公众号的接口能力。
appsecret:是校验公众号开发者身份的密码,具有极高的安全性。

url接入校验配置

 

URL:就是指我们自己的服务器地址(公网可访问)
该URL是开发者用来接收和响应微信消息和事件的接口URL
(必须以http://或https://开头,分别支持80端口和443端口)
Token:可任意填写,用作生成签名(必须为英文或数字,长度为3-32字符)
该签名在后边会用到,这里暂时随便填个内容也可以

url接入校验流程

当你提交接口配置信息后。
1:首先会发送到微信的服务器上,微信的服务器就会对内容处理
2:微信服务器转发到我们配置的url上(url必须外网可以访问),并带上相应的校验参数
3:我们的服务器接收到请求后,对微信发送的参数进行校验

php校验源码

/**
 * 微信公众号 - 接入接口配置验证
 * 请原样返回echostr参数内容,则接入生效,成为开发者成功
 * https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421135319
 * Display a listing of the posts.
 *
 */
public function checkSignature(Request $request)
{
    Log::info('start checkSignature');
    $echostr = $request->get('echostr', '');
    $signature = $request->get('signature', '');
    $timestamp = $request->get('timestamp', '');
    $nonce = $request->get('nonce', '');

    $tmpArr = array($this->token, $timestamp, $nonce);
    sort($tmpArr, SORT_STRING);
    $tmpStr = implode($tmpArr);
    $tmpStr = sha1($tmpStr);
    if($tmpStr == $signature){
        echo $echostr;
        Log::info('checkSignature success');
        exit;
    }else{
        return false;
    }
}

ps: $this->token是你在接口配置信息里设置的token
发布了20 篇原创文章 · 获赞 8 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/web_snail/article/details/90474299