payUrl == null) { $this->payUrl = Yii::$app->params['otczhifu.payUrl']; //网关地址 } if ($this->merId == null) { $this->merId = Yii::$app->params['otczhifu.merId']; //商户号码 } if ($this->privateKey == null) { $this->privateKey = __DIR__ . '/prem/otczhifu_private.pem'; //密钥 } if ($this->Key == null) { $this->Key = Yii::$app->params['otczhifu.key']; //公钥 } } /** * @param array $deposit * @param array $params * @return string */ public function outPay($deposit, $params = []) { $data = []; //存储数据的容器 $data['s'] = 'PaymentOrder.AddPayment'; //支付类型 $data['name'] = $this->merId; //商户号 $data['num'] = $deposit['amount']; //金额(数量和美元是挂钩的) $data['returnUrl'] = $this->notifyUrl; //回调地址(异步回调) $data['paymentNo'] = $deposit['order_sn']; //订单号 $data['memo'] = $deposit['order_sn']; //备注 $reuslt = PayUtils::makeSign($data, $this->Key,$this->payUrl); //开始支付(传递数据,公钥,网关地址) return $reuslt; } /** * @param array $data * @return bool */ public function handleNotify($data) { file_put_contents("data.txt",$data); //记录返回的数据 $tt = PayUtils::response($data, $this->privateKey,$this->Key); //验签函数(需要参数, 私钥,公钥) if ($tt) { //验签函数通过 $merOrderId = $tt; file_put_contents("dingdan.txt",$tt); //记录下来订单的号码 $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; } }else{ return false; } } public function outNotify($success) { if ($success == true) { return "true"; } else { // 返回的数据格式 return "false"; } } /** * @param array $data * @return bool */ public function handleReturn($data) { $tt = PayUtils::response($data, $this->privateKey,$this->Key); if ($tt) { $merOrderId = $tt; $reuslt = Deposit::find()->where(['order_sn' => $merOrderId])->asArray()->limit(1)->one(); if ($reuslt) { return true; } }else{ return false; } } public function outReturn($success) { } }