微信和支付宝支付成功以后的回调方法
//微信回调地址
public function actionNotify(){
// $msg = array();
$postStr = file_get_contents('php://input');
//$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
$msg = (array)simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
$out_trade_no = $msg['out_trade_no'];//订单号
if (empty($msg['out_trade_no'])) {
return Helper::format_data(PARAM_ERROR,['data'=>'1']);
}
$order = new Orders();
if ($msg['result_code'] == 'SUCCESS') {
$data = $order->find()->where(['order_sn'=>$out_trade_no])->one();
$data->status = 2;
$data->pay_time = time();
if($data->save()){
$wxpay = new Wxpay();
$str = $wxpay->find()->where(['order_sn'=>$msg['out_trade_no']])->one();
if(empty($str)){
$wxpay->user_id = $data->user_id;
$wxpay->total_fee = $msg['total_fee']/100;
$wxpay->order_sn = $msg['out_trade_no'];
$wxpay->time_end = $msg['time_end'];
$wxpay->create_time = time();
if($wxpay->save(false)){
return Helper::format_data(SUCC,$data->orders_id);
}
}
}
} else {
return Helper::format_data(PARAM_ERROR, $msg);
}
}
//支付宝回调
public function actionNotifys(){
$out_trade_no = $_POST['out_trade_no'];
if (empty($_POST['out_trade_no'])) {
return Helper::format_data(PARAM_ERROR,['id'=>'修改充值记录没有获取POST']);
}
if(!empty($_POST['trade_status'])){ //状态值不为空
//检查该账单是否已支付.....
if($_POST['trade_status'] == 'TRADE_FINISHED' OR $_POST['trade_status'] == 'TRADE_SUCCESS') {
$order = new Orders();
$data = $order->find()->where(['order_sn'=>$_POST['out_trade_no']])->one();
if(empty($data)){
return Helper::format_data(PARAM_ERROR,['id'=>'无效的订单号']);
}
$data->status = 2;
$data->pay_time = time();
$zfbpay = new Zfbpay();
$str = $zfbpay->find()->where(['order_sn'=>$_POST['out_trade_no']])->one();
if(!empty($str)){
return Helper::format_data(PARAM_ERROR,['id'=>'已经存在']);
}
$zfbpay->user_id = $data->user_id;
$zfbpay->total_fee = $_POST['invoice_amount'];
$zfbpay->order_sn = $_POST['out_trade_no'];
$zfbpay->create_time = time();
if($data->save() && $zfbpay->save(false)){
return Helper::format_data(SUCC,$data->orders_id);
}
}else {
return Helper::format_data(PARAM_ERROR, $_POST);
}
}
}
//将XML转为array
public function actionxmlToArray($xml)
{
//禁止引用外部xml实体
libxml_disable_entity_loader(true);
$array = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
return $array;
}