批改状态:合格
老师批语:
对接微信服务器需要的签名程序
可以把这段代码写在模型层中
//对接微信服务器时 需要的数字签名程序,即生成signature
public function valid()
{
$signature = input("get.signature");
$timestamp = input("get.timestamp");
$nonce = input("get.nonce");
$token = "weixin";
$tmpArr = array($timestamp, $nonce,$token);
sort($tmpArr, SORT_STRING);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if ($tmpStr == $signature){
return true;
}else{
return false;
}点击 "运行实例" 按钮查看在线实例
在控制器中调用此方法
public function index(\app\index\model\Weixin $weixin)
{
$data = $weixin -> valid();
if ($data){
exit(input("get.echostr")); //返回的如果是true 这个地方不能是echo echo的话会配置不成功
}else{
exit("signature error");
}
}点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号