<?php

/* ========================================================================
 * $Id: notify.php 1424 2020-07-08 16:03:40Z onez $
 * 
 * Email: www@onez.cn
 * QQ: 6200103
 * HomePage: http://www.onez.cn
 * ========================================================================
 * Copyright 2016-2017 佳蓝科技.
 * 
 * ======================================================================== */

!defined('IN_ONEZ') && exit('Access Denied');
include_once(dirname(dirname(__FILE__)).'/api.php');
$trade_order_id = $order['orderno'];//商户网站内部ID，此处time()是演示数据
$appid              = $PT['api_appid'];
$appsecret          = $PT['api_appsecret'];
$payment          = 'alipay';
$my_plugin_id =$order['data']['sitetoken'];
$data = $_REQUEST;
unset($data['action']);
unset($data['method']);
unset($data['noVue']);
unset($data['orderno']);
unset($data['siteid']);
foreach ($data as $k=>$v){
  $data[$k] = stripslashes($v);
}
if(!isset($data['hash'])||!isset($data['trade_order_id'])){
  onez('log')->write('pay.log',"\n$orderno:没有订单编号",'a+');
  echo 'failed';exit('');
}

//自定义插件ID,请与支付请求时一致
if(isset($data['plugins'])&&$data['plugins']!=$my_plugin_id){
    onez('log')->write('pay.log',"\n$orderno:请与支付请求时不一致",'a+');
    echo 'failed';exit('');
}

//APP SECRET
$appkey =$appsecret;
$hash =XH_Payment_Api::generate_xh_hash($data,$appkey);
if($data['hash']!=$hash){
    //签名验证失败
    onez('log')->write('pay.log',"\n$orderno:签名验证失败",'a+');
    echo 'failed';exit('');
}

if($data['status']=='OD'){
  onez('log')->write('pay.log',"\n$orderno:支付成功",'a+');
  onez('bs.pay')->payOK($orderno,'ok');
}else{
  onez('log')->write('pay.log',"\n$orderno:支付失改",'a+');
  
}
//ob_clean();
echo 'success';
exit();