debug 支付接口

This commit is contained in:
chenbo 2023-11-16 14:04:58 +08:00
parent ebd209e9f4
commit eacdc1f9a5
3 changed files with 26 additions and 26 deletions

View File

@ -46,7 +46,7 @@ class PayConfigLogic extends BaseLogic
$config = [ $config = [
'interface_version' => $params['config']['interface_version'], 'interface_version' => $params['config']['interface_version'],
'merchant_type' => $params['config']['merchant_type'], 'merchant_type' => $params['config']['merchant_type'],
'appid' => $params['config']['app_id'], 'app_id' => $params['config']['app_id'],
'mch_id' => $params['config']['mch_id'], 'mch_id' => $params['config']['mch_id'],
'pay_sign_key' => $params['config']['pay_sign_key'], 'pay_sign_key' => $params['config']['pay_sign_key'],
'apiclient_cert' => $params['config']['apiclient_cert'], 'apiclient_cert' => $params['config']['apiclient_cert'],

View File

@ -11,6 +11,7 @@ use app\common\service\pay\WeChatPayService;
class WechatPayServiceMerchantPayController extends BaseApiController class WechatPayServiceMerchantPayController extends BaseApiController
{ {
public array $notNeedLogin = ['appPrePay'];
/** /**
* 微信服务商APP支付 * 微信服务商APP支付
*/ */
@ -23,9 +24,9 @@ class WechatPayServiceMerchantPayController extends BaseApiController
return $this->fail('支付订单创建失败', $params); return $this->fail('支付订单创建失败', $params);
} }
//支付流程 //支付流程
$result = WeChatPayMerchantService::wechatPayServiceMerchantAppPay($order); $result = (new WeChatPayMerchantService())->wechatPayServiceMerchantAppPay($order);
if (false === $result) { if (false === $result) {
return $this->fail(WeChatPayMerchantService::getError(), $params); return $this->fail((new WeChatPayMerchantService())->getError(), $params);
} }
return $this->success('', $result); return $this->success('', $result);
} }

View File

@ -20,12 +20,14 @@ use app\common\enum\PayEnum;
use app\common\enum\PayOrderEnum; use app\common\enum\PayOrderEnum;
use app\common\enum\user\UserTerminalEnum; use app\common\enum\user\UserTerminalEnum;
use app\common\logic\PayNotifyLogic; use app\common\logic\PayNotifyLogic;
use app\common\model\pay\PayConfig;
use app\common\model\recharge\RechargeOrder; use app\common\model\recharge\RechargeOrder;
use app\common\model\user\UserAuth; use app\common\model\user\UserAuth;
use app\common\service\wechat\WeChatConfigService; use app\common\service\wechat\WeChatConfigService;
use app\common\service\wechat\WeChatPayMerchantConfigService; use app\common\service\wechat\WeChatPayMerchantConfigService;
use EasyWeChat\Pay\Application; use EasyWeChat\Pay\Application;
use EasyWeChat\Pay\Message; use EasyWeChat\Pay\Message;
use think\Log;
/** /**
@ -74,29 +76,32 @@ class WeChatPayMerchantService extends BasePayService
public function wechatPayServiceMerchantAppPay($order) public function wechatPayServiceMerchantAppPay($order)
{ {
try { // try {
$response = $this->app->getClient()->postJson('pay/unifiedorder', [ $pay = PayConfig::where(['pay_way' => PayEnum::WECHAT_PAY])->findOrEmpty()->toArray();
'appid' => $this->config['app_id'], $client = $this->app->getClient();
'mchid' => $this->config['mch_id'], $response = $client->postXml('pay/unifiedorder', [
'sub_mch_id' => $order['sub_mch_id'], 'appid' => $pay['config']['app_id'],
'mch_id' => $this->config['mch_id'],
'sub_mch_id' => $order['collection_account'],
'description' => PayOrderEnum::getPayOrderTypeDesc($order['order_type']), 'description' => PayOrderEnum::getPayOrderTypeDesc($order['order_type']),
'out_trade_no' => $order['order_no'], 'out_trade_no' => $order['order_no'],
'notify_url' => $this->config['notify_url'], 'notify_url' => $this->config['notify_url'],
'total_fee' => $order['total_fee'], 'total_fee' => $order['total_fee'],
'spbill_create_ip' => $_SERVER['SERVER_ADDR'], // 调用微信支付API的机器IP 'spbill_create_ip' => $_SERVER['SERVER_ADDR'], // 调用微信支付API的机器IP
'time_start' => date('YmdHis', $order['create_time']), 'time_start' => date('YmdHis', intval($order['create_time'])),
'trade_type' => 'APP', 'trade_type' => 'APP',
'attach' => $order['order_no'] 'attach' => $order['order_no'],
'body' => PayOrderEnum::getPayOrderTypeDesc($order['order_type']).'订单'
]); ]);
$result = $response->toArray(false); $result = $response->toArray(false);dd($result);
$this->checkResultFail($result); $this->checkResultFail($result);
$re = $this->app->getUtils()->buildAppConfig($result['prepay_id'], $this->config['appid']); $re = $this->app->getUtils()->buildAppConfig($result['prepay_id'], $this->config['appid']);
$re['partnerid'] = $order['sub_mch_id']; $re['partnerid'] = $order['sub_mch_id'];
return $re; return $re;
} catch (\Exception $e) { // } catch (\Exception $e) {
$this->setError($e->getMessage()); // $this->setError($e->getMessage());
return false; // return false;
} // }
} }
@ -188,25 +193,19 @@ class WeChatPayMerchantService extends BasePayService
$server = $this->app->getServer(); $server = $this->app->getServer();
// 支付通知 // 支付通知
$server->handlePaid(function (Message $message) { $server->handlePaid(function (Message $message) {
Log::info(['支付回调信息', $message]);
if ($message['trade_state'] === 'SUCCESS') { if ($message['trade_state'] === 'SUCCESS') {
$extra['transaction_id'] = $message['transaction_id']; $transaction_id = $message['transaction_id'];
$attach = $message['attach']; $attach = $message['attach'];
$message['out_trade_no'] = mb_substr($message['out_trade_no'], 0, 18); $out_trade_no = $message['out_trade_no'];
switch ($attach) {
case 'recharge':
$order = RechargeOrder::where(['sn' => $message['out_trade_no']])->findOrEmpty();
if($order->isEmpty() || $order->pay_status == PayEnum::ISPAID) {
return true;
}
PayNotifyLogic::handle('recharge', $message['out_trade_no'], $extra);
break;
}
} }
return true; return true;
}); });
// 退款通知 // 退款通知
$server->handleRefunded(function (Message $message) { $server->handleRefunded(function (Message $message) {
Log::info(['退款回调信息', $message]);
return true; return true;
}); });
return $server->serve(); return $server->serve();