update
This commit is contained in:
parent
784fa45415
commit
de6a67c910
@ -9,10 +9,20 @@ define("PRIVATE_KEY", '999712592d00ad2f75b04421e030ba04');
|
||||
|
||||
class KefuController {
|
||||
|
||||
protected function getRedis($openid)
|
||||
{
|
||||
$redis_conf = getRedisConfig(crc32($openid));
|
||||
$r = new phpcommon\Redis(array(
|
||||
'host' => $redis_conf['host'],
|
||||
'port' => $redis_conf['port'],
|
||||
'passwd' => $redis_conf['passwd']
|
||||
));
|
||||
return $r;
|
||||
}
|
||||
|
||||
public function checkServer() // 校验服务器地址URL
|
||||
{
|
||||
if ( isset($_GET['echostr'])) {
|
||||
if ( isset($_REQUEST['echostr'])) {
|
||||
$this->valid();
|
||||
} else {
|
||||
$this->responseMsg();
|
||||
@ -21,7 +31,7 @@ class KefuController {
|
||||
|
||||
public function valid()
|
||||
{
|
||||
$echoStr = $_GET['echostr'];
|
||||
$echoStr = $_REQUEST['echostr'];
|
||||
if ( $this->checkSignature()){
|
||||
echo $echoStr;
|
||||
exit;
|
||||
@ -34,9 +44,9 @@ class KefuController {
|
||||
private function checkSignature()
|
||||
{
|
||||
|
||||
$signature = $_GET["signature"];
|
||||
$timestamp = $_GET["timestamp"];
|
||||
$nonce = $_GET["nonce"];
|
||||
$signature = $_REQUEST["signature"];
|
||||
$timestamp = $_REQUEST["timestamp"];
|
||||
$nonce = $_REQUEST["nonce"];
|
||||
|
||||
$token = TOKEN;
|
||||
error_log('token:' . $token);
|
||||
@ -54,11 +64,29 @@ class KefuController {
|
||||
}
|
||||
}
|
||||
|
||||
private function disposeText($postArr)
|
||||
{
|
||||
$openid = $postArr['FromUserName'];
|
||||
$toUserName = $postArr['ToUserName'];
|
||||
$CreateTime = $postArr['CreateTime'];
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function_exists($postArr)
|
||||
{
|
||||
$openid = $postArr['FromUserName'];
|
||||
$toUserName = $postArr['ToUserName'];
|
||||
$CreateTime = $postArr['CreateTime'];
|
||||
|
||||
}
|
||||
|
||||
public function responseMsg()
|
||||
{
|
||||
$postStr = $GLOBALS ["HTTP_RAW_POST_DATA" ];
|
||||
error_log('responseMsg');
|
||||
|
||||
if (! empty ( $postStr ) && is_string ( $postStr )){
|
||||
if (! empty( $postStr ) && is_string( $postStr )){
|
||||
|
||||
$postArr = json_decode( $postStr , true );
|
||||
if (! empty ( $postArr ['MsgType']) && $postArr ['MsgType'] == 'text'){ // 文本消息
|
||||
@ -89,32 +117,22 @@ class KefuController {
|
||||
"msgtype"=>"text",
|
||||
"text"=> array ("content"=> $content )
|
||||
);
|
||||
$json = json_encode( $data ,JSON_UNESCAPED_UNICODE); // php5.4+
|
||||
$params = json_encode( $data ,JSON_UNESCAPED_UNICODE);
|
||||
|
||||
$access_token = $this->getAccessToken();
|
||||
/*
|
||||
* POST发送https请求客服接口api
|
||||
*/
|
||||
$url = " https :// api . weixin . qq . com / cgi - bin / message / custom / send ? access _ token = ". $access_token ;
|
||||
|
||||
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" . $access_token;
|
||||
|
||||
// 以'json'格式发送post的https请求
|
||||
$curl = curl_init();
|
||||
curl_setopt( $curl , CURLOPT_URL, $url );
|
||||
curl_setopt( $curl , CURLOPT_POST, 1); // 发送一个常规的Post请求
|
||||
curl_setopt( $curl , CURLOPT_SSL_VERIFYPEER, FALSE );
|
||||
curl_setopt( $curl , CURLOPT_SSL_VERIFYHOST, FALSE );
|
||||
if (! empty ( $json )){
|
||||
curl_setopt( $curl , CURLOPT_POSTFIELDS, $json );
|
||||
$response = '';
|
||||
if (!phpcommon\HttpClient::get($url, $params, $response)) {
|
||||
phpcommon\sendError(ERR_RETRY, '系统繁忙');
|
||||
return;
|
||||
}
|
||||
curl_setopt( $curl , CURLOPT_RETURNTRANSFER, 1 );
|
||||
// curl_setopt($curl, CURLOPT_HTTPHEADER, $headers );
|
||||
$output = curl_exec( $curl );
|
||||
if (curl_errno( $curl )) {
|
||||
echo 'Errno'.curl_error( $curl ); // 捕抓异常
|
||||
}
|
||||
curl_close( $curl );
|
||||
if ( $output == 0 ){
|
||||
|
||||
if ( $response == 0 ){
|
||||
echo 'success'; exit ;
|
||||
}
|
||||
|
||||
@ -127,17 +145,15 @@ class KefuController {
|
||||
}
|
||||
}
|
||||
|
||||
/* 调用微信api,获取access_token,有效期7200s -xzz0704 */
|
||||
|
||||
public function getAccessToken(){
|
||||
/* 在有效期,直接返回access_token */
|
||||
if (S('access_token' )){
|
||||
return S('access_token' );
|
||||
}
|
||||
/* 不在有效期,重新发送请求,获取access_token */
|
||||
else {
|
||||
$appid = SHAOWEI_APPID;
|
||||
$appkey = PRIVATE_KEY;
|
||||
$url = "https://api.weixing.qq.com/cgi-bin/token?;grant_type=client_credential&appid=$appid&secret=$appkey";
|
||||
$url = "https://api.weixing.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appkey";
|
||||
$response = '';
|
||||
if (!phpcommon\HttpClient::get($url, $params, $response)) {
|
||||
phpcommon\sendError(ERR_RETRY, '系统繁忙');
|
||||
|
Loading…
x
Reference in New Issue
Block a user