| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- namespace common\pay\aotu;
- use backend\models\Deposit;
- use common\helpers\Utils;
- use common\pay\BasePayHandler;
- use Yii;
- class PayHandler extends BasePayHandler
- {
- public $payUrl;
- public $MerchantID;
- public $secretKey;
- /**
- * @inheritdoc
- */
- public function init()
- {
- parent::init();
- if ($this->payUrl == null) {
- $this->payUrl = Yii::$app->params['aotu.payUrl'];
- }
- if ($this->MerchantID == null) {
- $this->MerchantID = Yii::$app->params['aotu.MerchantID'];
- }
- if ($this->secretKey == null) {
- $this->secretKey = Yii::$app->params['aotu.secretKey'];
- }
- }
- /**
- * @param array $deposit
- * @param array $params
- * @return string
- */
- public function outPay($deposit, $params = [])
- {
- $data = [];
- $data['TradeType'] = 'bis.pay.submit'; // 交易类型
- $data['OperatorID'] = $this->MerchantID; // 操作员 默认商户编号
- $data['PayType'] = '0202'; // 支付类型
- $data['TerminalType'] = 'PC'; // 终端类型
- // $data['MemberID'] = ''; // 用户编号 快捷支付必填
- $data['MerchantID'] = $this->MerchantID; // 商户编号
- // $data['AppID'] = ''; // 公众号appid
- // $data['OpenID'] = ''; // 微信openid
- $data['BankID'] = isset($params['bankCode']) ? $params['bankCode'] : ''; // 银行代码
- $data['OrderID'] = $deposit['id']; // 订单号
- // $data['DeviceID'] = ''; // 设备号
- $data['Subject'] = 'RJ' . $deposit['id']; // 商品名称
- $data['MachineIP'] = isset($params['ip']) ? $params['ip'] : Utils::getClientIp(); // 终端IP
- $data['NotifyUrl'] = $this->notifyUrl; // 通知地址
- $data['ReturnUrl'] = $this->returnUrl; // 返回地址
- $data['SubmitTime'] = date('YmdHis'); // 订单提交时间
- // $data['OrderValidity'] = ''; // 订单有效截止时间
- $data['CreditLimit'] = '1'; // 信用卡限制使用标识
- $data['Amt'] = $deposit['rmb'] * 100; // 交易金额 单位为分,不含小数点
- // $data['Summary'] = ''; // 交易附言
- $data['Sign'] = PayUtils::makeSign($data, $this->secretKey); // 签名
- return static::createHtml($data, $this->payUrl);
- }
- /**
- * @param array $data
- * @return bool
- */
- public function handleNotify($data)
- {
- if (PayUtils::checkSign($data, $this->secretKey)) {
- if (isset($data['RetStatus']) && $data['RetStatus'] == 0 && isset($data['DealStatus']) && $data['DealStatus'] == 0
- && isset($data['Status']) && $data['Status'] == '02'
- ) {
- $merOrderId = trim($data['OrderID']);
- /** @var Deposit $model */
- $model = Deposit::find()->where(['id' => $merOrderId])->asArray()->limit(1)->one();
- if ($model) {
- // $model->type = 1;
- // $model->save(false);
- return true;
- }
- }
- }
- return false;
- }
- public function outNotify($success)
- {
- if ($success == true) {
- return "SUCCESS";
- } else {
- return "FAIL";
- }
- }
- /**
- * @param array $data
- * @return bool
- */
- public function handleReturn($data)
- {
- if (PayUtils::checkSign($data, $this->secretKey)) {
- if (isset($data['RetStatus']) && $data['RetStatus'] == 0 && isset($data['DealStatus']) && $data['DealStatus'] == 0) {
- $merOrderId = trim($data['OrderID']);
- /** @var Deposit $model */
- $model = Deposit::find()->where(['id' => $merOrderId])->asArray()->limit(1)->one();
- if ($model) {
- return true;
- }
- }
- }
- return false;
- }
- public function outReturn($success)
- {
- }
- }
|