/**
*
* @author
* @return void
*/
public function WxPayNotify()
{
require_once EXTEND_PATH.'/wxpay/lib/WxPay.Data.php';
$wxpay = new \WxPayDataBase();
Db::startTrans();
try{
// , xml
$xmlData = file_get_contents('php://input');
//$result = \WxPayResults::Init($xmlData);
// xml
$data = $wxpay->FromXml($xmlData);
if($data['sign'] == $wxpay->getSign($data)){
if ($data['result_code'] == 'SUCCESS'){
//
Log::write(json_encode($request)."\r
");
//
Db::commit();
//
//echo '';exit;
$return['return_code'] = 'SUCCESS';
$return['return_msg'] = 'OK';
$string = self::arrayToXml($return);
echo $string; exit;
}else{
Log::write(" :".json_encode($data).date("Y-m-d H:i:s"),time()."\r
");
}
}else{
Log::write(" :".json_encode($data).date("Y-m-d H:i:s"),time()."\r
");
}
}catch (\Exception $e){
Db::rollback();
Log::write($e->getMessage()."\r
"." :".json_encode($data).date("Y-m-d H:i:s"),time()."\r
");
}
}
/**
* xml
* @param array $arr *
* @author
* @return string
*/
public static function arrayToXml($arr){
$xml = "";
foreach($arr as $key => $val){
if(is_numeric($val)){
$xml.=".$key.">".$val."".$key.">";
}else{
$xml.=".$key.">.$val."]]>".$key.">";
}
}
$xml.="";
return $xml;
}
/**
* xml
* @param string $xml xml *
* @author
* @return array|bool|\mix|mixed|\stdClass|string
*/
public static function xmlToArray($xml){
$array_data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
return $array_data;
}