202 lines
6.8 KiB
PHP
202 lines
6.8 KiB
PHP
<?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('商品信息错误', 500);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 发起支付请求
|
||
* @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)
|
||
{
|
||
}
|
||
|
||
} |