| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- namespace common\pay\xunjie;
- use backend\models\Config;
- use backend\models\Deposit;
- use backend\models\SyncDesposit;
- use common\pay\BasePayHandler;
- use Yii;
- use yii\helpers\VarDumper;
- class PayHandler extends BasePayHandler
- {
- public $payUrl;
- public $merId;
- public $comkey;
- /**
- * @inheritdoc
- */
- public function init()
- {
- parent::init();
- if ($this->payUrl == null) {
- $this->payUrl = Yii::$app->params['xunjie.payUrl'];
- }
- if ($this->merId == null) {
- $this->merId = Yii::$app->params['xunjie.customerid'];
- }
- if ($this->comkey == null) {
- $this->comkey = Yii::$app->params['xunjie.key'];
- }
- }
- /**
- * @param array $deposit
- * @param array $params
- * @return string
- */
- public function outPay($deposit, $params = [])
- {
- $data = [];
- $data['version'] = '1.0';
- $data['customerid'] = $this->merId;
- $data['sdorderno'] = $deposit['order_sn'];
- $data['total_fee'] = $deposit['rmb']; // 金额
- $data['paytype'] = 'wy4';
- $data['returnurl'] = $this->returnUrl; // 支付完成返回地址
- $data['notifyurl'] = $this->notifyUrl; // 回调地址
- $data['remark'] = '111';
- $data['bankcode'] = '';
- // 1. 加密所需参数
- $signData = [];
- foreach (['version', 'customerid', 'total_fee', 'sdorderno', 'notifyurl', 'returnurl'] as $field) {
- $signData[$field] = $data[$field];
- }
- $data['sign'] = PayUtils::makeSign($signData, $this->comkey);
- Yii::warning('支付请求参数,' . VarDumper::dumpAsString($data), __METHOD__);
- $result = static::createHtml($data, $this->payUrl);
- Yii::warning('支付请求结果,' . VarDumper::dumpAsString($result), __METHOD__);
- return $result;
- }
- /**
- * @param array $data
- * @return bool
- */
- public function handleNotify($data)
- {
- Yii::warning('支付异步通知参数,' . VarDumper::dumpAsString($data), __METHOD__);
- if (isset($data['sign']) && trim($data['sign']) !== '') {
- $signData = [];
- foreach (['customerid', 'status', 'sdpayno', 'sdorderno', 'total_fee', 'paytype'] as $field) {
- $signData[$field] = isset($data[$field]) ? $data[$field] : null;
- }
- $sign = PayUtils::makeSign($signData, $this->comkey);
- if ($sign == $data['sign']) {
- if ($data['status'] == '1') {
- $merOrderId = trim($data['sdorderno']);
- $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 "OK";
- } else {
- return "FAIL";
- }
- }
- /**
- * @param array $data
- * @return bool
- */
- public function handleReturn($data)
- {
- Yii::warning('支付同步通知参数,' . VarDumper::dumpAsString($data), __METHOD__);
- if (isset($data['sign']) && trim($data['sign']) !== '') {
- $signData = [];
- foreach (['customerid', 'status', 'sdpayno', 'sdorderno', 'total_fee', 'paytype'] as $field) {
- $signData[$field] = isset($data[$field]) ? $data[$field] : null;
- }
- $sign = PayUtils::makeSign($signData, $this->comkey);
- if ($sign == $data['sign']) {
- if ($data['status'] == '1') {
- $merOrderId = trim($data['sdorderno']);
- $reuslt = Deposit::find()->where(['order_sn' => $merOrderId])->asArray()->limit(1)->one();
- if ($reuslt) {
- return true;
- }
- }
- }
- }
- return false;
- }
- public function outReturn($success)
- {
- }
- }
|