From b44a12ed6cbd054f4bfaaf2b1e72183aee325d3e Mon Sep 17 00:00:00 2001
From: gongfuxiang <2499232802@qq.com>
Date: Tue, 23 Oct 2018 01:13:10 +0800
Subject: [PATCH] debug
---
.../Controller/AlipayLifeController.class.php | 20 +-
.../Application/Library/AlipayLife.class.php | 187 +++++++++++-------
.../Service/AlipayLifeService.class.php | 28 +++
3 files changed, 162 insertions(+), 73 deletions(-)
diff --git a/service/Application/Api/Controller/AlipayLifeController.class.php b/service/Application/Api/Controller/AlipayLifeController.class.php
index b74fb3736..dfb4c950f 100644
--- a/service/Application/Api/Controller/AlipayLifeController.class.php
+++ b/service/Application/Api/Controller/AlipayLifeController.class.php
@@ -34,14 +34,21 @@ class AlipayLifeController extends CommonController
*/
public function Index()
{
- file_put_contents('./gggggg.txt', json_encode($_GET));
- file_put_contents('./pppppp.txt', json_encode($_POST));
- file_put_contents('./ffffff.txt', urldecode(file_get_contents("php://input")));
-
+ // file_put_contents('./gggggg.txt', json_encode($_GET));
+ // file_put_contents('./pppppp.txt', json_encode($_POST));
+ // file_put_contents('./ffffff.txt', urldecode(file_get_contents("php://input")));
// 参数
$params = $_POST;
+ if(empty($params))
+ {
+ $input = file_get_contents("php://input");
+ if(!empty($input))
+ {
+ $params = iconv("GBK", "UTF-8", urldecode($input));
+ }
+ }
if(empty($params['service']))
{
die('service error');
@@ -58,6 +65,11 @@ class AlipayLifeController extends CommonController
$o->Check();
break;
+ // 关注/取消
+ case 'alipay.mobile.public.message.notify' :
+ $o->Life();
+ break;
+
// 默认
default :
exit('service error');
diff --git a/service/Application/Library/AlipayLife.class.php b/service/Application/Library/AlipayLife.class.php
index 380e53ad7..efccbde82 100644
--- a/service/Application/Library/AlipayLife.class.php
+++ b/service/Application/Library/AlipayLife.class.php
@@ -44,75 +44,6 @@ class AlipayLife
}
}
- /**
- * xml转属组
- * @author Devil
- * @blog http://gong.gg/
- * @version 1.0.0
- * @date 2018-10-22
- * @desc description
- * @param [string] $xmltext [xml数据]
- * @return [array] [属组]
- */
- public function xmlToArray($xmltext)
- {
- libxml_disable_entity_loader(true);
- return json_decode(json_encode(simplexml_load_string($xmltext, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
- }
-
- /**
- * 属组转url字符串
- * @author Devil
- * @blog http://gong.gg/
- * @version 1.0.0
- * @date 2018-10-22
- * @desc description
- * @param [array] $data [输入参数-数组]
- * @return [string] [url字符串]
- */
- public function ArrayToUrlString($data)
- {
- $ur_lstring = '';
- ksort($data);
- foreach($data AS $key=>$val)
- {
- if(!in_array($key, ['sign']))
- {
- $ur_lstring .= "$key=$val&";
- }
- }
- return substr($ur_lstring, 0, -1);
- }
-
- /**
- * 校验
- * @author Devil
- * @blog http://gong.gg/
- * @version 1.0.0
- * @date 2018-10-22
- * @desc description
- */
- public function Check()
- {
- if($this->OutRsaVerify($this->ArrayToUrlString($this->params), $this->params['sign']))
- {
- $response_xml = 'true'.$this->life_data['rsa_public'].'';
- } else {
- $response_xml = 'falseVERIFY_FAILED'.$this->life_data['rsa_public'].'';
- }
- $return_xml = '
-
-
- '.$this->life_data['rsa_public'].'
- true
-
- '.$this->MyRsaSign($response_xml).'
- RSA2
- ';
- die($return_xml);
- }
-
-
/**
* [MyRsaSign 签名字符串]
* @author Devil
@@ -181,5 +112,123 @@ class AlipayLife
}
return (isset($verify) && $verify == 1) ? true : false;
}
+
+ /**
+ * xml转属组
+ * @author Devil
+ * @blog http://gong.gg/
+ * @version 1.0.0
+ * @date 2018-10-22
+ * @desc description
+ * @param [string] $xmltext [xml数据]
+ * @return [array] [属组]
+ */
+ public function xmlToArray($xmltext)
+ {
+ libxml_disable_entity_loader(true);
+ return json_decode(json_encode(simplexml_load_string($xmltext, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
+ }
+
+ /**
+ * 属组转url字符串
+ * @author Devil
+ * @blog http://gong.gg/
+ * @version 1.0.0
+ * @date 2018-10-22
+ * @desc description
+ * @param [array] $data [输入参数-数组]
+ * @return [string] [url字符串]
+ */
+ public function ArrayToUrlString($data)
+ {
+ $ur_lstring = '';
+ ksort($data);
+ foreach($data AS $key=>$val)
+ {
+ if(!in_array($key, ['sign']))
+ {
+ $ur_lstring .= "$key=$val&";
+ }
+ }
+ return substr($ur_lstring, 0, -1);
+ }
+
+ /**
+ * 返回操作状态
+ * @author Devil
+ * @blog http://gong.gg/
+ * @version 1.0.0
+ * @datetime 2018-10-23T01:07:28+0800
+ * @param boolean $status [description]
+ */
+ public function Respond($status = false)
+ {
+ if($status === true)
+ {
+ $response_xml = 'true'.$this->life_data['rsa_public'].'';
+ } else {
+ $response_xml = 'falseVERIFY_FAILED'.$this->life_data['rsa_public'].'';
+ }
+ $return_xml = '
+
+
+ '.$this->life_data['rsa_public'].'
+ true
+
+ '.$this->MyRsaSign($response_xml).'
+ RSA2
+ ';
+ die($return_xml);
+ }
+
+ /**
+ * 校验
+ * @author Devil
+ * @blog http://gong.gg/
+ * @version 1.0.0
+ * @date 2018-10-22
+ * @desc description
+ */
+ public function Check()
+ {
+ $status = $this->OutRsaVerify($this->ArrayToUrlString($this->params), $this->params['sign']);
+ $this->Respond($status);
+ }
+
+ /**
+ * 生活号事件
+ * @author Devil
+ * @blog http://gong.gg/
+ * @version 1.0.0
+ * @datetime 2018-10-23T00:38:21+0800
+ */
+ public function Life()
+ {
+ $status = false;
+ if($this->OutRsaVerify($this->ArrayToUrlString($this->params), $this->params['sign']))
+ {
+ $data = [
+ 'appid' => $this->xml_data['AppId'],
+ 'alipay_open_id' => $this->xml_data['FromAlipayUserId'],
+ 'user_id' => empty($this->xml_data['FromUserId']) ? '' : $this->xml_data['FromUserId'],
+ 'logon_id' => empty($userinfo['logon_id']) ? '' : $userinfo['logon_id'],
+ 'user_name' => empty($user_id['user_name']) ? '' : $user_id['user_name'],
+ ];
+ switch($this->xml_data['EventType'])
+ {
+ // 取消关注
+ case 'unfollow' :
+ $status = AlipayLifeService::UserUnfollow($data);
+ break;
+
+ // 关注/进入生活号
+ case 'enter' :
+ $status = AlipayLifeService::UserEnter($data);
+ break;
+ }
+ }
+ $this->Respond($status);
+ }
+
}
?>
\ No newline at end of file
diff --git a/service/Application/Service/AlipayLifeService.class.php b/service/Application/Service/AlipayLifeService.class.php
index d805644cf..ff30a5825 100644
--- a/service/Application/Service/AlipayLifeService.class.php
+++ b/service/Application/Service/AlipayLifeService.class.php
@@ -28,5 +28,33 @@ class AlipayLifeService
}
return null;
}
+
+ /**
+ * 用户取消关注生活号
+ * @author Devil
+ * @blog http://gong.gg/
+ * @version 1.0.0
+ * @date 2018-08-29
+ * @desc description
+ * @param [array] $params [输入参数]
+ */
+ public static function UserUnfollow($params = [])
+ {
+ file_put_contents('./uuuuuu.txt', json_encode($params));
+ }
+
+ /**
+ * 用户关注/进入生活号
+ * @author Devil
+ * @blog http://gong.gg/
+ * @version 1.0.0
+ * @date 2018-08-29
+ * @desc description
+ * @param [array] $params [输入参数]
+ */
+ public static function UserEnter($params = [])
+ {
+ file_put_contents('./eeeeee.txt', json_encode($params));
+ }
}
?>
\ No newline at end of file