debug 支付接口
This commit is contained in:
parent
ebd209e9f4
commit
eacdc1f9a5
|
@ -46,7 +46,7 @@ class PayConfigLogic extends BaseLogic
|
|||
$config = [
|
||||
'interface_version' => $params['config']['interface_version'],
|
||||
'merchant_type' => $params['config']['merchant_type'],
|
||||
'appid' => $params['config']['app_id'],
|
||||
'app_id' => $params['config']['app_id'],
|
||||
'mch_id' => $params['config']['mch_id'],
|
||||
'pay_sign_key' => $params['config']['pay_sign_key'],
|
||||
'apiclient_cert' => $params['config']['apiclient_cert'],
|
||||
|
|
|
@ -11,6 +11,7 @@ use app\common\service\pay\WeChatPayService;
|
|||
class WechatPayServiceMerchantPayController extends BaseApiController
|
||||
{
|
||||
|
||||
public array $notNeedLogin = ['appPrePay'];
|
||||
/**
|
||||
* 微信服务商APP支付
|
||||
*/
|
||||
|
@ -23,9 +24,9 @@ class WechatPayServiceMerchantPayController extends BaseApiController
|
|||
return $this->fail('支付订单创建失败', $params);
|
||||
}
|
||||
//支付流程
|
||||
$result = WeChatPayMerchantService::wechatPayServiceMerchantAppPay($order);
|
||||
$result = (new WeChatPayMerchantService())->wechatPayServiceMerchantAppPay($order);
|
||||
if (false === $result) {
|
||||
return $this->fail(WeChatPayMerchantService::getError(), $params);
|
||||
return $this->fail((new WeChatPayMerchantService())->getError(), $params);
|
||||
}
|
||||
return $this->success('', $result);
|
||||
}
|
||||
|
|
|
@ -20,12 +20,14 @@ use app\common\enum\PayEnum;
|
|||
use app\common\enum\PayOrderEnum;
|
||||
use app\common\enum\user\UserTerminalEnum;
|
||||
use app\common\logic\PayNotifyLogic;
|
||||
use app\common\model\pay\PayConfig;
|
||||
use app\common\model\recharge\RechargeOrder;
|
||||
use app\common\model\user\UserAuth;
|
||||
use app\common\service\wechat\WeChatConfigService;
|
||||
use app\common\service\wechat\WeChatPayMerchantConfigService;
|
||||
use EasyWeChat\Pay\Application;
|
||||
use EasyWeChat\Pay\Message;
|
||||
use think\Log;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -74,29 +76,32 @@ class WeChatPayMerchantService extends BasePayService
|
|||
|
||||
public function wechatPayServiceMerchantAppPay($order)
|
||||
{
|
||||
try {
|
||||
$response = $this->app->getClient()->postJson('pay/unifiedorder', [
|
||||
'appid' => $this->config['app_id'],
|
||||
'mchid' => $this->config['mch_id'],
|
||||
'sub_mch_id' => $order['sub_mch_id'],
|
||||
// try {
|
||||
$pay = PayConfig::where(['pay_way' => PayEnum::WECHAT_PAY])->findOrEmpty()->toArray();
|
||||
$client = $this->app->getClient();
|
||||
$response = $client->postXml('pay/unifiedorder', [
|
||||
'appid' => $pay['config']['app_id'],
|
||||
'mch_id' => $this->config['mch_id'],
|
||||
'sub_mch_id' => $order['collection_account'],
|
||||
'description' => PayOrderEnum::getPayOrderTypeDesc($order['order_type']),
|
||||
'out_trade_no' => $order['order_no'],
|
||||
'notify_url' => $this->config['notify_url'],
|
||||
'total_fee' => $order['total_fee'],
|
||||
'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',
|
||||
'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);
|
||||
$re = $this->app->getUtils()->buildAppConfig($result['prepay_id'], $this->config['appid']);
|
||||
$re['partnerid'] = $order['sub_mch_id'];
|
||||
return $re;
|
||||
} catch (\Exception $e) {
|
||||
$this->setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
// } catch (\Exception $e) {
|
||||
// $this->setError($e->getMessage());
|
||||
// return false;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
@ -188,25 +193,19 @@ class WeChatPayMerchantService extends BasePayService
|
|||
$server = $this->app->getServer();
|
||||
// 支付通知
|
||||
$server->handlePaid(function (Message $message) {
|
||||
Log::info(['支付回调信息', $message]);
|
||||
if ($message['trade_state'] === 'SUCCESS') {
|
||||
$extra['transaction_id'] = $message['transaction_id'];
|
||||
$transaction_id = $message['transaction_id'];
|
||||
$attach = $message['attach'];
|
||||
$message['out_trade_no'] = mb_substr($message['out_trade_no'], 0, 18);
|
||||
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;
|
||||
}
|
||||
$out_trade_no = $message['out_trade_no'];
|
||||
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
// 退款通知
|
||||
$server->handleRefunded(function (Message $message) {
|
||||
Log::info(['退款回调信息', $message]);
|
||||
return true;
|
||||
});
|
||||
return $server->serve();
|
||||
|
|
Loading…
Reference in New Issue