| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
- namespace App\Repositories\Service\Payment;
- use App\Repositories\ConfigRepoistory;
- use App\Repositories\Service\CommonService;
- class PaycenterPayment extends PaymentInterface
- {
- /**
- * @var null
- */
- private static $_instance = null;
- /**
- * @return PaycenterPayment|null
- */
- public static function getInstance()
- {
- if (is_null(self::$_instance)) {
- self::$_instance = new self();
- }
- return self::$_instance;
- }
- public function createPayLink($data = array())
- {
- $payUrl = make(ConfigRepoistory::class)
- ->get('pay_notify_url', 'sys', '');
- if (!$payUrl) {
- $this->_lastError = '网络错误';
- payLogger(__CLASS__, '网络错误');
- return '';
- }
- $notifyUrl = trim($payUrl, '/');
- $notifyUrl .= '/notify/' . $data['type'] . '/' . $data['orderId'];
- $info = [
- 'merchant_code' => env('PAY_CENTER_MERCHANT_CODE'),
- 'payment_id' => $data['payId'],
- 'amount' => $data['money'],
- 'order_id' => $data['orderSn'],
- 'notify_url' => $notifyUrl,
- 'redirect_url' => $payUrl,
- 'product_name' => 'DK',
- ];
- $info['signature'] = strtoupper(md5($this->getSign($info) . "key=" . env('PAY_CENTER_KEY')));
- $info['ip'] = make(CommonService::class)->getIp();
- $res = $this->httpPost(env('PAY_CENTER_URL') . '/api/pay/url', ['data' => $info]);
- if (empty($res)) {
- payLogger(__CLASS__, '获取支付中心链接失败' . $res);
- return '';
- }
- $res = json_decode($res, true);
- if (empty($res) || $res['code'] == 500) {
- payLogger(__CLASS__, '获取支付中心链接异常:' . $res['message']);
- return '';
- }
- return $res['data']['pay_url'];
- }
- public function notify(&$orderSn, &$tradeNo, &$money)
- {
- $data = request()->all();
- if ($data['status'] != 2) {
- payLogger(__CLASS__, '回调订单状态失败!'.json_encode($data));
- return false;
- }
- $sendData = [
- 'merchant_code' => env('PAY_CENTER_MERCHANT_CODE'),
- 'status' => $data['status'],
- 'order_id' => $data['order_id'],
- 'trade_no' => $data['trade_no'],
- 'amount' => $data['amount'],
- 'real_amount' => $data['real_amount'],
- 'product_name' => $data['product_name'],
- 'notify_url' => $data['notify_url'],
- 'redirect_url' => $data['redirect_url'],
- ];
- $sign = strtoupper(md5($this->getSign($sendData) . 'key=' . env('PAY_CENTER_KEY')));
- if ($sign != $data['signature']) {
- $this->_lastError = '验证失败!';
- payLogger(__CLASS__, '验证失败!'.json_encode($data));
- return false;
- }
- $money = $data['amount'];
- $orderSn = $data['order_id'];
- $tradeNo = $data['trade_no'];
- return true;
- }
- }
|