|
|
@@ -0,0 +1,136 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace common\pay\payplat;
|
|
|
+
|
|
|
+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 $confirmUrl;
|
|
|
+ public $merId;
|
|
|
+ public $Key;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @inheritdoc
|
|
|
+ */
|
|
|
+ public function init()
|
|
|
+ {
|
|
|
+ parent::init();
|
|
|
+ if ($this->payUrl == null) {
|
|
|
+ $this->payUrl = Yii::$app->params['payplat.payUrl'];
|
|
|
+ }
|
|
|
+ if ($this->merId == null) {
|
|
|
+ $this->merId = Yii::$app->params['payplat.merId'];
|
|
|
+ }
|
|
|
+ if ($this->Key == null) {
|
|
|
+ $this->Key = Yii::$app->params['payplat.Key'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param array $deposit
|
|
|
+ * @param array $params
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ public function outPay($deposit, $params = [])
|
|
|
+ {
|
|
|
+ $data = [];
|
|
|
+
|
|
|
+ $data['userNo'] = $this->merId; //商户号码
|
|
|
+
|
|
|
+ $data['payType'] = 'wypay'; //商户平台用户唯一标识
|
|
|
+ $data['price'] = $deposit['rmb'] * 100; //订单金额
|
|
|
+ $data['sdOrderNo'] = $deposit['order_sn']; //商户订单号码
|
|
|
+
|
|
|
+ $data['sdReturnUrl'] = $this->returnUrl; //支付完成返回地址(同步地址)
|
|
|
+ $data['sdNotifyUrl'] = $this->notifyUrl; //异步回调地址
|
|
|
+
|
|
|
+ $data['secret'] = $this->Key; //签名的秘钥
|
|
|
+
|
|
|
+ $data['sign'] = PayUtils::makeSign($data);
|
|
|
+ $result = static::createHtml($data, $this->payUrl);
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param array $data
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function handleNotify($data)
|
|
|
+ {
|
|
|
+
|
|
|
+ $tt = print_r($data,true);
|
|
|
+ file_put_contents('payplat_data.txt',$tt);
|
|
|
+ $data['secret'] = $this->Key;
|
|
|
+ if (isset($data['sign']) && trim($data['sign']) !== '') {
|
|
|
+
|
|
|
+ if (PayUtils::verify($data)) {
|
|
|
+ file_put_contents('payplat_success.txt','验签成功');
|
|
|
+ $merOrderId = trim($data['orderNo']);
|
|
|
+ $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; //存储入金表的订单id
|
|
|
+ $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)
|
|
|
+ {
|
|
|
+ //Yii::warning('支付同步通知参数,' . VarDumper::dumpAsString($data), __METHOD__);
|
|
|
+ if (isset($data['sign']) && trim($data['sign']) !== '') {
|
|
|
+ $data['secret'] = $this->Key;
|
|
|
+ if (PayUtils::verify($data)) {
|
|
|
+ if ($data['payStatus'] == '1') {
|
|
|
+ $merOrderId = trim($data['orderNo']);
|
|
|
+ $reuslt = Deposit::find()->where(['order_sn' => $merOrderId])->asArray()->limit(1)->one();
|
|
|
+ if ($reuslt) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function outReturn($success)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|