payUrl == null) { $this->payUrl = Yii::$app->params['rtw.payUrl']; } if ($this->merId == null) { $this->merId = Yii::$app->params['rtw.merId']; } if ($this->comkey == null) { $this->comkey = Yii::$app->params['rtw.key']; } } /** * @param array $deposit * @param array $params * @return string */ public function outPay($deposit, $params = []) { $data = []; $data['merchantNo'] = $this->merId; $data['merchantOrderNo'] = $deposit['order_sn']; $data['orderAmount'] = $deposit['rmb']; // 金额 $data['requestIp'] = isset($params['ip']) ? $params['ip'] : Utils::getClientIp(); $data['returnUrl'] = $this->returnUrl; // 支付完成返回地址 $data['notifyUrl'] = $this->notifyUrl; // 回调地址 $data['orderTitle'] = $deposit['order_sn']; $data['service'] = 'service.business.gate_way'; $data['bankCode'] = $params['bankCode']; $data['cardType'] = 'DC'; $data['sign'] = PayUtils::makeSign($data, $this->comkey); Yii::warning('支付请求参数,' . VarDumper::dumpAsString($data), __METHOD__); $res= PayUtils::sendPost($this->payUrl, $data); Yii::warning('支付请求结果,' . VarDumper::dumpAsString($tmp), __METHOD__); $tmp = json_decode($res, true); if ($tmp['code'] != 1) { return $res; } $result = $tmp['result']; Yii::warning('支付请求结果,' . VarDumper::dumpAsString($result['payInfo']), __METHOD__); return $result['payInfo']; } /** * @param array $data * @return bool */ public function handleNotify($data) { Yii::warning('支付异步通知参数,' . var_export($data, true), __METHOD__); $res = $data['result']; $res['orderAmount'] = sprintf('%.2f', $res['orderAmount']); $notifySign = $res['sign']; unset($res['sign']); Yii::warning('支付异步通知参数2222,' . var_export($res, true), __METHOD__); $sign = PayUtils::makeSign($res, $this->comkey); if ($sign == $notifySign) { if ($data['code'] == '1') { $merOrderId = trim($res['merchantOrderNo']); $reuslt = Deposit::find()->where(['order_sn' => $merOrderId])->asArray()->limit(1)->one(); if ($reuslt['type'] != 1 && $res['tradeStatus'] == 'PAY_SUCCESS') { $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; } } } Yii::warning('支付异步通知签名失败,' . $sign.'----resign:'.$notifySign, __METHOD__); 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']) !== '') { $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) { } }