Files
CompanyProject/芳林公司项目/www.zhiyuanhelp.com/application/api/controller/Pay.php
2024-09-27 01:32:49 +08:00

86 lines
2.3 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
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/4/17
* Time: 20:27
*/
namespace app\api\controller;
use app\api\model\Order as OrderModel;
use app\api\service\WxNotify;
use app\api\service\Pay as PayService;
use think\facade\Log;
class Pay extends BaseController
{
/*
* 支付
* */
public function prePayOrder(){
$user_id = $this->verifyToken();
$payType = input('post.pay_type',1);
$payWay = input('post.pay_way',1);
//订单ID
$orderID = input('post.order_id');
//支付后返回页面
$rebackUrl = input('post.rebackUrl');
//验证订单信息并返回订单号
$pay = new PayService($orderID,$payType,$payWay);
//payType1是移动支付2是pc支付,PayWay 1是微信支付2是支付宝
$res = [];
if($payWay == 1){
$result = $payType == 2?$pay->codePay($user_id):$pay->wapPay($user_id,$rebackUrl);
$res['url'] = $result;
$res['pay_way'] = 1;
}else{
$result = $payType == 2?$pay->alipay_pc($user_id,$rebackUrl):$pay->alipay_wap($user_id,$rebackUrl);
$res['url'] = $result;
$res['pay_way'] = 2;
}
return api_return('成功',$res);
}
//微信支付回调
public function receiveNotify(){
//2..更新订单状态
$notify = new WxNotify();
$notify->Handle();
}
//支付宝异步回调
public function alipayNotifyUrl()
{
$params=$_POST;
//获取支付成功后支付宝返回的参数
$out_trade_no = htmlspecialchars($params['out_trade_no']);//商户订单号
$total_amount = htmlspecialchars($params['total_amount']);//价格
$trade_status = htmlspecialchars($params['trade_status']);//交易状态
$gmt_payment = htmlspecialchars($params['gmt_payment']);//交易付款时间
if ($trade_status == "TRADE_SUCCESS" || $trade_status == "TRADE_FINISHED") {//支付成功
$data['status'] = 1;
$data['pay_way'] = 2;
$data['pay_time'] = strtotime($gmt_payment);
OrderModel::where([['ord_no','=',$out_trade_no],['money','=',$total_amount]])->update($data);
echo "success"; //请不要修改或删除
} else {
echo "fail";
}
}
}