调试农信支付
This commit is contained in:
parent
a0f3d2374b
commit
f95209e9df
@ -44,6 +44,7 @@ use crmeb\services\CombinePayService;
|
|||||||
use crmeb\services\CrmebServeServices;
|
use crmeb\services\CrmebServeServices;
|
||||||
use crmeb\services\ExpressService;
|
use crmeb\services\ExpressService;
|
||||||
use crmeb\services\PayService;
|
use crmeb\services\PayService;
|
||||||
|
use crmeb\services\payTool\PayTool;
|
||||||
use crmeb\services\printer\Printer;
|
use crmeb\services\printer\Printer;
|
||||||
use crmeb\services\QrcodeService;
|
use crmeb\services\QrcodeService;
|
||||||
use crmeb\services\SpreadsheetExcelService;
|
use crmeb\services\SpreadsheetExcelService;
|
||||||
@ -73,7 +74,7 @@ class StoreOrderRepository extends BaseRepository
|
|||||||
/**
|
/**
|
||||||
* 支付类型
|
* 支付类型
|
||||||
*/
|
*/
|
||||||
const PAY_TYPE = ['balance', 'weixin', 'routine', 'h5', 'alipay', 'alipayQr', 'weixinQr'];
|
const PAY_TYPE = ['balance', 'weixin', 'routine', 'h5', 'alipay', 'alipayQr', 'weixinQr', 'scrcu'];
|
||||||
|
|
||||||
const TYPE_SN_ORDER = 'wxo';
|
const TYPE_SN_ORDER = 'wxo';
|
||||||
const TYPE_SN_PRESELL = 'wxp';
|
const TYPE_SN_PRESELL = 'wxp';
|
||||||
@ -112,6 +113,10 @@ class StoreOrderRepository extends BaseRepository
|
|||||||
event('order.pay.before', compact('groupOrder', 'type', 'isApp'));
|
event('order.pay.before', compact('groupOrder', 'type', 'isApp'));
|
||||||
if (in_array($type, ['weixin', 'weixinApp', 'routine', 'h5', 'weixinQr'], true) && systemConfig('open_wx_combine')) {
|
if (in_array($type, ['weixin', 'weixinApp', 'routine', 'h5', 'weixinQr'], true) && systemConfig('open_wx_combine')) {
|
||||||
$service = new CombinePayService($type, $groupOrder->getCombinePayParams());
|
$service = new CombinePayService($type, $groupOrder->getCombinePayParams());
|
||||||
|
} elseif ($type == 'scrcu') {
|
||||||
|
$payTool = PayTool::instance($type);
|
||||||
|
$groupOrder = $payTool->format($groupOrder);
|
||||||
|
return app('json')->status($type, $payTool->pay($groupOrder));
|
||||||
} else {
|
} else {
|
||||||
$service = new PayService($type, $groupOrder->getPayParams($type === 'alipay' ? $return_url : ''));
|
$service = new PayService($type, $groupOrder->getPayParams($type === 'alipay' ? $return_url : ''));
|
||||||
}
|
}
|
||||||
|
50
crmeb/services/payTool/PayTool.php
Normal file
50
crmeb/services/payTool/PayTool.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace crmeb\services\payTool;
|
||||||
|
|
||||||
|
abstract class PayTool
|
||||||
|
{
|
||||||
|
|
||||||
|
public $config;
|
||||||
|
public $error = ['success' => false];
|
||||||
|
const Scrcu = 'scrcu';
|
||||||
|
|
||||||
|
const ClassMap = [
|
||||||
|
self::Scrcu => Scrcu::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $name
|
||||||
|
* @param $params
|
||||||
|
* @return mixed|Scrcu
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public static function instance($name, $params = [])
|
||||||
|
{
|
||||||
|
$class = self::ClassMap[$name];
|
||||||
|
if (class_exists($class)) {
|
||||||
|
return new $class($params);
|
||||||
|
}
|
||||||
|
throw new \Exception('支付方式未开通', 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getError()
|
||||||
|
{
|
||||||
|
return $this->error;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract function pay($order);
|
||||||
|
|
||||||
|
public abstract function query($orderNo);
|
||||||
|
|
||||||
|
public abstract function callback($request = null);
|
||||||
|
|
||||||
|
public abstract function success();
|
||||||
|
|
||||||
|
public abstract function refund($order);
|
||||||
|
|
||||||
|
public abstract function refundQuery($refundOrder);
|
||||||
|
|
||||||
|
public abstract function transfer($withdraw);
|
||||||
|
|
||||||
|
}
|
202
crmeb/services/payTool/Scrcu.php
Normal file
202
crmeb/services/payTool/Scrcu.php
Normal file
@ -0,0 +1,202 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace crmeb\services\payTool;
|
||||||
|
|
||||||
|
use crmeb\utils\DingTalk;
|
||||||
|
|
||||||
|
class Scrcu extends PayTool
|
||||||
|
{
|
||||||
|
|
||||||
|
public $domain;
|
||||||
|
public $onlinePayApi = 'onlinepay/OPC321560202000200000500';
|
||||||
|
public $queryApi = 'onlinepay/OPC321560202000200000000';
|
||||||
|
public $refundApi = 'onlinepay/OPC321560202000200000400';
|
||||||
|
public $closeApi = 'onlinepay/OPC321560102000200000100';
|
||||||
|
public $gateway = 'http://127.0.0.1:23552/sdk/doApi';
|
||||||
|
public $callbackUrl = '';
|
||||||
|
public $callbackApi = '';
|
||||||
|
public $commonHeader = [];
|
||||||
|
public $requestHeader;
|
||||||
|
public $requestBody;
|
||||||
|
public $merId = '129765100270890';
|
||||||
|
public $order;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->commonHeader = [
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
'Accept' => '*/*',
|
||||||
|
'Host' => '127.0.0.1:23552',
|
||||||
|
'Connection' => 'keep-alive'
|
||||||
|
];
|
||||||
|
$this->domain = env('APP_DEBUG', false) ? 'https://open-test.scrcu.com:9051/open-gate/' : 'https://open.scrcu.com/open-gate/';
|
||||||
|
$this->requestHeader = [
|
||||||
|
'appId' => '000000000010012',
|
||||||
|
'appSecret' => '8c76d098-ce22-4df8-a01d-ea6f5502e5ec',
|
||||||
|
'openEPubK' => '3A743B476533D137EAA130F266501CAAE6D0870B1CAF0934D1CA5566F90B763F5B11C4A57B402C102C956ADF0DFDA3BD91F2843C648EAF159A9B08C0C8ACF541',
|
||||||
|
'appDPriK' => '7D0B1F1BAFAE24436AD322EF35A6784B264700B9402C33F9CA2C6BB7FE325AF9',
|
||||||
|
'openVPubK' => '7EAFB55A843DCBB33E07E4E59D3AF14216768CC0C8055985633AC753E29F9A5C07586CDBC9806CD31F66B17B12B07193B3C471C3A707C07E793D42B676AF80B1',
|
||||||
|
'appSPriK' => 'E8E0A7F49E2EC0E0C45352BDD4D8579FAC73A258FEDFF919B334DA2103EB32B7',
|
||||||
|
'httpDomainName' => $this->domain,
|
||||||
|
'version' => '1.0.0',
|
||||||
|
];
|
||||||
|
$this->requestBody = [
|
||||||
|
'charset' => 'UTF-8',
|
||||||
|
'version' => 'V5.0.0',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function format($order)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$firstGoods = $order->orderList[0]->orderProduct[0];
|
||||||
|
$order['goodsInfo'] = [
|
||||||
|
'goodsSubject' => $firstGoods->product->store_name,
|
||||||
|
'goodsPrice' => $firstGoods->product_price,
|
||||||
|
'goodsUnit' => $firstGoods->product->unit_name,
|
||||||
|
'goodsNum' => $firstGoods->product_num,
|
||||||
|
'goodsTotalAmt' => $firstGoods->total_price,
|
||||||
|
'goodsSpec' => $firstGoods->product_sku,
|
||||||
|
];
|
||||||
|
$order['subject'] = $firstGoods->product->store_name . " 等{$order['total_num']}件商品";
|
||||||
|
return $order;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
throw new \Exception('商品信息错误');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发起支付请求
|
||||||
|
* @param $order
|
||||||
|
* @return string
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function pay($order)
|
||||||
|
{
|
||||||
|
$body['header'] = array_merge($this->requestHeader, ['apiUrl' => $this->onlinePayApi]);
|
||||||
|
$body['body'] = array_merge($this->requestBody, [
|
||||||
|
'orderType' => '01', //订单类型,固定值:01=使用我行支付的实物消费订单
|
||||||
|
'orderNumber' => $order['group_order_sn'],
|
||||||
|
'orderCurrency' => '01', //交易币种,01-人民币
|
||||||
|
'subject' => $order['subject'],
|
||||||
|
'channel' => '02', //"接入渠道:01:PC 02:手机"
|
||||||
|
'orderSendTime' => date('YmdHis'),
|
||||||
|
'orderAmt' => bcmul($order['total_price'], 100),
|
||||||
|
'payAmt' => bcmul($order['pay_price'], 100),
|
||||||
|
'backEndUrl' => $this->callbackApi,
|
||||||
|
'frontEndUrl' => $this->callbackUrl,
|
||||||
|
'merId' => $this->merId,
|
||||||
|
"orderDetailList" => [
|
||||||
|
"orderAmt" => bcmul($order['total_price'], 100),
|
||||||
|
"payAmt" => bcmul($order['pay_price'], 100),
|
||||||
|
"payType" => "",
|
||||||
|
"merLst" => [
|
||||||
|
[
|
||||||
|
"subOrderAmt" => bcmul($order['total_price'], 100),
|
||||||
|
"orderNumber" => $order['group_order_sn'],
|
||||||
|
"merId" => $this->merId,
|
||||||
|
"subPayAmt" => bcmul($order['pay_price'], 100),
|
||||||
|
"autoSettleFlag" => "1", //自动结算标记,1=自动结算,0=不自动结算,可以不传
|
||||||
|
"goodsInfo" => $order['goodsInfo'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
return $this->request($body);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询
|
||||||
|
* @param $order
|
||||||
|
* @return string
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function query($order)
|
||||||
|
{
|
||||||
|
$body['header'] = array_merge($this->requestHeader, ['apiUrl' => $this->queryApi]);
|
||||||
|
$body['body'] = array_merge($this->requestBody, [
|
||||||
|
'orderNumber' => $order['group_order_sn'],
|
||||||
|
'merId' => $this->merId,
|
||||||
|
'tranType' => '04',
|
||||||
|
]);
|
||||||
|
return $this->request($body);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退款
|
||||||
|
* @param $order
|
||||||
|
* @return string
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function refund($order)
|
||||||
|
{
|
||||||
|
$body['header'] = array_merge($this->requestHeader, ['apiUrl' => $this->refundApi]);
|
||||||
|
$body['body'] = array_merge($this->requestBody, [
|
||||||
|
'orderNumber' => $order['group_order_sn'],
|
||||||
|
'merNo' => $this->merId,
|
||||||
|
'channel' => '02',
|
||||||
|
'oriSubOrderNumber' => 'f7jugi1d8pca8b5555d8d363075392',
|
||||||
|
'merId' => $this->merId,
|
||||||
|
'orderSendTime' => date('YmdHis'),
|
||||||
|
'orderAmt' => bcmul($order['pay_price'], 100),
|
||||||
|
'oriOrderNumber' => 'f7jugi1d8pca8b5555d8d363075392',
|
||||||
|
'backEndUrl' => $this->callbackApi,
|
||||||
|
]);
|
||||||
|
return $this->request($body);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关闭订单
|
||||||
|
* @param $order
|
||||||
|
* @return string
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function close($order)
|
||||||
|
{
|
||||||
|
$body['header'] = array_merge($this->requestHeader, ['apiUrl' => $this->closeApi]);
|
||||||
|
$body['body'] = array_merge($this->requestBody, [
|
||||||
|
'orderNumber' => $order['group_order_sn'],
|
||||||
|
'merId' => $this->merId,
|
||||||
|
]);
|
||||||
|
return $this->request($body);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发起请求
|
||||||
|
* @param $body
|
||||||
|
* @return string
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function request($body)
|
||||||
|
{
|
||||||
|
$body = json_encode($body, JSON_UNESCAPED_UNICODE);
|
||||||
|
$client = new \GuzzleHttp\Client();
|
||||||
|
try {
|
||||||
|
$result = $client->post($this->gateway, [
|
||||||
|
'headers' => $this->commonHeader,
|
||||||
|
'body' => $body
|
||||||
|
]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DingTalk::exception($e, $e->getMessage());
|
||||||
|
throw new \Exception('请求出错');
|
||||||
|
}
|
||||||
|
return json_decode($result->getBody()->getContents(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function success()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function callback($request = null)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function refundQuery($refundOrder)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function transfer($withdraw)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user