update
This commit is contained in:
parent
784fa45415
commit
de6a67c910
@ -9,10 +9,20 @@ define("PRIVATE_KEY", '999712592d00ad2f75b04421e030ba04');
|
|||||||
|
|
||||||
class KefuController {
|
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
|
public function checkServer() // 校验服务器地址URL
|
||||||
{
|
{
|
||||||
if ( isset($_GET['echostr'])) {
|
if ( isset($_REQUEST['echostr'])) {
|
||||||
$this->valid();
|
$this->valid();
|
||||||
} else {
|
} else {
|
||||||
$this->responseMsg();
|
$this->responseMsg();
|
||||||
@ -21,7 +31,7 @@ class KefuController {
|
|||||||
|
|
||||||
public function valid()
|
public function valid()
|
||||||
{
|
{
|
||||||
$echoStr = $_GET['echostr'];
|
$echoStr = $_REQUEST['echostr'];
|
||||||
if ( $this->checkSignature()){
|
if ( $this->checkSignature()){
|
||||||
echo $echoStr;
|
echo $echoStr;
|
||||||
exit;
|
exit;
|
||||||
@ -34,9 +44,9 @@ class KefuController {
|
|||||||
private function checkSignature()
|
private function checkSignature()
|
||||||
{
|
{
|
||||||
|
|
||||||
$signature = $_GET["signature"];
|
$signature = $_REQUEST["signature"];
|
||||||
$timestamp = $_GET["timestamp"];
|
$timestamp = $_REQUEST["timestamp"];
|
||||||
$nonce = $_GET["nonce"];
|
$nonce = $_REQUEST["nonce"];
|
||||||
|
|
||||||
$token = TOKEN;
|
$token = TOKEN;
|
||||||
error_log('token:' . $token);
|
error_log('token:' . $token);
|
||||||
@ -54,9 +64,27 @@ 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()
|
public function responseMsg()
|
||||||
{
|
{
|
||||||
$postStr = $GLOBALS ["HTTP_RAW_POST_DATA" ];
|
$postStr = $GLOBALS ["HTTP_RAW_POST_DATA" ];
|
||||||
|
error_log('responseMsg');
|
||||||
|
|
||||||
if (! empty( $postStr ) && is_string( $postStr )){
|
if (! empty( $postStr ) && is_string( $postStr )){
|
||||||
|
|
||||||
@ -89,32 +117,22 @@ class KefuController {
|
|||||||
"msgtype"=>"text",
|
"msgtype"=>"text",
|
||||||
"text"=> array ("content"=> $content )
|
"text"=> array ("content"=> $content )
|
||||||
);
|
);
|
||||||
$json = json_encode( $data ,JSON_UNESCAPED_UNICODE); // php5.4+
|
$params = json_encode( $data ,JSON_UNESCAPED_UNICODE);
|
||||||
|
|
||||||
$access_token = $this->getAccessToken();
|
$access_token = $this->getAccessToken();
|
||||||
/*
|
/*
|
||||||
* POST发送https请求客服接口api
|
* 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;
|
||||||
|
|
||||||
|
$response = '';
|
||||||
|
if (!phpcommon\HttpClient::get($url, $params, $response)) {
|
||||||
|
phpcommon\sendError(ERR_RETRY, '系统繁忙');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 以'json'格式发送post的https请求
|
if ( $response == 0 ){
|
||||||
$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 );
|
|
||||||
}
|
|
||||||
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 ){
|
|
||||||
echo 'success'; exit ;
|
echo 'success'; exit ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,17 +145,15 @@ class KefuController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 调用微信api,获取access_token,有效期7200s -xzz0704 */
|
|
||||||
public function getAccessToken(){
|
public function getAccessToken(){
|
||||||
/* 在有效期,直接返回access_token */
|
|
||||||
if (S('access_token' )){
|
if (S('access_token' )){
|
||||||
return S('access_token' );
|
return S('access_token' );
|
||||||
}
|
}
|
||||||
/* 不在有效期,重新发送请求,获取access_token */
|
|
||||||
else {
|
else {
|
||||||
$appid = SHAOWEI_APPID;
|
$appid = SHAOWEI_APPID;
|
||||||
$appkey = PRIVATE_KEY;
|
$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 = '';
|
$response = '';
|
||||||
if (!phpcommon\HttpClient::get($url, $params, $response)) {
|
if (!phpcommon\HttpClient::get($url, $params, $response)) {
|
||||||
phpcommon\sendError(ERR_RETRY, '系统繁忙');
|
phpcommon\sendError(ERR_RETRY, '系统繁忙');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user