signature:微信加密签名,signature结合了开发者填写的token参数和请求中的timestamp参数、nonce参数。
其中:
timestamp:时间戳
nonce:随机数
echostr:随机字符串2.将三个参数拼接成一个字符串,并使用sha1加密。
3.开发者将加密后的字符串与signature对比;若相同,则这次请求来源于微信,是可信的。
<span style="font-family:KaiTi_GB2312;font-size:14px;"><?php
define("TOKEN","weixin");
$weixinObj = new Wechat();
$weixinObj->valid();
class Wechat{
public function valid(){
$echoStr = $_GET['echostr'];
if($this->checkSignature()){
echo $echoStr;
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;
}
}
}</span>以上就介绍了微信入坑第一弹,包括了微信,第一方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
微信是一款手机通信软件,支持通过手机网络发送语音短信、视频、图片和文字。微信可以单聊及群聊,还能根据地理位置找到附近的人,带给大家全新的移动沟通体验,有需要的小伙伴快来保存下载体验吧!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号