first commit

This commit is contained in:
编码猿
2024-09-27 01:32:49 +08:00
commit 28ebe05a64
7399 changed files with 1174529 additions and 0 deletions

View File

@@ -0,0 +1,140 @@
<?php
namespace app\api\controller;
use app\common\service\PayService;
use app\exceptions\PayException;
use think\Db;
use think\Exception;
use think\facade\Config;
use think\facade\Log;
use wxpayNew\lib\WxPayNotify;
use wxpayNew\WxPayConfig;
class PayController extends ApiController
{
protected $noAuth = ['aliPayCallback','wxPayCallback'];
/**
* @apiDefine Pay 支付管理
*/
/**
* @apiVersion 1.0.0
* @api {post} /pay/appPay 订单现金支付参数(朱晓伟)
* @apiGroup Pay
* @apiHeader {String} authentication 验证
* @apiParam {int} order_id 订单id
* @apiParam {int} pay_type 值1货到付款值2线下支付值3小程序支付值4微信支付值5支付宝支付
* @apiSuccessExample Success-Response:
* {
"code":200,
"message":"成功",
"data":{
"aliPayInfo":"alipay_sdk=alipay-sdk-php-20161101&app_id=2016092600600876&biz_content=%7B%22subject%22%3A%22%5Cu652f%5Cu4ed8%5Cu5b9d%5Cu8ba2%5Cu5355%22%2C%22timeout_express%22%3A%22165885m%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%2C%22total_amount%22%3A%220.00%22%2C%22out_trade_no%22%3A%222019082048489749%22%7D&charset=UTF-8&format=json&method=alipay.trade.app.pay¬ify_url=http%3A%2F%2Fapi.gamekingtao.top%2Forder-aliPay-callback&sign_type=RSA×tamp=2019-08-21+10%3A38%3A30&version=1.0&sign=fG173y4NgKrXbIpWd0gPHCUiAytfwnDzCMJo%2Fkix3r5pjohAlldgirvV9GQjD%2FrErz4jcQI9ycgrp49SuvdBBs4Ao6u1IoxFHHMHArYbsIT34yYWPvR40AsOXqmNfTyrhnUFSscIBzgQosrZ3plFlqBIqivvgQAfbrIAB8wluXRf1Nb85oQp8M69QGkoAXG51NNfOt%2Bm4cKW%2B4hdz6s2ZsbY1y7cgdtLXkHelI2duLNMWy9w%2FL6UZTUHU6xMAfYW%2BEEQPFNNgnUoet%2FrQBBS5a9jlc6zv52vb8znTId%2B9jA%2FnvdIy2SqmUNi9WTlWzJB%2B4GsG6lnC3cK6NYxPGcCpg%3D%3D",
"wxPayInfo":{
"errorCode":0,
"msg":"预支付完成",
"data":{
"appid":"wxd8994a99ecb6c5ad",
"partnerid":"1516520031",
"prepayid":"wx241412507174778076f635510070001215",
"noncestr":"6BF2268744B9D5BBDC16988546124B27",
"package":"Sign=WXPay",
"timestamp":"1540361565",
"sign":"9AB0FD4246CE080A91164592E02A83BA",
"pay_type":2,
"out_trade_no":"w20181024141245529843"
}
},
"pay_type":"1",
"out_trade_no":"2019082048489749"
}
}
*/
public function appPay()
{
try{
$order_id = input('param.order_id');
$payType = input('param.pay_type');
$user_id = $this->uid;
$order = Db::name('order_info')->where('user_id',$user_id)->where('order_id',$order_id)->find();
if($order['pay_status'] != 0)
{
throw new Exception(self::getMessage('ERR_ORDER_STATUS_ERROR'), self::ERR_ORDER_STATUS_ERROR);
}
switch($payType)
{
case 1://货到付款
$data['pay_type'] = $payType;
$data['status'] = 6;
Db::name('order_info')->where('user_id',$user_id)->where('order_id',$order_id)->update($data);
break;
case 2://线下支付
$data['pay_type'] = $payType;
$data['status'] = 6;
Db::name('order_info')->where('user_id',$user_id)->where('order_id',$order_id)->update($data);
break;
case 3://小程序支付
break;
case 4://微信支付
$data['wxPayInfo'] = model(PayService::class)->wxPayInfo($order);
break;
case 5://支付宝支付
$data['aliPayInfo'] = model(PayService::class)->aliPayInfo($order);
break;
default:
throw new Exception('支付方式有误');
}
$data['pay_type'] = $payType;
$data['out_trade_no'] = $order['order_sn'];
return self::returnMsg(self::SUCCESS, self::getMessage('SUCCESS'), $data);
} catch (Exception $e) {
return self::returnMsg(self::ERR_ORDER_STATUS_ERROR, $e->getMessage());
}
}
public function aliPayCallback(){
$result = false;
try{
$params = $_POST;
$result = model(PayService::class)->aliPayCallback($params);
} catch (PayException $e) {
Log::error('支付宝支付失败');
$result = false;
} catch (\app\exceptions\Exception $e) {
//TODO 进来的订单是待支付状态
Log::error('支付宝回调失败');
Log::error($e->getMessage());
$returnData = $e->getReturnData();
model(PayService::class)->aliPayRefund($returnData);
$result = false;
} finally {
if($result)
{
echo "success";
}else{
echo "fail";
}
}
}
public function wxPayCallback(){
try{
Log::info("进入微信支付回调");
$config = Config::pull('wxpay');
$wxConfig = new WxPayConfig($config);
$notify = new WxPayNotify();
$notify->Handle($wxConfig);
} catch (PayException $e) {
//TODO 进来的订单是待支付状态
Log::record('微信支付失败');
echo '<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[ERROR]]></return_msg></xml>';
} catch (\app\exceptions\Exception $e) {
Log::record('微信支付失败');
model(PayService::class)->wxPayRefund($e->getReturnData());
echo '<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[ERROR]]></return_msg></xml>';
}
}
}