| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <?php
- namespace common\pay\nongzhitong;
- use backend\models\Config;
- use backend\models\Deposit;
- use backend\models\SyncDesposit;
- use common\helpers\Utils;
- use common\pay\BasePayHandler;
- use Yii;
- class PayHandler extends BasePayHandler
- {
- public $payUrl;
- public $userId;
- public $Key;
- /**
- * @inheritdoc
- */
- public function init()
- {
- parent::init();
- if ($this->payUrl == null) {
- $this->payUrl = Yii::$app->params['nongzhitong.payUrl'];
- }
- if ($this->userId == null) {
- $this->userId = Yii::$app->params['nongzhitong.userId'];
- }
- if ($this->Key == null) {
- $this->Key = Yii::$app->params['nongzhitong.Key'];
- }
- }
- /**
- * @param array $deposit
- * @param array $params
- * @return string
- */
- public function outPay($deposit, $params = [])
- {
- $data = [];
- $data['userId'] = $this->userId;
- $data['timestamp'] = time();
- $data['orderNo'] = intval($deposit['order_sn']); // 商户订单号
- $data['amount'] = $deposit['rmb'] * 100; // 交易金额 单位为分,不含小数点
- $data['bankCode'] = isset($params['bankCode']) ? $params['bankCode'] : ''; //银行代码
- if($data['bankCode'] == '102100099996'){
- $data['bankName'] = '中国工商银行'; //银行名称
- }else if($data['bankCode'] == '103100000026'){
- $data['bankName'] = '中国农业银行';
- }else if($data['bankCode'] == '105100000017'){
- $data['bankName'] = '中国建设银行';
- }else if($data['bankCode'] == '403100000004'){
- $data['bankName'] = '中国邮政储蓄银行';
- }else if($data['bankCode'] == '303100000006'){
- $data['bankName'] = '光大银行';
- }else if($data['bankCode'] == '305100000013'){
- $data['bankName'] = '民生银行';
- }else if($data['bankCode'] == '313100000013'){
- $data['bankName'] = '北京银行';
- }else if($data['bankCode'] == '301290000007'){
- $data['bankName'] = '交通银行';
- }else if($data['bankCode'] == '325290000012'){
- $data['bankName'] = '上海银行';
- }
- $data['cardType'] = 2; //(卡类型(1信用卡2借记卡)目前只支持2)
- $data['productName'] = 'RJ' . $deposit['id']; // 商品名称
- //$data['NotifyUrl'] = $this->notifyUrl; // 通知地址
- $data['callBackUrl'] = $this->returnUrl; // 返回地址
- $data['sign'] = PayUtils::makeSign($data, $this->Key); // 签名
- return static::createHtml($data, $this->payUrl);
- }
- /**
- * @param array $data
- * @return bool
- */
- public function handleNotify($data)
- {
- if (PayUtils::checkSign($data, $this->Key)) {
- if (isset($data['status']) && $data['status'] == 1 && isset($data['actType']) && $data['actType'] == 1) {
- $merOrderId = trim($data['orderNo']);
- /** @var Deposit $model */
- $reuslt = Deposit::find()->where(['order_sn' => $merOrderId])->asArray()->limit(1)->one();
- if ($reuslt['type'] != 1) {
- $res = Deposit::updateAll(['type' => 1], "order_sn = $merOrderId");
- $configData = Config::find()->asArray()->one();
- if ($configData['auto_deposit'] == 1 && $res) {
- $syncDespositModel = new SyncDesposit();
- $syncDespositModel->login = $reuslt['login'];
- $syncDespositModel->amount = $reuslt['amount'];
- $syncDespositModel->comment = 'Deposit';
- $syncDespositModel->memo = $merOrderId;
- $syncDespositModel->type = 2;
- $syncDespositModel->in_time = time();
- $syncDespositModel->save();
- }
- 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->Key)) {
- if (isset($data['status']) && $data['status'] == 1 && isset($data['actType']) && $data['actType'] == 1) {
- $merOrderId = trim($data['orderNo']);
- /** @var Deposit $model */
- $reuslt = Deposit::find()->where(['order_sn' => $merOrderId])->asArray()->limit(1)->one();
- if ($reuslt['type'] != 1) {
- $res = Deposit::updateAll(['type' => 1], "order_sn = $merOrderId");
- $configData = Config::find()->asArray()->one();
- if ($configData['auto_deposit'] == 1 && $res) {
- $syncDespositModel = new SyncDesposit();
- $syncDespositModel->login = $reuslt['login'];
- $syncDespositModel->amount = $reuslt['amount'];
- $syncDespositModel->comment = 'Deposit';
- $syncDespositModel->memo = $merOrderId;
- $syncDespositModel->type = 2;
- $syncDespositModel->in_time = time();
- $syncDespositModel->save();
- }
- return success;
- }
- // if ($model) {
- // return success;
- // }
- }
- }
- return false;
- }
- public function outReturn($success)
- {
- }
- }
|