qc.ifish7.com/Application/Shop/Controller/PayNotifyController.class.php

82 lines
3.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Shop\Controller;
use Think\Controller;
class PayNotifyController extends Controller {
//异步通知(PC支付)
public function notify_url(){
$arr=$_POST;
Vendor('AlipaySdk.pagepay.service.AlipayTradeService');
$alipaySevice = new \AlipayTradeService(C('alipay'));
$alipaySevice->writeLog(var_export($_POST,true));
$result = $alipaySevice->check($arr);
if($result){
$out_trade_no = $_POST['out_trade_no'];
$total_amount= $_POST['total_amount'];
if ($_POST['trade_status'] == 'TRADE_SUCCESS') {
//这里加入商业逻辑处理
$order=D("shop_order")->where(array("order_num"=>$out_trade_no))->find();
//这里要判断是否is_pay为0才执行商业处理防止异步通知执行两次以上从而造成多条付款明细
if($order&&!$order["is_pay"]){
M("shop_order")->save(array(
"order_id"=>$order["order_id"],
"is_pay"=>1,
));
//设置订单状态
D("shop_order")->setOrderState($order["order_id"]);
//订单日志
D("shop_order")->log($order["order_id"],"用户在线支付,金额:{$total_amount},支付方式:支付宝");
//
$this->payMent($order["order_id"],"alipay",json_encode($_POST));
}
}
echo "success";//请不要修改或删除
}else{
}
}
//异步通知(手机支付)
public function wap_notify_url(){
$arr=$_POST;
Vendor('AlipaySdk.aop.AopClient');
Vendor('AlipaySdk.wappay.service.AlipayTradeService');
$alipaySevice = new \AlipayTradeService(C('alipay'));
$result = $alipaySevice->check($arr);
if($result){
$out_trade_no = $_POST['out_trade_no'];
$total_amount= $_POST['total_amount'];
if ($_POST['trade_status'] == 'TRADE_SUCCESS') {
//这里加入商业逻辑处理
$order=D("shop_order")->where(array("order_num"=>$out_trade_no))->find();
//这里要判断是否is_pay为0才执行商业处理防止异步通知执行两次以上从而造成多条付款明细
if($order&&!$order["is_pay"]){
M("shop_order")->save(array(
"order_id"=>$order["order_id"],
"is_pay"=>1,
));
//设置订单状态
D("shop_order")->setOrderState($order["order_id"]);
//订单日志
D("shop_order")->log($order["order_id"],"用户在线支付,金额:{$total_amount},支付方式:支付宝(wap)");
//
$this->payMent($order["order_id"],"alipay",json_encode($_POST));
}
}
echo "success";//请不要修改或删除
}else{
}
}
//支付定同步返回
public function return_url(){
redirect(U("Shop/ShopOrder/index"));
}
//付款记录
private function payMent($orderid,$paytype,$detail){
M("shop_order_payment")->add(array(
"order_id" =>$orderid,
"addtime" =>time(),
"paytype" =>$paytype,
"detail" =>$detail,
));
}
}