| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- namespace App\Repositories\Service\Payment;
- class DahePayment extends PaymentInterface
- {
- /**
- * 支付请求地址
- *
- * @var string
- */
- private $payUrl = 'http://www.azhifu2022.com/Pay';
- const SUCCESS_STATUS = 1;
- /**
- * 公钥
- *
- * @var string
- */
- private $publicKey = 'LzMIHCQnVlWFWYVJlrcAmLDUjSraEHhL';
- /**
- * @var null
- */
- private static $_instance = null;
- /**
- * @return WhiteSharkPayment|null
- */
- public static function getInstance()
- {
- if (is_null(self::$_instance)) {
- self::$_instance = new self();
- }
- return self::$_instance;
- }
- public function createPayLink($data = array())
- {
- $payInfo = [
- 'fxid' => $data['partner_id'], //商户号
- 'fxddh' => $data['order_sn'],
- 'fxdesc' => 'PAY',
- 'fxattch' => 'PAY',
- 'fxfee' => sprintf('%.2f', $data['money']),
- 'fxnotifyurl' => $data['notify_url'],
- 'fxbackurl' => $data['pay_url'],
- 'fxpay' => $data['pay_attr_code'],
- ];
- $payInfo['fxip'] = '127.0.0.1';
- $payInfo['fxsign'] = md5($payInfo['fxid'] . $payInfo['fxddh'] . $payInfo['fxfee'] . $payInfo['fxnotifyurl'] . $this->publicKey);
- $sRes = $this->httpPost($this->payUrl, $payInfo);
- if (empty($sRes)) {
- $this->_lastError = '请求异常';
- payLogger(__CLASS__, '请求异常data=' . $sRes, $payInfo);
- return '';
- }
- $aRes = json_decode($sRes, true);
- if (empty($aRes)) {
- $this->_lastError = '请求异常!';
- payLogger(__CLASS__, '请求异常 (解析) data=' . $sRes, $payInfo);
- return '';
- }
- if ($aRes['status'] != self::SUCCESS_STATUS) {
- $this->_lastError = '请求异常,请求失败';
- payLogger(__CLASS__, '请求异常,请求失败 data=' . $sRes, $payInfo);
- return '';
- }
- return $aRes['payurl'];
- }
- public function queryOrder($data, &$orderSn, &$money, $partnerId)
- {
- $queryInfo = [
- 'fxid' => $partnerId,
- 'fxddh' => $orderSn,
- 'fxaction' => 'orderquery',
- ];
- $queryInfo['fxsign'] = md5($partnerId . $orderSn . 'orderquery' . $this->publicKey);
- $sRes = $this->httpPost($this->payUrl, $queryInfo);
- if (empty($sRes)) {
- $this->_lastError = '查询请求异常';
- payLogger(__CLASS__, '查询请求异常 data=' . $sRes, $queryInfo);
- return '';
- }
- $aRes = json_decode($sRes, true);
- if (empty($aRes)) {
- $this->_lastError = '查询解析异常';
- payLogger(__CLASS__, '查询解析异常 data=' . $sRes, $queryInfo);
- return '';
- }
- if ($aRes['fxstatus'] != self::SUCCESS_STATUS) {
- $this->_lastError = '查询订单状态异常';
- payLogger(__CLASS__, '查询订单状态异常 data=' . $sRes, $queryInfo);
- return '';
- }
- if ($money != $aRes['fxfee']) {
- $this->_lastError = '查询订单金额异常';
- payLogger(__CLASS__, '查询订单金额异常 data=' . $sRes, $queryInfo);
- return '';
- }
- return true;
- }
- public function notify(&$orderSn, &$tradeNo, &$money, $partnerId)
- {
- $data = request()->all();
- if ($data['fxstatus'] != self::SUCCESS_STATUS) {
- payLogger(__CLASS__, '回调订单状态失败', $data);
- return false;
- }
- $sign = md5($data['fxstatus'] . $partnerId . $data['fxddh'] . $data['fxfee'] . $this->publicKey);
- if ($sign != $data['fxsign']) {
- $this->_lastError = '验证失败!';
- payLogger(__CLASS__, '验证失败 key=' . $this->publicKey, $data);
- return false;
- }
- $money = $data['fxfee'];
- $res = $this->queryOrder($data, $data['fxddh'], $money, $partnerId);
- if (empty($res)) {
- return '';
- }
- $orderSn = $data['fxddh'];
- $tradeNo = $data['fxorder'];
- return true;
- }
- public function stopNotify()
- {
- return 'success';
- }
- }
|