diff --git a/service/Application/Api/Controller/AlipayLifeController.class.php b/service/Application/Api/Controller/AlipayLifeController.class.php new file mode 100644 index 000000000..d7341e18d --- /dev/null +++ b/service/Application/Api/Controller/AlipayLifeController.class.php @@ -0,0 +1,65 @@ +Check(); + break; + + // 默认 + default : + exit('service error'); + } + } + +} +?> \ No newline at end of file diff --git a/service/Application/Library/AlipayLife.class.php b/service/Application/Library/AlipayLife.class.php new file mode 100644 index 000000000..3219bfd1c --- /dev/null +++ b/service/Application/Library/AlipayLife.class.php @@ -0,0 +1,183 @@ +params = $params; + $this->xml_data = isset($params['biz_content']) ? $this->xmlToArray($params['biz_content']) : ''; + $this->life_data = isset($this->xml_data['AppId']) ? AlipayLifeService::AppidLifeRow(['appid'=>$this->xml_data['AppId']]) : ''; + + // 当前生活号是否存在 + if(empty($this->life_data)) + { + die('life error'); + } + } + + /** + * 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'])) + { + die(' + + + '.$this->life_data['rsa_public'].' + true + + '.$this->MyRsaSign(''.$this->life_data['rsa_public'].'true').' + RSA2 + '); + } + die('check error'); + } + + + /** + * [MyRsaSign 签名字符串] + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @datetime 2017-09-24T08:38:28+0800 + * @param [string] $prestr [需要签名的字符串] + * @return [string] [签名结果] + */ + private function MyRsaSign($prestr) + { + $res = "-----BEGIN PRIVATE KEY-----\n"; + $res .= wordwrap($this->life_data['rsa_private'], 64, "\n", true); + $res .= "\n-----END PRIVATE KEY-----"; + $pkeyid = openssl_pkey_get_private($res); + return openssl_sign($prestr, $sign, $pkeyid, OPENSSL_ALGO_SHA256) ? base64_encode($sign) : null; + } + + /** + * [MyRsaDecrypt RSA解密] + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @datetime 2017-09-24T09:12:06+0800 + * @param [string] $content [需要解密的内容,密文] + * @return [string] [解密后内容,明文] + */ + private function MyRsaDecrypt($content) + { + $res = "-----BEGIN PUBLIC KEY-----\n"; + $res .= wordwrap($this->life_data['rsa_private'], 64, "\n", true); + $res .= "\n-----END PUBLIC KEY-----"; + $res = openssl_get_privatekey($res); + $content = base64_decode($content); + $result = ''; + for($i=0; $ilife_data['out_rsa_public'], 64, "\n", true); + $res .= "\n-----END PUBLIC KEY-----"; + $pkeyid = openssl_pkey_get_public($res); + $sign = base64_decode($sign); + if($pkeyid) + { + $verify = openssl_verify($prestr, $sign, $pkeyid, OPENSSL_ALGO_SHA256); + openssl_free_key($pkeyid); + } + return (isset($verify) && $verify == 1) ? true : false; + } +} +?> \ No newline at end of file diff --git a/service/Application/Service/AlipayLifeService.class.php b/service/Application/Service/AlipayLifeService.class.php new file mode 100644 index 000000000..c1a57ef13 --- /dev/null +++ b/service/Application/Service/AlipayLifeService.class.php @@ -0,0 +1,32 @@ +where(['appid'=>$params['appid']])->find(); + } + return ''; + } +} +?> \ No newline at end of file diff --git a/service/alipay_life_notify.php b/service/alipay_life_notify.php index a5f0d198f..ffe401e3f 100644 --- a/service/alipay_life_notify.php +++ b/service/alipay_life_notify.php @@ -1,4 +1,18 @@ \ No newline at end of file