<?php
namespace
Apps\Controller;
use
Common\Controller\AppBaseController;
define(
"TOKEN"
,
""
);
define(
"APPID"
,
""
);
define(
"APPSECRET"
,
""
);
class
WeChatController
extends
AppBaseController
{
function
index()
{
$echoStr
=
$_GET
[
"echostr"
];
if
(
$this
->checkSignature()) {
echo
$echoStr
;
exit
;
}
}
private
function
checkSignature()
{
$signature
=
$_GET
[
"signature"
];
$timestamp
=
$_GET
[
"timestamp"
];
$nonce
=
$_GET
[
"nonce"
];
$token
=
"xiaochen"
;
$tmpArr
=
array
(
$token
,
$timestamp
,
$nonce
);
sort(
$tmpArr
, SORT_STRING);
$tmpStr
= implode(
$tmpArr
);
$tmpStr
= sha1(
$tmpStr
);
if
(
$tmpStr
==
$signature
) {
return
true;
}
else
{
return
false;
}
}
function
https_request(
$url
,
$data
= null)
{
$curl
= curl_init();
curl_setopt(
$curl
, CURLOPT_URL,
$url
);
curl_setopt(
$curl
, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt(
$curl
, CURLOPT_SSL_VERIFYHOST, FALSE);
if
(!
empty
(
$data
)){
curl_setopt(
$curl
, CURLOPT_POST, 1);
curl_setopt(
$curl
, CURLOPT_POSTFIELDS,
$data
);
}
curl_setopt(
$curl
, CURLOPT_RETURNTRANSFER, 1);
$output
= curl_exec(
$curl
);
curl_close(
$curl
);
return
$output
;
}
}